So I'm trying to embed Python in Nim using the nim-lang/python port.
In src/python.nim there's this code -
PyMethodDefPtr* = ptr PyMethodDef
PyMethodDef*{.final.} = object # structmember.h
mlName*: cstring
mlMeth*: PyCFunction
mlFlags*: int
mlDoc*: cstring
I know how to create an instance of PyMethodDef -
let myMethodDef: PyMethodDef = PyMethodDef(mlName : "myMethodName", mlMeth : myMethod)
where myMethod is of type PyCFunction that is defined as a specific proc signature.
But I don't know how to create an instance of PyMethodDefPtr to pass into some other function. Can someone help me out?
I may miss something...
You know alloc and alloc0 from manual? That procs can be use to allocate memory for untraced pointers on the heap. Like
var myMethodDef: PyMethodDefPtr = cast[PyMethodDefPtr](alloc0(sizeof(PyMethodDef))
myMethodDef[] = PyMethodDef(mlName : "myMethodName", mlMeth : myMethod)
First line allocates memory, second line copies data. Of course untested, I think I have never used alloc() myself yet.