I just began learning luabind and I'm trying to get the .property getter to work but with no luck.
When I set the getter to a lua variable and try to print it... it prints the function address instead of the value.
I made a simple program to test it here:
using namespace std;
class Test
{
private:
int stack;
public:
Test(){stack = 0;}
~Test(){}
void addStack(){stack++;}
void sayStack(){cout << stack << endl;}
int getStack(){return stack;}
void setStack(int stk){stack = stk;}
};
int main()
{
lua_State* l = luaL_newstate();
luaL_openlibs(l);
luabind::open(l);
//Bind the class to lua
luabind::module(l) [
luabind::class_<Test>("Test")
.def("sayStack", &Test::sayStack)
.def("addStack", &Test::addStack)
.property("stack", &Test::getStack, &Test::setStack)
];
//Create a Test class
Test ts;
//Make lua global test equal to local ts
luabind::globals(l)["test"] = &ts;
//Should make rs = stack,
//Say stack and then print the rs(print same as sayStack)
luaL_dostring(l,
"rs = test.stack\n"
"test:sayStack()\n"
"print(rs)\n"
);
//Close lua
lua_close(l);
return 0;
}
The output here:
0
function: 005FC568
I tried the setter and it works just fine.... its just the getter that doesnt work.
Does anybody have an idea why and how to get the getter to work?