Jump to content

View more

Image of the Day

Inventory ! Va falloir trouver une autre couleur pour le cadre D: #AzTroScreenshot #screenshotsaturday https://t.co/PvxhGL7cOH
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Luabind - .property getter not working

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
No replies to this topic

#1 Darksshades   Members   

125
Like
0Likes
Like

Posted 08 July 2012 - 10:59 AM

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:

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?




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.