Guest User

what's wrong :(

a guest
Jun 18th, 2020
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Nim 0.95 KB | None | 0 0
  1. ### NIM
  2.  
  3. import
  4.   lua
  5.  
  6. proc NimMain() {.importc.}
  7.  
  8. proc get_hello*(state: PState): cint {.cdecl, exportc, dynlib.} =
  9.   state.pushstring("Hello!")
  10.   return 1
  11.  
  12. let
  13.   test* = [
  14.     Treg(name: "get_hello", `func`: get_hello),
  15.     Treg(name: nil, `func`: nil)
  16.   ]
  17.  
  18. proc luaopen_test*(state: PState): cint {.cdecl, exportc, dynlib.} =
  19.   NimMain()
  20.   echo state.isNil
  21.   var lr = unsafeAddr(test[0])
  22.   var nup = cint(test.len-1)
  23.   state.openlib(cstring"test", lr, nup)
  24.   return 1
  25.  
  26. ### LUA
  27. local path = "/your/global/path/test.so"
  28. print("1")
  29. local f = package.loadlib(path, "luaopen_test")
  30. print("2")
  31. local f = f()
  32. print("3")
  33. print(f.get_hello())
  34.  
  35. print("yay!")
  36.  
  37. ### RUN
  38. nim c --app:lib --noMain -o:test.so test.nim
  39. lua main.lua
  40.  
  41. lua -v
  42. Lua 5.3.3  Copyright (C) 1994-2016 Lua.org, PUC-Rio
  43. nim -v
  44. Nim Compiler Version 1.2.0 [Linux: amd64]
  45. Compiled at 2020-04-03
  46. Copyright (c) 2006-2020 by Andreas Rumpf
  47.  
  48. active boot switches: -d:release
Advertisement
Add Comment
Please, Sign In to add comment