Guest User

Untitled

a guest
Sep 12th, 2012
42
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. hellobind.cpp:
  2. 1 extern "C"
  3. 2 {
  4. 3 #include <lua5.1/lua.h>
  5. 4 }
  6. 5 #include <iostream>
  7. 6 #include <luabind/lua_include.hpp>
  8. 7 #include <luabind/luabind.hpp>
  9. 8
  10. 9 void greet()
  11. 10 {
  12. 11 std::cout << "hello world!\n";
  13. 12 }
  14. 13
  15. 14 extern "C" int init(lua_State* L)
  16. 15 {
  17. 16 using namespace luabind;
  18. 17
  19. 18 open(L);
  20. 19
  21. 20 module(L)
  22. 21 [
  23. 22 def("greet", &greet)
  24. 23 ];
  25. 24
  26. 25 return 0;
  27. 26 }
  28.  
  29. building:
  30. $ g++ hellobind.cpp -llua5.1 -lluabind -I/usr/include/lua5.1/ -c -fPIC
  31. $ g++ -shared -Wl,-soname,libhellobind.so.0 -o libhellobind.so.0.0 hellobind.o
  32.  
  33. test.lua:
  34. 1 local path = "libhellobind.so.0.0"
  35. 2 local f = package.loadlib(path, "init")
  36. 3 greet()
  37.  
  38.  
  39. output:
  40. $ lua test.lua
  41. lua: test.lua:3: attempt to call global 'greet' (a nil value)
  42. stack traceback:
  43. test.lua:3: in main chunk
  44. [C]: ?
  45.  
  46. other info:
  47. $ uname -a
  48. Linux gmans-magicbox 3.5.3-custom #2 SMP Sun Aug 26 09:02:47 CEST 2012 x86_64 GNU/Linux
  49. $ gcc --version
  50. gcc (Debian 4.7.1-7) 4.7.1
  51. $ lua -v
  52. Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio
RAW Paste Data