lua-users home
lua-l archive

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


Hi all,

I have a very basic question about how a Lua C function should check
optional arguments. Let us suppose a C function with the following
prototype:

myfunc (s[, a, b])

where the two parameters a and b are optional. When the C function is
called what is the correct way to check for the optional parameters ?
Should I use lua_gettop to know how many parameters was given ? In
this case can be tricky because you can give explicitly a nil value
and in this case, even if it is nil, it will count as an additional
value in the stack. Otherwise I can be tempted to access the value on
the stack without checking with lua_gettop with the idea that if no
parameter was given the value that I will found on the stack will be
nil. In this case the question arises: it is legitimate to access
value beyond the top of the stack ? if yes, can I assume that I will
always obtain nil in this case ?

I know it is a dumb question :-) but I was not able to find an obvious
answer by myself!!

-- 
Francesco