Quantcast
WoWInterface - View Single Post - How could this be written neater?
View Single Post
05-08-17, 08:40 AM   #12
MunkDev
A Scalebane Royal Guard
 
MunkDev's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 429
Originally Posted by Kkthnx View Post
Is this bad practice? If so I'd love more info on this. Everyone has their ways.

So telling him he doesn't need to do this is right or wrong here or are you teaching him what you have learned.

Lua Code:
  1. -- WoW Lua
  2. local _G = _G
  3.  
  4. -- Wow API
  5. local GetSpecialization = _G.GetSpecialization
  6. local GetSpellInfo = _G.GetSpellInfo
I'm not saying it's bad practice, I'm saying it's pointless. Lua in WoW assumes global environment access if the variable name you're looking for doesn't exist in your current scope. Localising those functions only entails two instances of table access. Why store a pointer to the global environment for the remainder of your game session when you're not even using it for anything?

The performance gain is negligible at best. The only recurring functions that are used in loops in response to a frequent event are the two functions I listed at the top. If you're doing a ton of lookups very frequently, it might be wise to upvalue functions or entire tables in that case.

Personally, I don't upvalue the global environment because it produces uglier code.
__________________

Last edited by MunkDev : 05-08-17 at 08:58 AM.
  Reply With Quote