Files
mtgodot-poc/extension/src/port/common/PortPythonPointer.h
T

27 lines
691 B
C++

#pragma once
#include <Python.h>
// The 40250 Python API represents native handles as integers. Keep that API while allowing a
// 64-bit pointer to survive the round trip on macOS and mobile builds.
template <typename T>
PyObject* Py_BuildPointer(T* pointer)
{
return PyLong_FromVoidPtr(static_cast<void*>(pointer));
}
template <typename T>
bool PyTuple_GetPointer(PyObject* args, int position, T** out)
{
if (position < 0 || position >= PyTuple_Size(args))
return false;
PyObject* value = PyTuple_GetItem(args, position);
if (!value)
return false;
void* pointer = PyLong_AsVoidPtr(value);
if (PyErr_Occurred())
return false;
*out = static_cast<T*>(pointer);
return true;
}