lua-users home
lua-l archive

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


Wesley Smith wrote:
>> The magic is as follows and is one combination I did not try because
>> neither on their own work. Syntax is inconsistent, to do with runtime
>> type definition.
>>
> 
> I'm not sure I understand this last sentence.  Would you care to
> elaborate?  The syntax to me seems to be explicit (in terms of a
> constructor v. modifying an existing table).
> 
> -------------------------------------
> require"tprint"
> 
> var="fred"
> 
> pa1="john"
> va1="sam"
> pa2="ken"
> va2="sal"
> 
> rt={} -- new empty table
> 
> rt[var]={[pa1]=va1}  -- hint to Lua is subtable and give a it a pair
> rt[var][pa2]=va2   -- Lua now knows it is a table,
>                 --syntax for adding is different!
> -------------------------------------
> 
> My question to you in code comments would be: How could Lua possible
> know that rt[var] was a table before?  It didn't even exist before the
> previous line.

Quite. That is what I was getting at. Sorry, my language usage and
thinking tends to be alien to others.

As some have pointed out the initialiser is explicit.