How to set a default parameter in function?

Hi,
The title says all, i want to set a default parameter for a function om lua like in python:

def wowThisNameIsVeryLongIdkWhyINamedThisFunctionLikeThat(a, b, c=3)
    print(a + b + c)

wowThisNameIsVeryLongIdkWhyINamedThisFunctionLikeThat(1, 2)

Results:
6

You can use typed Lua or check the parameters at the start of the function.

local function f(a, b, c)
	c = tonumber(c) or 3
	print(a + b + c)
end

f(1, 2) -- 6 (default value for c used)
f(1, 2, 1) -- 4 (parameter used)
1 Like