lua-users home
lua-l archive

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


> steve d.
> Why not just use a true two-dimensioned array?

Perhaps, but I like having names for the ads, since I use them elsewhere. I might make the names more meaningful, such as lrg_rotating_ad, versus sml_static_ad (ad3 has only one lineup, so it has no timer).

Also, each lineup doesn't have the same number of array elements, so conceptually it's not really a true double-dimmed array. To be accurate I should have entitled this 'a table of arrays'.

But you've answered my question, which is whether I need to explicitly have a line to declare a field of a table as a new table in order to use it as an array (or table). Yours did the same thing as mine: ad_lineup[1] ={}


> Rob K.
> Nothing is stopping you putting tables into tables: you can put any value in a table as key or value except nil.  

Yes. I was just wondering if there was a more elegant way of declaring it, rather than the two-step approach used.


Dave Collins
Front-End Engineer
Mercatus Technologies Inc.
60 Adelaide Street East, Suite 700
Toronto ON M5C 3E4
T  416 603 3406 x 298
F  416 603 1790

dave.collins@mercatustechnologies.com
www.mercatustechnologies.com


-----Original Message-----
From: lua-l-bounces@lists.lua.org [mailto:lua-l-bounces@lists.lua.org] On Behalf Of steve donovan
Sent: Friday, July 15, 2011 9:56 AM
To: Lua mailing list
Subject: Re: double dim'd arrays

On Fri, Jul 15, 2011 at 3:51 PM, Dave Collins
<Dave.Collins@mercatustechnologies.com> wrote:
> I've got an array of rotating adverts, each one has a lineup of ads it will go through. So I made a double-dimensioned array.

Why not just use a true two-dimensioned array?

 local ad_lineup ={}

ad_lineup[1] ={}
ad_lineup[1][1] = "CoolWhip"
ad_lineup[1][2] = "ShreddedWheat"
...
ad_lineup[2] ={}
ad_lineup[2][1] = "ShreddedWheat"
ad_lineup[2][2] = "Swiffer"
...

That would be easier to work with, I think

steve d.