How can I export C++ pointer to lua? -


in c++, have 2 class

class { void a_func(); }  class b { a* _a; a* geta(){return _a;} } 

and then, suppose have userdata object of b, b.

a = b:geta(); a:a_func(); 

question is, how can implement b::geta ?

probably, guys let me use lightuserdata. but, far can know, lightuserdata not have individual metatable. so, if pushed pointer lightuserdata, still can not use a_func() above. , since not creating a here, lua_newuserdata can not used too.

in case, think lua_pushuserdata doesn't exist suits me well.


(update)

int b::geta_lua(lua_state* l)  {   void* p = lua_newuserdata(l, sizeof(pointer));   memcpy(p, &_a, sizeof(pointer);   lua_getmetatable();   lua_setmetatable();   return 1; }  int a::a_func_lua(lua_state* l) {   void* p = lua_touserdata();   (a*)(*p)->*a_func_pointer();   return 0; } 

is solution ?

int b::geta_lua(lua_state* l)  {   void* p = lua_newuserdata(l, sizeof(pointer));   memcpy(p, &_a, sizeof(pointer);   lua_getmetatable();   lua_setmetatable();   return 1; }  int a::a_func_lua(lua_state* l) {   void* p = lua_touserdata();   (a*)(*p)->*a_func_pointer();   return 0; } 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -