Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to skip optional parameters in Lua?

There is a method I have been calling:

t1, t2 = LSL:GetDiffItem(item)

where the method is declared as:

GetDiffID(item, ignoreEnchant, ignoreGem, red, yellow, blue, meta, ignorePris)

Now I want to pass additional parameters, skipping some:

item, ignoreEnchant, ignoreGem, red, yellow, blue, meta, ignorePris

I tried just skipping the parameters:

t1, t2 = LSL:GetDiffItem(item, ignore, ignore, , , , , ignore)

But of course that doesn't work:

unexpected symbol near ','

So, how do I skip optional parameters in Lua?


See also

  • lua.org - 5.3 - Named Arguments "arguments are positional"
like image 201
Ian Boyd Avatar asked Jul 23 '26 15:07

Ian Boyd


1 Answers

Pass nil. This will be identical to not ever having passed the parameter. However, be aware that the documentation states that you can do this, because most functions will not check each individual optional parameter, and only check each parameter if the previous one was provided.

like image 60
Puppy Avatar answered Jul 26 '26 10:07

Puppy