Advertisement
Guest User

main.nim

a guest
Oct 23rd, 2017
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Nim 0.64 KB | None | 0 0
  1. import dynlib
  2.  
  3. type
  4.   setupProc = proc (toCall: proc(): string) {.nimcall.}
  5.   callProc = proc () {.nimcall.}
  6.  
  7.  
  8. var
  9.   dll: LibHandle
  10.   setup: setupProc
  11.   call: callProc
  12.   theValue = 2
  13.  
  14. proc myProc(): string =
  15.   theValue += 1
  16.   return "Something cool"
  17.  
  18. dll = loadLib("./liblib.so")
  19. if dll != nil:
  20.   let setupAddr = dll.symAddr("setup")
  21.   if setupAddr != nil:
  22.     setup = cast[setupProc](setupAddr)
  23.   let callAddr = dll.symAddr("call")
  24.   if callAddr != nil:
  25.     call = cast[callProc](callAddr)
  26.  
  27. if setup != nil:
  28.   setup(myProc)
  29.   call()
  30.   call()
  31.   call()
  32.   echo theValue
  33. else:
  34.   echo "Wasn't able to load setup() from DLL."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement