lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]




2009/1/23 Leo Razoumov <slonik.az@gmail.com>
On Fri, 23 Jan 2009, Ignacio Burgueño wrote:
[..snip..]


lcbBaseObject.h contains a lot of stuff you won't need at all. Is just there for the RegType struct, so you can rip this:
      typedef struct { T* pT; } userdataType;
       typedef int (T::*mfp)(lua_State* L);
       typedef struct {
               const char* name;
               mfp mfunc;
       } RegType;

and paste it somewhere else.


What is the purpose of


typedef int (T::*mfp)(lua_State* L);

Type mpf refers to a C++ member function of class T and cannot be made into Lua C-closure because it implicitly passes this-pointer as an extra argument.

--Leo--
It is not made into a C-closure instead a  thunk function is called which has an upvalue of the struct which does the work
// member function dispatcher
       static int thunk_methods(lua_State* L) {
               // stack has userdata, followed by method args
               T* obj = Base::check(L, 1);  // get 'self', or if you prefer, 'this'
               //lua_remove(L, 1);  // remove self so member function args start at index 1
               // get member function from upvalue
               RegType* l = static_cast<RegType*>(lua_
touserdata(L, lua_upvalueindex(1)));
               return (obj->*(l->mfunc))(L);  // call member function
       }

It looks just like the Luna/Lunar binding although it does not give it credit by including the copyright notice which is required.