[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Inheritance
- From: Christoph Schreiber <luky0711@...>
- Date: Sun, 9 May 2010 18:27:08 +0000 (GMT)
>> Also, please do not post your questions as
>> follow-ups to unrelated mailing list threads.
Oops. Sorry.
Here is the full function. I don't understand how lua knows which base class to call. I return only the method name. I always thougt the return value (1 in this case) tells lua how many values I return on the stack.
int ChildClass::index(lua_State* L)
{
// searches for the method in child's metatable
const char* key = luaL_checkstring(L, 2);
lua_getmetatable(L, 1);
lua_getfield(L, -1, key);
// if it doesn't find the method it calls
// the method of the base class
if(lua_isnil(L, -1))
{
luaL_getmetatable(L, BaseClass::classId);
lua_getfield(L, -1, key);
}
return 1;
}
--- Florian Weimer <fw@deneb.enyo.de> schrieb am So, 9.5.2010:
> Von: Florian Weimer <fw@deneb.enyo.de>
> Betreff: Re: Inheritance
> An: lua@bazar2.conectiva.com.br
> Datum: Sonntag, 9. Mai, 2010 20:18 Uhr
> * Christoph Schreiber:
>
> > The following code works. But I don't understand why.
> That drives me nuts.
> >
> > int ChildClass::index(lua_State* L)
> > {
> > const char* key =
> luaL_checkstring(L, 2);
> > lua_getmetatable(L, 1);
> > lua_getfield(L, -1, key);
> > if(lua_isnil(L, -1))
> > {
> >
> luaL_getmetatable(L, Base::classId);
> > lua_getfield(L,
> -1, key);
> > return 1;
> > }
>
> A closing brace is missing in that snippet. Perhaps
> you did not copy
> the full function? And you shold really tell us what
> is so surprising
> to you.
>
> Also, please do not post your questions as follow-ups to
> unrelated
> mailing list threads.
>