Originally Posted by Wandamey
whaow... how to scare the noobs.
sry but i still need a translation.
are you saying "stop using anonymous functions for your handlers" or there is more to it?
|
Avoid using variables declared out-side anonymous, nested functions, if you can pass them via member of control.
Lua Code:
local var = "outside"
ctl:SetHandler("WhatEver", function() d("from " .. var)
-- var must be "magically" known by storing a closure.
-- (Which is how large??? And stored how long???)
end)
=>
Lua Code:
local var = "outside"
ctl.save_var = var
ctl:SetHandler("WhatEver", function(self) d("from " .. self.save_var)
-- self is ctl, because handler get passed the control they are assigned to.
-- But now all used variables are declared inside:
-- Function is "stand-alone". => no closure.
-- And does not need to be nested anymore.
end)