3 ms·
You can actually implement that sort of logic in pure Lua too using `...` in your parameter list and then using `select('#', ...)` in the function body. For exa
by nikki93 6y ago
You can actually implement that sort of logic in pure Lua too using `...` in your parameter list and then using `select('#', ...)` in the function body. For example:
> function f(...) print(select('#', ...)) end
> f(1, 2)
2
> f(1, 2, nil)
3
- samatman 6y agoI didn't mean "it is impossible to build logic incorporating the number of parameters passed to a function", but rather "there will be no difference between calling an ordinary Lua function with (a, b, nil) vs (a, b), unlike table.insert, without extensive effort" Sooner or later, a budding Lua programmer makes an index an optional, last parameter to a function, and then passes it through to `insert`. If what you're inserting happens to be a number, this silently does the wrong thing. Suffice to say I won't ever forget this particular wart on what's become my favorite language.
- nikki93 6y agoMakes sense. I was just clarifying "It's not possible to build this in pure Lua": it is.