lua-users home
lua-l archive

Re: Bug in lua_getfield() ?

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


Rici Lake <lua@ricilake.net> [2007年03月25日 23:36:16]:
> Petr Stetiar wrote:
> >The problem happens in my C lua_get_function(), which calls lua_getfield()
> >about 200 times per minute. 
> >
> >int lua_get_function(char *function)
> >{
> >	... snip ...
> >	lua_getfield(L, LUA_GLOBALSINDEX, function);
> >	... snip ...
> >}
> 
> Do you check to make sure that there was a hook with that name? It's 
> hard to tell from your snipped code.
> 
> You should be doing something like:
> 
> lua_getfield(L, LUA_GLOBALSINDEX, function);
> if (!lua_isnil(L, -1)) { ... call the function ... }
Ok, but the memory is already corrupted by lua_getfield(), even before check
lua_isnil().
-- ynezz

AltStyle によって変換されたページ (->オリジナル) /