Maintenance - We're currently working on things and you might experience some issues. Should be wrapped up soon!

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.

1
Appending function properly
Post Flair (click to view more posts with a particular flair)
Post Body

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?

Author
Account Strength
80%
Account Age
4 years
Verified Email
Yes
Verified Flair
No
Total Karma
146
Link Karma
129
Comment Karma
17
Profile updated: 6 days ago
Posts updated: 7 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
1 year ago