Re: Inheriting from C++ Classes
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: Inheriting from C++ Classes
- From: liam mail <liam.list@...>
- Date: 2009年1月23日 14:52:00 +0000
2009年1月23日 Leo Razoumov
<slonik.az@gmail.com>
On 2009年1月23日, 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.