First I defined the `AppendScript` function
Lua Code:
local mt = {
AppendScript = function(self, handler, method)
local func = self:GetScript(handler)
self:SetScript(handler, function(...)
func(...)
method()
end)
end,
}
setmetatable(object, { __index = setmetatable(mt, getmetatable(object)) })
This way I can write
Lua Code:
local method = function()
--do stuffs
end
object:AppendScript(handler, method)
for append method to the handler script that, for example, I defined previously.
I would like to make sure that the function is not appended indefinitely: in a nutshell that the function is not appended every time the event fires.
it was recommended to make the Function Constructor in Metamethod __newindex and decide in AppendScript if it has to be recreated/destroyed, but I'm still a bit inexperienced with metatables.
Can you help me?