Strange statement in Lua

Ok, so I am new to Lua, so it can be a very stupid question, but I came across the following statement and I have no idea what this means (even after some searching)

if (...) then

   -- Doing some stuff

end

What does it mean ...?

+4
source share
2 answers

...used in vararg functions . Its value is a list of all the "extra" arguments (i.e. those that follow the last named argument of the current function.)

(...) (like any other expression in parentheses) sets the result to one value (the first in the list).

, if " false nil."

:

local function f1(...)
  if (...) then
    return true
  else
    return false
  end
end

local function f2(x, ...)
  if (...) then
    return true
  else
    return false
  end
end

print(f1())       -- false
print(f1(1))      -- true
print(f1(1, 2))   -- true
print(f1(1, nil)) -- true
print(f1(nil, 2)) -- false

print(f2())       -- false
print(f2(1))      -- false
print(f2(1, 2))   -- true
print(f2(1, nil)) -- false
print(f2(nil, 2)) -- true

(.. function . . . end) - , (.. script .)

, (...) . if(...) , .

script, (...) ( if(...) , - .)

+3

... , , . , .

, :

function vafun(num, ...)
    if (...) then
        for _, v in ipairs{...} do
            print(v)
        end
    else
        print("empty var")
    end
end

if(...) , .

vafun(3, 4, 5)
vafun(3)
vafun()

:

4
5
empty var
empty var
+1

All Articles