[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Oddity with tinsert (Lua 4.0)
- From: Edgar Toernig <froese@...>
- Date: Mon, 13 Aug 2001 21:38:16 +0200
Reuben Thomas wrote:
> However, in general I think best practice is to make C API functions behave
> just like Lua ones when passed more or fewer arguments. Unfortunately there
> are a few standard functions that break this (they can tell the difference
> between being passed a nil final argument and no final argument), but it's a
> good thing to work towards; then no-one is surprised.
I did this in Sol. It changes the C-API though.
The functions to push C functions (lua_pushcfunction, lua_pushcclosure) take
an additional argument, the minimum number of arguments expected by that
function. Before calling that functions the VM checks if there are at least
that number of arguments and pushes additional nils if necessary.
The lua_isnull is gone as is LUA_TNONE. All lauxlib functions that check
for optional arguments check against nil. IMHO the LUA_TNONE stuff (and
lua_isnull) is bogus anyway. They just work well if there are no upvalues
on the stack and you haven't pushed anything yourself.
Basically that's all.
PS: And upvalues in Sol are not pushed as additional arguments (that just
disturbs the normal argument handling) but can be access with high index
numbers (10001 for first upvalue, 10002 for 2nd, ...).