Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Siv3D.hpp>
- #include <lua.hpp>
- #pragma comment(lib, "lua52.lib")
- #include <LuaBridge.h>
- using namespace luabridge;
- class A
- {
- public:
- A(const int val) : val_(val)
- {
- }
- int f()
- {
- Println(L"f() : val=", val_);
- return 123 + val_;
- }
- private:
- int val_;
- };
- void Main()
- {
- // Initialize Lua
- lua_State* L = luaL_newstate();
- luaL_openlibs(L);
- luaL_dostring(L,
- "function luafunc(e)\n"
- " return e:f()\n"
- "end\n"
- );
- // Register C++ classes using LuaBridge
- getGlobalNamespace(L)
- .beginNamespace("foo")
- .beginClass<A>("A")
- .addFunction("f", &A::f)
- .endClass()
- .endNamespace();
- // Call Lua function
- LuaRef luafunc = getGlobal(L, "luafunc");
- A a(90000);
- int ret = luafunc(&a);
- Println(ret);
- WaitKey();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement