Advertisement
Guest User

Untitled

a guest
Aug 28th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. #include <Siv3D.hpp>
  2. #include <lua.hpp>
  3. #pragma comment(lib, "lua52.lib")
  4.  
  5. #include <LuaBridge.h>
  6. using namespace luabridge;
  7.  
  8. class A
  9. {
  10. public:
  11. A(const int val) : val_(val)
  12. {
  13. }
  14.  
  15. int f()
  16. {
  17. Println(L"f() : val=", val_);
  18. return 123 + val_;
  19. }
  20.  
  21. private:
  22. int val_;
  23. };
  24.  
  25. void Main()
  26. {
  27. // Initialize Lua
  28.  
  29. lua_State* L = luaL_newstate();
  30. luaL_openlibs(L);
  31.  
  32. luaL_dostring(L,
  33. "function luafunc(e)\n"
  34. " return e:f()\n"
  35. "end\n"
  36. );
  37.  
  38. // Register C++ classes using LuaBridge
  39.  
  40. getGlobalNamespace(L)
  41. .beginNamespace("foo")
  42. .beginClass<A>("A")
  43. .addFunction("f", &A::f)
  44. .endClass()
  45. .endNamespace();
  46.  
  47. // Call Lua function
  48.  
  49. LuaRef luafunc = getGlobal(L, "luafunc");
  50.  
  51. A a(90000);
  52.  
  53. int ret = luafunc(&a);
  54.  
  55. Println(ret);
  56.  
  57. WaitKey();
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement