Log In  


Possibly a bug or just a quality of life issue...
Functions should handle trailing commas gracefully.

data={1,2,3,} -- trailing comma
poke( 0x5600, unpack(data) ) -- works
poke( 0x5600, 1,2,3, ) -- fails

... this may be fundamental to Lua?



indeed, the language definition shows that commas in function declarations is only between parameters, not after: https://www.lua.org/manual/5.2/manual.html#3.4.10

no bug here.


Thanks. Presumably the trailing comma in the table is discarded by Lua... or unpack() removes it?


tables are built with other rules, that permit a trailing comma: https://www.lua.org/manual/5.2/manual.html#3.4.8


1

Yep, the trailing comma in the table is simply ignored while functions are stricter.
Also about lua manual for trailing commas in table definition:
> The field list can have an optional trailing separator, as a convenience for machine-generated code.

I'd say, not only for machine-generated code, also convenient for the very lazy dev who can append more items without adding a comma to the last line 👌

For some (apparently illogical) reason this reminded me of this peculiar expression in JS:
('b' + 'a' + + 'a' + 'a').toLowerCase()
resulting in the string value:
"banana" 😆


Ha! Perfect NaN wordplay... 🤣

Yes, the use for the trailing comma is both for my automated coded generation (slightly simpler), but mainly for users to copy and paste blocks of code without having to reformat/ worry about joining commas.


1

In response to @Heracleum:

That is too funny ! Here it is for Pico-8. :)

cls()
?"va"..sub(tostr(_),2,4).."la"

Ahah excellent 😁👍



[Please log in to post a comment]