lua-users home
lua-l archive

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


Hello,

Yes I am sorry, I forgot the "k". Here is the right code :
----------------------------------------
iterator = 0
basic_table ={k={},v={}}
str

for x = 0,5 do
iterator = iterator + 1

    basic_table["k"][iterator] = iterator + 100

     end

str = table.concat(basic_table,",")
--------------------

So, According to your answers, I think it is ok.

Many thanks !

> From: thijs@thijsschreijer.nl
> To: lua-l@lists.lua.org
> Date: Thu, 27 Mar 2014 16:43:44 +0000
> Subject: RE: tables as array : little confirmation
>
>
>
> > -----Original Message-----
> > From: lua-l-bounces@lists.lua.org [mailto:lua-l-bounces@lists.lua.org] On
> > Behalf Of Alain Meunier
> > Sent: donderdag 27 maart 2014 16:56
> > To: lua-l@lists.lua.org
> > Subject: tables as array : little confirmation
> >
> > 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,",")
>
> Are you sure? Basic_table only contains one entry with key "k" here.
> str = table.concat(basic_table["k"],",")
> would make sense here
>
> > ----------------------------------------
> >
> > indexing is continuous and always numeric.
> >
> > If i concat this table in str, am I sure the order is preserved ?
>
> Yes. That is how basic string buffers are used in Lua to do only a single efficient concat operation at the end of a loop.
>
> > My tests confirm that but I just can't bear a mistake|my misconception there
> > that would occur -even once a decade :)
> >
> > Thanks
>
>
>