lua-users home
lua-l archive

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


On Thu, Mar 27, 2014 at 8:55 AM, Alain Meunier <deco33@hotmail.fr> wrote:
> Hello,
>
> I know that tables don't preserve order in case of an associative array.
>
> but I 've got the following code (didn't scoped them for the ex):
>
> ----------------------------------------
> iterator = 0
> basic_table ={}
> str
>
> for x = 0,5 do
> iterator = iterator + 1
>
>          basic_table["k"][iterator] = iterator + 100
>
> end
>
> str = table.concat(basic_table,",")
> ----------------------------------------
>
> indexing is continuous and always numeric.
>
> If i concat this table in str, am I sure the order is preserved ?
> My tests confirm that but I just can't bear a mistake|my misconception there
> that would occur -even once a decade :)
>
> Thanks

table.concat can be considered at starting at index 1 and then adding
1 until it hits a nil (that is, an undefined index). Your approach is
safe. Though I do wonder what the ["k"] in there is, since you forgot
it later.

/s/ Adam