July 2018
Beginner
202 pages
5h 42m
English
Because the global table is just a table, it can be indexed dynamically. You can concatenate strings to index the global table using the square bracket notation. For example, the following three lines of code all do the same thing:
foo = "bar"_G.foo = "bar"_G["foo"] = "bar"
In the preceding code example, the last line indexes the global environment with a string. The following code demonstrates how to index the global table using dynamic strings:
value1 = 'x'value2 = 'y'value3 = 'z'for i = 1,3 do print ("value" .. i .. ": " .. _G["value" .. i])end
Read now
Unlock full access