lua-users home
lua-l archive

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


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.

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.

(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 [].)

-- 
┌── dg@cowlark.com ─── http://www.cowlark.com ───────────────────
│
│ "There does not now, nor will there ever, exist a programming language in
│ which it is the least bit hard to write bad programs." --- Flon's Axiom

Attachment: signature.asc
Description: OpenPGP digital signature