Extended functions in embedded code

Chris Angelico rosuav at gmail.com
Tue Oct 13 19:30:12 EDT 2015


On Wed, Oct 14, 2015 at 7:28 AM, Ervin Hegedüs <airween at gmail.com> wrote:
> Hi Chris,
>
> what I misses: currently I'm using Python 2.7.

Oh, sorry. In that case, you'll be importing "__builtin__" rather than
"builtins", but the same technique works.

> On Wed, Oct 14, 2015 at 02:48:57AM +1100, Chris Angelico wrote:
>> It'd look broadly like this:
>>
>> /* initialize the interpreter, yada yada */
>> PyObject *builtins = PyImport_ImportModule("builtins");
>> PyModule_AddFunctions(builtins, mymodule_methods);
>
> PyModule_AddFunction was introduced in Python 3.5. Most of stable
> Linux distribution has Python 3.4

It's been years since I actually did this, so I cheated and just
flipped through the docs :) But there'll be a way to create a Python
function from a C function, and then you can simply stuff that into
the module's dictionary.

ChrisA



More information about the Python-list mailing list