[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: How does lua store data in a table?
- From: Patrick Rapin <toupie300@...>
- Date: Fri, 30 Mar 2012 11:13:15 +0200
Every Lua table consist in a C array together with a hash table (but
both can be empty).
- Consecutive integer indexes starting from 1 are stored in the array part
- All other indexes are hashed and stored in the hash table part
The hash array is by nature unsorted. It is impossible to get back the
same order as the construction.
If you need it, you must use numeric indexes (a sequence), or an
associated array with keys order.
Example:
mydata = {
{ "key1", "value1" },
{ "key2", "value2" }
}
Or :
mytable_keys = { "key1", "key2" }