【发布时间】:2014-02-08 16:16:24
【问题描述】:
正如所料,这段代码:
s = "bar"
bar = function() print(s) end
_G[s]()
输出:
酒吧
但要么这样:
s = "bar"
foo = {
bar = function() print(s) end,
_G["foo." .. s]()
}
或者这个:
s = "bar"
foo = {
bar = function() print(s) end
}
_G["foo." .. s]()
输出:
尝试调用字段“?” (零值)
堆栈回溯:
test.lua:4: 在主块中
[C]: ?
如何从字符串变量中调用非全局函数?
【问题讨论】: