nil
is the type and value to represent empty in Lua, so instead of passing an empty string ""
or nothing, you should pass nil
like this:
local dog3 = dog.new(nil ,nil , "bonus", nil )
Note that the last nil
can be omitted.
Take the first parameter x
as an example, the expression
x = x or 0
is equivalent to:
if not x then x = 0 end
That is, if x
is neither false
nor nil
, sets x
with the default value 0
.