lua-users home
lua-l archive

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


When a table is used as an index, the value is the reference to the table. You can't use `t = {[{1, 2}] = "hello world"}; print(t[{1, 2}])`, you have to use the same table when originally assigning the index.

On Tue, May 2, 2017 at 6:55 PM Russell Haley <russ.haley@gmail.com> wrote:
Can a table be used as an index? What 'value' does that have (i.e the serialized table?)

Curse my BlackBerry for not having lua! :)

Russ

Sent from my BlackBerry 10 smartphone on the Virgin Mobile network.
  Original Message  
From: Soni L.
Sent: Tuesday, May 2, 2017 4:02 PM
To: Lua mailing list
Reply To: Lua mailing list
Subject: [Bug] Wording

The manual says "The type table implements associative arrays, that is,
arrays that can be indexed not only with numbers, but with any Lua value
except nil and NaN."

I believe this would be better worded as "The type table implements
associative arrays, that is, arrays that can have as indices not only
numbers, but any Lua value except nil and NaN."

The truth is, v=t[nil] and t[nil]=v both are valid Lua code, except the
latter errors because *a nil index cannot exist*. More specifically, you
cannot *create* a nil index, but you can check for its existence. Same
for NaN.

This wording more accurately represents the reference implementation,
and I believe this is intended behaviour.

--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.



--
--

Ryan <vandor2012@gmail.com>
Software Developer / System Administrator
https://hashbang.sh