Re: Inheriting from C++ Classes
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: Inheriting from C++ Classes
- From: Ignacio Burgueño <ignaciob@...>
- Date: 2009年1月23日 12:58:25 -0200
Leo Razoumov wrote:
On 2009年1月23日, Ignacio Burgueño wrote:
[..snip..]
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.
Indeed, its not made into a closure. It is used instead by this function:
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
}
l->mfunc is of type mfp, and the function thunk_methods is the c closure
indeed.
Regards,
Ignacio