lua-users home
lua-l archive

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


Hello,

I have come across a problem, and I'd like to know what other people think
about it and/or if it's fixed in 3.0/3.1.

The following is valid Lua code:

a_table = {};
a_table[1] = "test";
a_table["1"] = "test string";

printTable(a_table);     -- my basic print table

output>> table: 00673608
         [number] 1  =  [string] test
         [string] 1  =  [string] test string
         2 entries


However, it's NOT possible for me to do:

> a_table = { 1 = "test string" };

However, it's NOT valid to do:

> a_table = { "test" ; 1 = "test string" };

** QUESTION *** Why can't I have "named table entries" which begin with
 numbers, knowing that they will be strings?


Of course, it _is_ valid to do:

> a_table = { "test" ; boo = "test string" };



** QUESTION *** Also, why do unnamed entries in a table have to come
   first? I find it rather cumbersome. I am using the following
   initialization "style" and i'd like to do:

   table = { list_type = "image";
             { "filename1.boo" , 10, 10, 20, 20 },
             { "filename2.boo" , 10, 10, 20, 20 }
           };

 Which is much more readable than:

   table = { {"filename1.boo" , 10, 10, 20, 20 },
             {"filename2.boo" , 10, 10, 20, 20 },
             list_type = "image"
           };

 Especially when the lists are long and you have to go looking for the
 list type.             

-- 
David Jeske (N9LCA) + http://www.chat.net/~jeske/ + jeske@chat.net