Search
 
SCRIPT & CODE EXAMPLE
 

LUA

lua how to default value if nil or false

local function foo(x, y, z)
    local x = x or true
    local y = y or 1234
    z = z or "default"
end
Comment

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
Comment

PREVIOUS NEXT
Code Example
Lua :: Ackermann function lua 
Lua :: how to make a run in roblox lua 
Lua :: how to make a math text in lua 
Lua :: lua to float 
Lua :: Roblox Studio Mouse Shaking 
Lua :: open while loop lua 
Lua :: roblox lua exploiting rconsole 
Matlab :: matlab get row from matrix 
Matlab :: transfer function get num and den matlab 
Matlab :: matlab preallocate array size 
Matlab :: matlab 1d matrix declarationg 
Matlab :: sin in scilab 
Basic :: vb string to int32 
Basic :: powershell how to removve only empty direcoties 
Basic :: dos assign command output to variable (when output is of multiple lines) 
Elixir :: elixir string concatination 
Elixir :: elixir eval ast 
Elixir :: elixir new structs 
Scala :: scala split string to list 
Scala :: scala list all permutations 
Actionscript :: Create menu group in Maximo 
Excel :: excel paste delimited text into separate columns 
Perl :: perl for 
Pascal :: pascal input number 
Powershell :: disable defender powershell 
Gdscript :: gdscript while loop 
Cobol :: google apps script remove nulls array 
Assembly :: how to import servo library in arduino 
Assembly :: why assembly language use register 
Javascript :: jquery vslidation remove spaces from input 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =