I'm trying to create a simple program that has a table with indices that can refer to it's parent table. I realize you can create an empty table first, then just create new keys while having the reference to the table. Example:
local t = {}
t.x = 1
t.y = t.x -- Refer to table 'x' for a value inside table 't'
However, I'm wondering if it's possible to do this during the table initialization. In other words, assigning key/value pairs in the table up-front instead of giving it a new index later in the code. Abstract example:
local t = {
x = 1;
y = t.y -- Refering to 't', inside of 't', for index 'y'
}
The code above is just an example, I know why it won't actually work. So I tried creating a reference to t using local before assigning it a value, so I could possibly access it during it's declaration. This is what confuses me...
local t -- Reference to t for later in the code, even though t is nil for now.
t = {
x = 1;
y = t.y -- This time t has been defined outside this table, so it should work?
}
The code above is what I expected to work, however it still reads 't' as nil inside the table. I'm not quite sure what else to try, or if it's even possible (even though I'm pretty sure it is). But if any of you see something I'm not getting, I'd appreciate the insight!
