Sign in to follow this  
Darksshades

Luabind - .property getter not working

Recommended Posts

Darksshades    125
Hey,

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:

[code]
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;
}
[/code]

The output here:
[code]
0
function: 005FC568
[/code]

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