Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### NIM
- import
- lua
- proc NimMain() {.importc.}
- proc get_hello*(state: PState): cint {.cdecl, exportc, dynlib.} =
- state.pushstring("Hello!")
- return 1
- let
- test* = [
- Treg(name: "get_hello", `func`: get_hello),
- Treg(name: nil, `func`: nil)
- ]
- proc luaopen_test*(state: PState): cint {.cdecl, exportc, dynlib.} =
- NimMain()
- echo state.isNil
- var lr = unsafeAddr(test[0])
- var nup = cint(test.len-1)
- state.openlib(cstring"test", lr, nup)
- return 1
- ### LUA
- local path = "/your/global/path/test.so"
- print("1")
- local f = package.loadlib(path, "luaopen_test")
- print("2")
- local f = f()
- print("3")
- print(f.get_hello())
- print("yay!")
- ### RUN
- nim c --app:lib --noMain -o:test.so test.nim
- lua main.lua
- lua -v
- Lua 5.3.3 Copyright (C) 1994-2016 Lua.org, PUC-Rio
- nim -v
- Nim Compiler Version 1.2.0 [Linux: amd64]
- Compiled at 2020-04-03
- Copyright (c) 2006-2020 by Andreas Rumpf
- active boot switches: -d:release
Advertisement
Add Comment
Please, Sign In to add comment