在初始化嵌入式Python的同时,在运行时创建Python3模块 [英] Create a Python3 module at runtime while initialize an embedded Python

查看:120
本文介绍了在初始化嵌入式Python的同时,在运行时创建Python3模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个实现自定义编程语言的DLL.我想做的就是添加对python语言的支持,并保持与"API函数"相同的代码.

We have a DLL that implements a custom programming language. What I want to do is adding support for the python language keeping the same code for "API function".

我已经在该DLL中成功嵌入了python,现在我正在解决将所有旧功能公开为python模块的问题.

I have succefully embedded python in this DLL, now I'm approaching the problem to expose all the old function as a python module.

现在,该DLL不会将API函数公开为接口函数,而是已安装(作为函数指针)到语言引擎.这样就不可能创建一个新的python模块(一个新的DLL).但是我需要保持与旧方法的兼容性...

Now this DLL doesn't expose the API function as interface function but it's installed (as function pointer) to the language engine. In this way it's impossible to create a new python module (a new DLL). But I need to keep the compatibility with the old method...

是否可以在运行时创建(并安装)在Python所在的同一个DLL中定义的模块?

It's possible to create (and install) at runtime a module defined in the same DLL where the Python is located?

我认为有点像在PyInitialize()之后调用PyInit_xxxx方法;

I think something like calling the PyInit_xxxx method after PyInitialize();

推荐答案

我已经使用像这样的代码之前 Py_Initialize();

I've solved using a code like this before Py_Initialize();

/* Add a built-in module, before Py_Initialize */
PyImport_AppendInittab("xxx", PyInit_xxx);

这篇关于在初始化嵌入式Python的同时,在运行时创建Python3模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆