Main Content

The indexed and hashed parts of a Lua table

Archive - Originally posted on "The Horse's Mouth" - 2009-08-10 18:34:30 - Graham Ellis

A Lua table contains both a sequentially indexed section and a hash keyed section (and a few other things too). When you sort the table, you sort only the index keyed section, when you use ipairs you use just the first (indexed) section, but when you use pairs you use the whole table. See source code example.

Because of these two sections, a table is the only Lua native collection object (userdata is available via C), and it is used for Vectors, Lists, Tuples, Arrays, Stacks, queues, dictionaries, associative arrays, hashed and objects. After all, Lua has a tiny footprint at it's great to be able to use a single type in so many ways.

We teach Programming in Lua at our Melksham Training Centre regularly, and can run on site courses in many countries to our standard agenda, or to an agenda tuned for your specific needs.