I wrote simple code of Nim nim.nim below.
proc nimSample*(n: cint) {. exportc .} =
echo n
also by Python3
import ctypes
nim = ctypes.CDLL('nim')
arg = ctypes.c_int(1)
nim.nimSample(arg)
But there are not available. Error message below.
Segmentation fault: 11
Please let me know why this code is not available.
Thanks.
# Compile: nim c --app:lib --out:pymodule.so thisfile.nim
import nimpy
proc myfunction*(name: string): string {.exportpy.} =
"Hello " & name
Thank you for all your kindness.
But I got error message Error: undeclared identifier: 'nnkTupleConstr' using nimpy on nim 0.18.0.
But I got error message
That one is fixed.
Now regarding your first question. When calling nim function from a foreign runtime you have to make sure that nim's GC is configured properly. Quick way to check it is to do GC_disable() as the very first operation of your externally called function. If it works, it means that nim GC is initialized with wrong stack bottom (see nimGC_setStackBottom). nimpy does that for you, but iirc you'll need a more recent nim version.
you’ll need a more recent nim version.
More recent than release (0.18.0)?