Lua 从表WIN'中检索的函数引用;我不接受任何论据
我有一个函数引用表,如下所示:Lua 从表WIN'中检索的函数引用;我不接受任何论据,lua,Lua,我有一个函数引用表,如下所示: KLC.ChatCommandBank = { test = KLC.TestFunction, config = KLC.OpenInterfaceOptions, option = KLC.OpenInterfaceOptions, options = KLC.OpenInterfaceOptions, help = KLC.PrintHelp }; 但是当f=“test”和t是一个字符串表时,我调用 KLC.ChatCommandBank[f](t);
KLC.ChatCommandBank = {
test = KLC.TestFunction,
config = KLC.OpenInterfaceOptions,
option = KLC.OpenInterfaceOptions,
options = KLC.OpenInterfaceOptions,
help = KLC.PrintHelp
};
但是当f=“test”
和t
是一个字符串表时,我调用
KLC.ChatCommandBank[f](t);
然后是函数
function KLC:TestFunction(tab)
print(tab);
end
尽管调用函数时,t
不是nil
,但是tab
的值为nil
我怀疑这是因为函数引用表没有定义参数;我无法用谷歌找到任何东西,我自己的修补也无法修复它!因为当您将函数定义为KLC:TestFunction(tab)
时,它会得到一个隐式参数self
,该参数引用调用它的表
当您将其称为KLC.ChatCommandBank[f](t)
时,您需要显式地传递某些内容来代替该参数:
KLC.ChatCommandBank[f](KLC, t)
或者,您可以将定义更改为本地函数KLC.TestFunction(tab)