PageRenderTime 43ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Examples/lua/pointer/runme.lua

#
Lua | 48 lines | 27 code | 9 blank | 12 comment | 1 complexity | 8d90a53d1fe5df43f9b66795d42c280f MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. ---- importing ----
  2. if string.sub(_VERSION,1,7)=='Lua 5.0' then
  3. -- lua5.0 doesnt have a nice way to do this
  4. lib=loadlib('example.dll','luaopen_example') or loadlib('example.so','luaopen_example')
  5. assert(lib)()
  6. else
  7. -- lua 5.1 does
  8. require('example')
  9. end
  10. -- First create some objects using the pointer library.
  11. print("Testing the pointer library")
  12. a = example.new_intp()
  13. b = example.new_intp()
  14. c = example.new_intp()
  15. example.intp_assign(a,37)
  16. example.intp_assign(b,42)
  17. print(" a = "..tostring(a))
  18. print(" b = "..tostring(b))
  19. print(" c = "..tostring(c))
  20. -- Call the add() function with some pointers
  21. example.add(a,b,c)
  22. -- Now get the result
  23. r = example.intp_value(c)
  24. print(" 37 + 42 = "..r)
  25. -- Clean up the pointers
  26. -- since this is C-style pointers you must clean it up
  27. example.delete_intp(a)
  28. example.delete_intp(b)
  29. example.delete_intp(c)
  30. -- Now try the typemap library
  31. -- This should be much easier. Now how it is no longer
  32. -- necessary to manufacture pointers.
  33. print("Trying the typemap library")
  34. r = example.sub(37,42)
  35. print(" 37 - 42 = "..r)
  36. -- Now try the version with multiple return values
  37. print("Testing multiple return values")
  38. q,r = example.divide(42,37)
  39. print(" 42/37 = "..q.." remainder "..r)