Open inv2004 opened 3 years ago
Ok, looks like I found the same issue, so the question is:
1) Is there any option to expose proc without precompiled .so or .pyd? 2) Any future plans to support expose classes?
Thank you,
import nimpy
type NimObj = ref object x: int
proc fn1(o: NimObj, x: int) = o.x.inc(x)
pyGlobals()["fn1"] = fn1 # Add function to python globals
discard pyBuiltinsModule().exec """ class MyClass: def method1(self, obj): fn1(obj, 1) """
let obj = NimObj()
let MyClass = pyGlobals()["MyClass"].to(proc():PyObject) # Get MyClass constructor from globals let c = MyClass() discard c.method1(obj) discard c.method1(obj)
echo obj.x
Hello, Is it possible to export object type and its function into python, but without using precompiled module?
Here is an example, which works, but I put comment there:
My next idea is to export nim-class somehow, and in python use the following: