【发布时间】:2020-03-05 06:27:49
【问题描述】:
local tbl = {a = 1}
-- Passed and executed function
function tbl:handleFunc(x, y)
print(self.a + x + y)
end
-- I know the above code is syntax sugar.
-- tbl["handleFunc"] = function(self, x, y)
-- print(self.a + x + y)
-- end
-- Register event handlers that I can't control the call
Frame:SetScript("OnClick", tbl.handleFunc)
-- Probably called when an event occurs.
tbl.handleFunc(2, 3)
-- Then it will be like this.
tbl.handleFunc(2, 3, nil)
-- So I wrote a function like this
function tbl.handleFunc(x, y)
local self = tbl -- This variable is too cumbersome
-- And this way, every time I call a function, I need to check whether the function definition is a dot (.) Or colon (:)
end
在调用函数时,在不能传递self的情况下,有没有办法使用self?
如果没有,我应该如何设计?
[已解决] 我使用了翻译器,但我想保持礼貌。谢谢你的好答案。
【问题讨论】:
标签: lua add-on world-of-warcraft