Is there documentation on the calling convention when there are multiple optional arguments? E.g. what’s the difference between a nested list of optimal arguments like playdate.graphics.image:rotatedImage(angle, [scale, [yscale]]) v.s. independently optional arguments like playdate.network.http.new(server, [port], [usessl], [reason])? Also, it seems like the way to leave usessl to default is to omit it instead of passing nil (which is more common in Lua). Omitting arguments can also be ambiguous when the next argument has the same type; e.g. if [reason] is also a bool, the it’s unclear if http.new(“example“, 433, true) should trigger the default for usessl or reason.
I’m posting this under Get Help as I might be missing something, but if not I can convert this into a bug report.
My understanding is that [scale, [yscale]] means that you can have scale without yscale but you can’t have yscale without scale.
In other words:
• The outer brackets means “this whole set is optional.”
• The inner brackets mean that within that set, yscale is optional—but scale is not. If only one value is provided, it’s assumed to be scale.
That kind of nesting prevents ambiguity. For http.new, reason is not a boolean—all three are different types, so there’s no ambiguity.
But where there is possible ambiguity (like the three numbers for rotatedImage) then nested brackets are used to tell you which one is assumed if you don’t include both/all.
So if reason were a boolean, it would have to work something like: playdate.network.http.new(server, [port], [usessl, [reason]]).
It’s a Lua requirement. Because Lua doesn’t have named arguments (as Swift does, to name one example), the called function has no way to distinguish which argument is which, short of its position in the argument list.