user2999071
user2999071

Reputation: 173

Lua: String to name?

is it possible to convert a string into a name of a table entry? just like

string = "test"
y = {test = 123}
print y.string

So if string is "test" it would print y.test if there is such a entry
Hope you understand my question!
Thanks in advance...

Upvotes: 1

Views: 115

Answers (1)

W.B.
W.B.

Reputation: 5525

print(y[string])

Be careful with using names such as string for variables, especially globals. You've just overwritten the string table.

Upvotes: 4

Related Questions