lua-users home
lua-l archive

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


I have observed the following thing with a lua C function, such as:

// C

int f ( lua_State * L )
	lua_Number n1 = lua_tonumber ( L , 1 ) ;
	lua_Number n2 = lua_tonumber ( L , 2 ) ;

	return 0 ;

lua_register ( L , "f" , f ) ;

and :

-- LUA

f ( 3 )

if this function is passed a given number of arguments, attempting to get an
argument with an absolute index greater than the actual number of received
arguments will return the object at that position as long as it is not
beyond the absolute top of the stack. Therefore, lua_tonumber ( L , 2 ) will
try to convert whatever is in the stack at that position, disregarding the
fact that there is only one argument.

I would have expected all lua_to... functions to behave in that situation as
if nil was found at that position.

What is the official behaviour ? Do C functions have to explicitly check the
number of arguments before getting them ?