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?

P#119072 2022-10-13 22:23

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.

P#119074 2022-10-13 22:49

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

P#119075 2022-10-13 23:16

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

P#119077 2022-10-14 00:12
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" 😆

P#119559 2022-10-25 21:22 ( Edited 2022-10-25 21:25)

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.

P#119566 2022-10-25 22:45 ( Edited 2022-10-25 22:48)
1

In response to @Heracleum:

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

cls()
?"va"..sub(tostr(_),2,4).."la"
P#119577 2022-10-26 03:20

Ahah excellent 😁👍

P#119588 2022-10-26 08:13

[Please log in to post a comment]