View Single Post
02-24-17, 10:06 AM   #17
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
The problem isn't really with Scorpio itself, it's running PLoop in a game, which Scorpio is an extension of. You're trying to answer the question of "Why should I use PLoop when I already know how to do this in baseline Lua?" The obvious answer is, you shouldn't.

The entire PLoop system is involved around using functions that appear as tags to set internal flags and intercept global environment writes to process the given function. Besides being terribly inefficient in doing so, there's an extremely likely situation that would cause a major problem for PLoop.

PLoop was designed to be used in a single project environment where you have control of every variable and their values. The problem being is WoW isn't like that. The same Lua environment is shared among all addons and the default UI. The relatively open access and the way PLoop is designed to work makes it extremely vulnerable to global leaks from other addons and existing globals set by the default UI. This is why there's a common rule when developing addons to at least prepend your addon's name to the name of any global you create. It lessens the chances of conflictions with other addons and even the default UI.

Why is PLoop vulnerable? Earlier, I explained how it uses functions as tags that intercept and modify an attempt to write a global function. PLoop does this by setting a __newindex metamethod on the global environment. The problem being is __newindex doesn't run if a global already exists. It simply overwrites the previous value. This means if you try to run the chunk that registers a function for UNIT_SPELLCAST_START and a global with that name already exists, you'll end up overwriting that global. Best case scenario, Scorpio will think AuctionFrameTab_OnClick is an event to register if the AuctionUI hasn't loaded already. Worst case, your addon throws an error and causes problems to whatever code already was using that global by corrupting their variable.



Why do I do this? People tend to blindly accept code without even taking a critical look at it for vulnerabilities and other problems. Even many addon authors fall into this trap. It's nothing to be ashamed of and I hope this becomes a learning experience to help raise awareness to the risks of doing so. The WoW UI environment isn't just pure Lua, there are lots of caveats to it that doesn't exist in a normal Lua environment.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 02-24-17 at 10:16 AM.
  Reply With Quote