[SOLVED] What does ... mean?
Posted: Sun Aug 17, 2014 11:34 pm
I've seen ... in code samples and such, but what is it?
Code: Select all
function foo(...)
This part isn't correct. It used to be with Lua 5.0, which the official online version of the Programming in Lua book is based on, but since Lua 5.1 (which was released in 2006 and is what LuaJIT is based on) it's no longer the case.veethree wrote:All the arguments you give the function are stored in a hidden table called arg.
Code: Select all
function foo(...)
local args = {...}
local arg1, arg2 = ...
local arg3, arg4, arg5 = select(3, ...)
local argcount = select("#", ...)
assert(args[1] == arg1)
assert(args[4] == arg4)
end
foo("one", "two", "three", "four", "five", "six")
Code: Select all
function bar(x, y, ...)
print("bar", x, y, ...)
end
bar(100, 100, os.date())
Code: Select all
function EntityManager:map(f, ...)
for _,v in pairs(self._entities) do
-- If the entity has the function f, then call it with the given vararg
if v[f] then v[f](v, ...) end
end
end
function love.update(dt)
self.entityManager:map('update', dt)
end
function love.draw()
self.entityManager:map('draw')
end
function love.keypressed(key, code)
self.entityManager:map('keypressed', key, code)
end
Code: Select all
local function CheckUserdata( ... )
local Userdata = {}
if type( ... ) ~= 'table' then Userdata = { ... } else Userdata = ... end
return Userdata
end
Code: Select all
function Blah( ... )
local BlahTable = CheckUserdata( ... )
end