This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
First I defined the AppendScript function
local object = {}
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
local method = function()
--do stuffs
end
object:AppendScript(handler, method)
for append method to the handler script (`self:GetScript(handler)`) that, for example, I defined previously.
`object` is a client UI form such as frame or button (stored as a table), and `handler` an event ("OnLoad", "OnShow" and so)
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?
Subreddit
Post Details
- Posted
- 1 year ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/lua/comment...