View Single Post
09/02/15, 09:27 AM   #14
votan
 
votan's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 577
Originally Posted by Wandamey View Post
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:
  1. local var = "outside"
  2. ctl:SetHandler("WhatEver", function() d("from " .. var)
  3. -- var must be "magically" known by storing a closure.
  4. -- (Which is how large??? And stored how long???)
  5. end)
=>
Lua Code:
  1. local var = "outside"
  2. ctl.save_var = var
  3. ctl:SetHandler("WhatEver", function(self) d("from " .. self.save_var)
  4. -- self is ctl, because handler get passed the control they are assigned to.
  5. -- But now all used variables are declared inside:
  6. -- Function is "stand-alone". => no closure.
  7. -- And does not need to be nested anymore.
  8.  end)
  Reply With Quote