lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Sorry, I did not know that ";" was accepted as a valid separator between key/value pairs in table constructors. I've never used it, never seen it in any Lua source, and I have missed that point in all the docs I read.
I've only seen that key/value pairs could have a trailing comma (a common practice in Lua, even if it's not valid in JSON).

It's hard to follow the changes in Lua versions and documentation; changes in Lua 5.2, 5.3 and now 5.4 are making them incompatible with previous versions, so Lua 5.1 cannot be declared "obsolete", it is not directly upgradable without inspecting (and testing/debugging again) all existing scripts. These Lua versions are distinct languages.

Le jeu. 9 sept. 2021 à 13:41, Xmilia Hermit <> a écrit :

Philippe Verdy wrote:

Note that that page of documentation uses an usual non-sense notation to describe the content of the local parameter named "arg" (implicitly declared in all functions):
This notation uses a semicolon in a table constructor, a syntax that does not exist in Lua.
It does exist in lua. In tables one can use either ',' or ';' as separator as stated in the manual:,
It may suggest that this semicolon indicates that the key/value pair n=2 is not stored in the table itself, but in its metatable.
It was used in earlier versions of lua to separate array and key-value parts. (see
Such observation cannot be made, but if it does, then any declared function that explicitly accesses to its "arg" parameter could have to create (on function entry) a new table indexing all upvalues (including nil values), and another table to store the key/value pair with an implicit key name 'n' (here ['n'] = 2) containing the effective number of upvalues (including nil's).

Such creation of two tables would be very inefficient (stressing the garbage collector), so I suspect that instead the "arg" type is not a true "table" but behaves "like a table" in user's Lua code.
Look at the sources. Here a normal table is created for the args table without a metatable. There is no special type for the args table nor has it only an array part.

I do not comment on the further points since they build upon these wrong asumptions.