所以我的所有自定义类和函数调用都运行得很好,但是我有一个全局函数,它返回对游戏对象工厂的引用,以便我们可以在脚本中创建游戏对象。
这个参考保证在程序和脚本的生命周期中存在,因此参考是安全的
现在这里是我得到的错误以及我正在使用的代码。
Traceback (most recent call last):
File "testscript.py", line 7, in <module>
Factory = Globals.GetFactory()
SystemError: Bad call flags in PyCFunction_Call. METH_OLDARGS is no longer suppo
rted!
//get factory is my function pointer to above mentioned function
PyMethodDef globalMethods[] =
{
{"GetFactory", (PyCFunction)GetFactory, METH_VARARGS,
"Gets the Factory"},
{NULL, NULL, 0, NULL}
};
//define out custom types module
PyModuleDef def = { PyModuleDef_HEAD_INIT,
"Globals",
0, -1, globalMethods, 0, 0, 0, 0 };
//push back onto module def ( makes a copy and makes it so pointer just doesn't change
//for the life of the program while python access this data )
gPyTypeObjects->mCustomeModulesDef.push_back(def);
//save the modules memory address by placing it in a list also
PyObject * mod = PyModule_Create(&gPyTypeObjects->mCustomeModulesDef.back());
ERROR_IF( mod == NULL, "Failed to create custom pyModule Globals" );
Py_INCREF(mod);
gPyTypeObjects->mCustomModules.push_back(mod);
return gPyTypeObjects->mCustomModules.back();
}
我正在努力提供尽可能多的材料,以免遗漏任何东西 但是在大多数情况下,我确信除了PyModuleDef之外你只需要错误和PyMethodDef来帮助我。