vararg
is a library for manipulation of variable arguments of
Lua functions.
These functions basically allow you to do things with vararg that cannot be efficiently done in pure Lua but can be easily done through the C API.
Actually, the main motivation for this library was the 'pack' function, which is an elegant alternative for the possible new standard function 'table.pack' and the praised 'apairs'. Also 'pack' allows an interesting implementaiton of tuples in pure Lua.
Use | Equivalent |
---|---|
p = pack(...) |
|
p() | ... |
p("#") | select("#", ...) |
p(i) | (select(i, ...)) |
p(i, j) | unpack({...}, i, j) |
for i,v in p do | for i,v in apairs(...) do |
range(i, j, ...) | unpack({...}, i, j) |
remove(i, ...) | t={...} table.remove(t,i) return unpack(t,1,select("#",...)-1) |
insert(v, i, ...) | t={...} table.insert(t,i,v) return unpack(t,1,select("#",...)+1) |
replace(v, i, ...) | t={...} t[i]=v return unpack(t,1,select("#",...)) |
append(v, ...) | c=select("#",...)+1 return unpack({[c]=val,...},1,c) |
map(f, ...) | t={} n=select("#",...) for i=1,n do t[i]=f((select(i,...))) end return unpack(t,1,n) |
concat(f1,f2,...) | return all the values returned by invocation of functions f1,f2,... |
Download
You can install VarArg through LuaRocks using the following command.
luarocks install vararg
This library is provided as free software under the terms of the MIT License, which are the same terms of the Lua License.
For download see the list of released packages.
Author
This project was created by Renato Maia.