lua-users home
lua-l archive

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


>From steve@inquisit.com Thu May 14 02:43:03 1998
>
>I may have asked this before, but is there any way to ask Lua for the
>number of arguments that a given Lua function expects?

no. the number of arguments that a function expects is not a notion in Lua.
sorry.
what do you need this for?

there are ways to fake this, however.
you can create a table with the number of args plus the functions itself,
and use tag methods to aloow the function to be called directly and at the
same time check the number or do whatever you want to do:

function f(x,y) ... end

f={n=2,f=f}

f(a,b,c) -- this gives an error

f(a,b) -- this is ok. the tag method uses 'call'.

something like this.

--lhf