lua-users home
lua-l archive

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


David Given wrote:
Jimmie Houchin wrote:
[...]
These IDs just seemed like such natural indexes that I didn't want to have to code around them if I didn't have to.

Do remember to distinguish between a key that's a number (as in table[4]) and
a string containing digits (as in table["4"]). Both are acceptable, but
they're different keys.

Yes, I understand. It generally won't be much of an issue since most of these are not simple numbers, but aren't valid Names either. But thanks for the heads up.

The . syntax for tables is semantic sugar for using a string key, so
table.four and table["four"] are equivalent --- but in this case, the thing
after the . must be a valid keyword, and there are strict rules about that.
When in doubt, use [] syntax.

Yes. Some of this is simply exploring and learning as I go.

(Typically, . syntax is only really used for objects and structures. If you're
using a table as an actual dynamic storage device, it's recommended to use [].)

Absolutely. My program will use things dynamically and thus use [].

But while playing, testing, experimenting in the interpreter I try the . syntax for learning.

Thanks for the reply and the education. It helps.

Jimmie