#pragma once #include // 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 PyObject* Py_BuildPointer(T* pointer) { return PyLong_FromVoidPtr(static_cast(pointer)); } template 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; // A ScriptLib call may leave an error set while returning None (Py_BuildException with a // message, e.g. a missing image). AVA2 ScriptLib PyTuple_GetInteger ignores that stale error, so // only judge this conversion and leave the earlier error as it was. PyObject *type, *error, *traceback; PyErr_Fetch(&type, &error, &traceback); void* pointer = PyLong_AsVoidPtr(value); const bool failed = PyErr_Occurred() != nullptr; if (failed) PyErr_Clear(); PyErr_Restore(type, error, traceback); if (failed) return false; *out = static_cast(pointer); return true; }