Thread Tools Display Modes
Prev Previous Post   Next Post Next
05-09-23, 06:54 AM   #1
Benalish
A Flamescale Wyrmkin
 
Benalish's Avatar
Join Date: Dec 2012
Posts: 123
Appending function properly

First I defined the `AppendScript` function

Lua Code:
  1. local mt = {
  2.             AppendScript = function(self, handler, method)
  3.                 local func = self:GetScript(handler)
  4.                 self:SetScript(handler, function(...)
  5.                     func(...)
  6.                     method()
  7.                 end)
  8.             end,
  9.         }
  10.        
  11.     setmetatable(object, { __index = setmetatable(mt, getmetatable(object)) })
This way I can write

Lua Code:
  1. local method = function()
  2.                        --do stuffs
  3.                    end
  4.     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?
  Reply With Quote
 

WoWInterface » Developer Discussions » Lua/XML Help » Appending function properly


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off