lua-users home
lua-l archive

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


Edgar Toernig wrote:
> 
> Peter Shook wrote:
> >
> > I call lua_settop with the number of arguments that the function
> > expects.  This has two benefits: any omitted arguments are set to nil,
> > and you can count on arguments being in the correct place relative to
> > the top of the stack [...]
> 
> ... and all argument handling functions stop working.
> 
> Sure, you can implement proper argument handling in each C function.
> The point is: what is encouraged by the given API?  Look at all the
> included libraries and you see what kind of argument handling is
> used.
> 
> The proposed change is easy for the API user: just tell the system
> how many arguments you expect.  Then use the provided functions to
> access them and you get a behaviour that is the same as that of Lua
> functions.
> 
> Ciao, ET.

But with lua_settop you get a behavior that is the same as that of Lua
functions without changing the API.  And how does the argument handling
function 'luaL_check_type' stop working in this example?

static int luaB_eventtable (lua_State *L) {
  luaL_check_type(L, 1, LUA_TTABLE);
  if (lua_isnull(L, 2))
    lua_geteventtable(L, 1);
  else {
    lua_settop(L, 2);
    luaL_check_type(L, 2, LUA_TTABLE);
    lua_seteventtable(L, 1);
  }
  return 1;
}

- Peter