Sign in to follow this  

Luabind - .property getter not working

Recommended Posts


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
int stack;
Test(){stack = 0;}
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();
//Bind the class to lua
luabind::module(l) [
.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)
"rs = test.stack\n"
//Close lua
return 0;

The output here:
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?

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this