Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR LUA

lua how to default value if nil

function foo(x, y, z)
    x = (x == nil) or x
    y = (y == nil and 1234) or y
    z = (z == nil and "default") or z
    print(x, y, z)
end

> foo()
true    1234    default
> foo(false, false, "me")
false   false   me
> foo(nil, 50, "me")
true    50  me
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #lua #default #nil
ADD COMMENT
Topic
Name
5+7 =