lua-users home
lua-l archive

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


Veli-Pekka Tätilä wrote:
In particular, the new var-arg syntax baffles me even having read the vararg second class citizen article in the Lua wiki. Why the change to make vararg processing more cumbersome?
It's faster. A lot of vararg functions can be written now without any creating any objects, where as before trying to write, for example, assert in Lua would have been very slow. Now it just looks like this:

function assert(val, ...)
 if not val then
   error(... or "assertion failed")
 end
 return val, ...
end

Quite a bit nicer, neater and a lot faster then the old way where the last line would look like:
 return cond, unpack(arg)

And where you need to iterate over the arguments, or address them via number, the creation of a table is incredibly simple:
 local arg = {...}

I do liek the fact that the list has a name like ... now, and you can even pass such lists to modules. Which reminds me, can I pass extra args to modules when requiring them, like i can in Perl's use operator? How does the module magiclly get its name as the first element of ... anyway?

According to http://www.lua.org/manual/5.1/manual.html#pdf-require require passes modname to the loader, and does not take any additional arguments. Surprised actually, thought it would pass them on.

- Alex