自定义全局函数的Python3.2运行时错误
因此,我所有的自定义类和函数调用都工作得很好,但我有一个全局函数,它返回对我们的游戏对象工厂的引用,以便我们可以在脚本中创建游戏对象。
该引用保证在程序和脚本的生命周期中存在,因此引用是安全的。
现在这是我收到的错误和我正在使用的代码。
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 来帮助我。
So all of my custom classes and function calls work just fine, but I have a global function that returns a reference to our game object factory so that we can create game objects in a script.
This reference is guaranteed to exist for the life of the program and script so a reference is safe.
Now here is the error I am getting and the code I am using.
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();
}
I am trying to provide as much material as needed to not leave anything out.
But for the most part I'm sure you only need the error and the PyMethodDef in addition to the PyModuleDef to help me out here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论