Reputation: 131
I understand why this mwe doesn't work but I don't know how make it works. I'd like to use the variable content as reference name (not the variable name).
salade = {}
name = "tomato"
salade.name = "red"
print (salade.tomato) -- nil, should be red
print (salade.name) -- red, should be nil
Upvotes: 1
Views: 43
Reputation: 41474
Just use the normal table indexing syntax, rather than the tbl.key
syntactic sugar:
salade = {}
name = "tomato"
salade[name] = "red"
print (salade.tomato) -- red
print (salade.name) -- nil
Upvotes: 1