Has anyone got a quick example of how to call Nim procs (simple ones, just a string parameter or similar) from a Lua script running from within a Nim compiled application?
Cheers!
Just as how it's done from any other languages:
import lua
proc nimluafunc(L: PState): cint {.cdecl.} =
let i = tonumber(L,1)
let j = tonumber(L,2)
let k = i + j
pushnumber(L,k)
result = 1
let l = newstate()
openlibs(L)
register(L, "callablefromlua", nimluafunc)
discard dostring(L,"""
x = callablefromlua(3,7)
print(x)
""")
Works for me on Win10, 64 bits, msys2 shell. Additionally, I copied some lua5.2.dll (cannot remember where from, probably the LuaBinaries) into the project folder.
$ nim -v
Nim Compiler Version 0.14.2 (2016-06-09) [Windows: amd64]
$ lua
Lua 5.3.2 Copyright (C) 1994-2015 Lua.org, PUC-Rio
$ sha256sum.exe lua5.2.dll
f1e91a4974d693660bb20406becff0048c394cacef748dae254b5f8ddee38816 *lua5.2.dll
Then did a nimble install lua and just import lua52 into my test app. lua52.nim has this ID:
$Id: lua.h,v 1.283 2012/04/20 13:18:26 roberto Exp $
Compiling lua52.nim failed initialy due to some spaces issue; on line 13 LUA_RELEASE = ... have replaced:
&"."& with & "." &
Then the project compiled and ran fine.