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

javascript - Confirm a form & display message if form is valid with JQuery -

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -