Go Back   WowAce Forums > General > Lua Code Discussion
Lua Code Discussion You scared? Terrified. Mortified. Petrified. Stupefied... by [coding].

Reply
 
Thread Tools
Old 11-06-2012   #1
Expf
Member
 
Join Date: Aug 2010
Posts: 14
Default The underscore is back with a vengeance

Another reason why variable localization is important! Source: http://us.battle.net/wow/en/forum/topic/7005434873

So anyone got a good script that can do static code analysis on Lua files to detect global variables?

Quote:
So recently I started doing a couple Challenge Modes and encountered this very annoying bug where the timer blows up and refuses to come back until /reloadui. Here's the error dump (truncated for your sanity):
Code:
FrameXML\WatchFrame.lua:670: WatchFrameLine2:SetPoint():
    Couldn"t find region named "Sabotage"
FrameXML\WatchFrame.lua:1811: in function "?"
There's a spell named "Sabotage" that occurs in Gates, but how did a spell name get mixed up with a region name?! Well, let's dig up the FrameXML\WatchFrame.lua, lines 669-670:
Code:
if ( anchor ) then
    line:SetPoint("RIGHT", anchor, "RIGHT", 0, 0);
So anchor is "Sabotage" for some odd reason. If we go back up a level to lines 1811, the source of the problem becomes obvious:
Code:
WatchFrame_SetLine(line, _, WATCHFRAMELINES_FONTSPACING - 6, IS_HEADER, stageName, DASH_NONE);
The underscore variable "_" here has not been referenced earlier, which means it's basically pulling the value from the global underscore variable. If all other addons behave correctly and do not use the global underscore variable, then this code will function correctly.

But if any code decides to corrupt the value of the global underscore variable, then WatchFrame_SetLine will break catastrophically. The easy fix (which only Blizzard can do) would be do just replace the underscore with nil. The hard fix would be to change every single addon to make sure that they do not use the global underscore variable.

To be fair, the mistake is really on both ends here, but not every addon author is prudent enough to localize their variables correctly. Furthermore, it's almost impossible to track down which addon is causing this bug -- unlike the taint bug, this bug doesn't inform the user of the source of variable corruption.
Expf is offline   Reply With Quote
Old 11-06-2012   #2
cremor
Hero Member
 
Join Date: Feb 2007
Posts: 834
Default Re: The underscore is back with a vengeance

FindGlobals in combination with the nppExec scripts and settings found in the comments works great.
cremor is offline   Reply With Quote
Old 11-06-2012   #3
funkydude
Administrator
 
funkydude's Avatar
 
Join Date: Nov 2005
Location: Scotland, UK
Posts: 2,988
Default Re: The underscore is back with a vengeance

Or if you don't want to use FindGlobals, simply set your taintLog to a value of 2 (though I recommend setting it back to 0 or 1 when you're done). That will record the "tainting" of every global variable and can help debugging which addon is the cause. Calling it "almost impossible to track down" is a bit of an overstatement.

Last edited by funkydude; 11-06-2012 at 02:34 PM.
funkydude is offline   Reply With Quote
Old 11-06-2012   #4
Expf
Member
 
Join Date: Aug 2010
Posts: 14
Default Re: The underscore is back with a vengeance

Quote:
Originally Posted by funkydude View Post
Or if you don't want to use FindGlobals, simply set your taintLog to a value of 2 (though I recommend setting it back to 0 or 1 when you're done). That will record the "tainting" of every global variable and can help debugging which addon is the cause. Calling it "almost impossible to track down" is a bit of an overstatement.
I should change that to "very annoying to track down".

Thanks for the info.
Expf is offline   Reply With Quote
Old 11-07-2012   #5
Lombra
Senior Member
 
Lombra's Avatar
 
Join Date: Jan 2006
Location: Sweden
Posts: 410
Default Re: The underscore is back with a vengeance

Before I go pulling my hair out trying to do this myself, any hints on how to use FindGlobals to.. oh, say looking for global underscores among all addons at once?

Edit: Hair still intact, and I managed somehow. Don't know if there's a better solution (or whether this actually works for all cases), but I changed line 115 in globals.lua
Code:
if globalName and GLOBALS[globalName] then
into
Code:
if globalName and GLOBALS[globalName] or globalName ~= "_" then
and then ran this
Code:
@echo off
set LUAC="C:\Games\Blizzard\World of Warcraft\Interface\luac-wow.exe"
set LUA="C:\Games\Blizzard\World of Warcraft\Interface\lua-wow.exe"
set FINDGLOBALS="C:\Games\Blizzard\World of Warcraft\Interface\FindGlobals.lua"

for /r %%a in ("\*.lua") do	%LUAC% -p -l "%%a" | %LUA% %FINDGLOBALS% "%%a"

pause
__________________
Grab your sword and fight the Horde!

Shattered Hand-EU

Last edited by Lombra; 11-07-2012 at 01:07 PM.
Lombra is offline   Reply With Quote
Old 11-08-2012   #6
Phanx
Seal Cub Clubbing Club
 
Phanx's Avatar
 
Join Date: May 2005
Location: United States
Posts: 8,146
Default Re: The underscore is back with a vengeance

Here is a GUI wrapper for FindGlobals:
http://www.wowinterface.com/download...OTANADDON.html
__________________
Author/maintainer of Grid, PhanxChat, and many more. | PM me on CurseForge
Troubleshoot an addon | Turn any code into an addon | More addon resources
Need help with your code? Attach or paste your whole, real files.
Please don't PM me about addon bugs, requests, or code help. Post a comment, ticket, or thread instead!
Phanx is offline   Reply With Quote
Old 11-08-2012   #7
myrroddin
Amazing Member
 
Join Date: May 2006
Location: Edmonton, Canada
Posts: 1,147
Send a message via MSN to myrroddin
Default Re: The underscore is back with a vengeance

Quote:
Originally Posted by Phanx View Post
Here is a GUI wrapper for FindGlobals:
http://www.wowinterface.com/download...OTANADDON.html
OMG, YOU RULE!!! Caps are intended, Phanx. Also, Zarnyeg2 is to be commended.
myrroddin is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 12:51 AM.