python - Adding new command to module through C-API? -


how dynamically add methods module through c-api? have many functions need register, , not in same array. assume can initialize module null method table, documentation says that's possible.

pyobject *mymod = py_initmodule("my", null); 

what name of function add methods 1 @ time.

basically, you'll have ahold of module dict first:

d = pymodule_getdict(m); 

store module name in pystring object:

n = pystring_fromstring("modname"); 

then populate pymethoddef struct ml , create new callable:

v = pycfunction_newex(&ml, (pyobject*)null, n); 

and add callable keyed function name module dict:

pydict_setitemstring(d, ml->ml_name, v); 

i've skipped relevant error checks.

all interpretation py_initmodule4 (py_initmodule macro calling py_initmodule4 default arguments).


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -