LuaBridge and member functions

I just downloaded LuaBridge today and am very pleased with it so far. One thing I noticed is that I can get around the normal requirement of having lua_State as a function parameter.

I can do it:

//C++ files void love(int i) {std::cout << i;} luabridge::getGlobalNamespace(lua) .addFunction("love", love); -- Lua file love(8) 

and it will work fine, but if I do something:

 //C++ files struct Tester { int number; void MemFunction (int i) { std::cout << i;} static void Register(lua_State*); }; void Tester::Register(lua_State *lua) { luabridge::getGlobalNamespace(lua) .beginClass<Tester>("Tester") .addConstructor <void (*) (void)> () .addData("number", &Tester::number) .addFunction("MemFunction", &Tester::MemFunction) .endClass(); } --Lua file c = Tester() -- works... c.number = 1 -- works... c.MemFunction(10) -- nothing! 

Nothing I read in the documentation indicates that member functions with non-lua_State arguments cannot be registered, and I saw some LuaBridge codes do this without problems. What am I doing wrong here?

+4
source share
1 answer

You must use the method invocation syntax

 c:MemFunction(10) 

I suggest you use the newer version from github , which contains extensive documentation. It also gives added flexibility with respect to input parameters and return values.

+7
source

Source: https://habr.com/ru/post/1445691/


All Articles