自定义全局函数的Python3.2运行时错误

发布于 11-25 10:40 字数 1488 浏览 0 评论 0原文

因此,我所有的自定义类和函数调用都工作得很好,但我有一个全局函数,它返回对我们的游戏对象工厂的引用,以便我们可以在脚本中创建游戏对象。
该引用保证在程序和脚本的生命周期中存在,因此引用是安全的。
现在这是我收到的错误和我正在使用的代码。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文