lua-users home
lua-l archive

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


On Mon, Oct 27, 2003 at 04:28:45PM -0500, RLake@oxfam.org.pe wrote:
> > Is there any way to determine how many arguments an arbitrary function 
> > expects?
> 
> No.

hmmm, couldn't one say that the Lua function 'function(x) end'
expects one argument and 'function(x, y, ...) end' expects at least
two arguments, irrespective of how many they actually receive ?

the debug interface currently doesn't expose the "numparams" and
"is_vararg" elements of LClosure.  it would be easy to add them
(maybe as part of lua_getinfo() 'S' option ??) if someone really
needed them.
 
>
> f=function(x, y, ...) end
> =debug.getinfo(f).is_vararg
1
> =debug.getinfo(f).numparams
2
> =debug.getinfo(print).is_vararg
-1
> =debug.getinfo(print).numparams
-1
> 

-taj