lua-users home
lua-l archive

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


Hi Eero,

If your host program chokes, you've done a bad thing in your C code.  If you call 'lua_gettable' with a key for witch there is no value, then 'nil' will be left on top of the stack, but the program won't choke.  Your index argument to lua_gettable may not be pointing to a table.

Check the type before you call lua_gettable.  Try adding this:

luaL_check_type(L, index, LUA_TTABLE);
lua_gettable(L, index);
if (lua_isnil(L, -1)) { /* why nil? */ }
else { /* okay */ }

Is your __index metamethod a table or a function?  If it is a table, then not much can go wrong.  If it is a function, then add more checks to it.  Check that stack index 1 is the userdata that you expect.

It would be helpful to see your __index code.

- Peter