s = "bar"
foo = {
bar = function() print(s) end
}
_G["foo." .. s]()
This last method doesn't work because there is no such table "foo.bar"
, but rather the field "bar"
in the table foo
. So you can call it like this:
_G.foo[s]()
or simply:
foo[s]()