View Single Post
02-24-17, 08:39 PM   #21
kurapica.igas
A Chromatic Dragonspawn
Join Date: Aug 2011
Posts: 152
Like I said, the environment is a standalone environment only used by the addon, it has no effect to the global environment. Loading a file would run it as a function, change the function's environment will only affect it's content

Lua Code:
  1. a = 100
  2.  
  3. function testenv()
  4.     setfenv(1, {})
  5.  
  6.     a = 200
  7. end
  8.  
  9. testenv()
  10. print(a) -- still is 100

And also an addon can have multi-modules, so each module can handle system event for their own. This won't set a meta-table to the global environment, the real job is like :

Lua Code:
  1. local _M = Scorpio("MyAddon.Module")
  2.  
  3. Scorpio.__SystemEvent__()
  4. function _M.UNIT_HEALTH(unit)
  5. end

Also _M:RegisterEvent(xxx, handler) can be used by those moduels. the reason use attribute is it can combine several information :

Lua Code:
  1. __Thread__()
  2. __BigWigsEvent__ "BigWigs_EnableFriendlyNameplates"
  3. __DBMEvent__ "BossMod_DisableFriendlyNameplates"
  4. function UpdateFriendlyNameplates()
  5. end

Last edited by kurapica.igas : 02-24-17 at 10:03 PM.
  Reply With Quote