Port 2V0 UI Python bindings and app module link surface
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user