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:
a = 100
function testenv()
setfenv(1, {})
a = 200
end
testenv()
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:
local _M = Scorpio("MyAddon.Module")
Scorpio.__SystemEvent__()
function _M.UNIT_HEALTH(unit)
end
Also _M:RegisterEvent(xxx, handler) can be used by those moduels. the reason use attribute is it can combine several information :
Lua Code:
__Thread__()
__BigWigsEvent__ "BigWigs_EnableFriendlyNameplates"
__DBMEvent__ "BossMod_DisableFriendlyNameplates"
function UpdateFriendlyNameplates()
end