lua-users home
lua-l archive

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


I am trying to write a C extension to lua and I am wondering what the rules are when it comes to stack cleanup. Specifically I have a function which checks for a field in a table and checks its metamethod:

static MyStruct ToStructIndirect(lua_State * L, int index, const char * name)
   void * p = NULL;
   lua_getfield(L, index, name);
if (lua_isnil(L, index)) luaL_error(L, "Field `%s' does not exist", name);
   p = luaL_checkudata(L, -1, MYSTRUCT_METATABLE);
   lua_pop(L, 1);
   return *(MyStruct*)p;

So this function is effectively type checking a tables field and returning its value. If the field doesn't exist then an error is raised and a nil value is left on the stack. If the field is there but checkudata fails, once again a value is left on the stack.

What actually happens to the value left on the stack? Can I basically just forget about it?