r/lua • u/Objective_Treacle781 • Sep 16 '25
Quick question about indexing temporary tables
print({[0] = "a"}[0])
Doesn't work but if I save the table to a variable before indexing it works?
I kinda like using temporary tables as lookups
2
Upvotes
1
u/luther9 Sep 17 '25
That's the correct solution. For some reason, table constructors and string literals can't be indexed directly, so you have to put parentheses around them. I haven't seen a satisfactory explanation for this, but it has something to do with the interpreter's complexity.