lua-users home
lua-l archive

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


In the great anticipation of Lua 3.1 (which I'm _really_ looking forward to),
I thought of another language mis-feature which I'm not happy about. 

I don't like that you can't accept variable arguments to a Lua function, and
I don't like that you can't compose an argument list to pass to another
function. 

The var-args case is pretty well known and understood. The best "solution" I
can think of is to set varargs as a property of the function. Basically,
create the function, and then specify it as a varargs function, which will
set a tag method for handling function calls. Then that tag method (written
in C) will gather up the arguments, put them into a Lua table, and pass them
in as one table argument.

function a_varargs_fn(myargs)

   -- myargs should be a table of arguments
end

make_varargs(a_varargs_fn);


Second, consider writing a "perform" function in Lua, which takes as
arguments "a table", "a method name", and "an argument list" It's easy to
resolv the method from the method name, but there is no way to call that
method with an arbitrary list of arguments. 

Again, this could be facilitated from C, so that you would pass your method
and table of arguments to a "call_function_with_args". That C function would
then pull args out of the table and dispatch them to the function call.

----

That said, I feel like I just walked myself into a corner because of how easy
these shortcomings are to solve. How about an inclusion of these two
functions as standard in the Lua runtime?

-- 
David Jeske (N9LCA) + http://www.chat.net/~jeske/ + jeske@chat.net