Thread Tools Display Modes
01-15-14, 05:36 AM   #1
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Get Globals from a file/scope

Anyone know a function/script for this? The best thing i could came up is this:

Lua Code:
  1. for k, v in pairs(_G) do
  2.     if string.find(tostring(k), "AddonName") then
  3.         print("Global key", k, "value", v)
  4.     end
  5. end

That will probably print out your global vars and functions from your addon, but it's not the best.
  Reply With Quote
01-15-14, 06:02 AM   #2
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Meanwhile i came up with this:

To start of the file:
Lua Code:
  1. local globalsStart = { }
  2.  
  3. for k, v in pairs(_G) do
  4.     globalsStart[k] = v
  5. end

To end of the file you want to check:
Lua Code:
  1. local globalsEnd = { }
  2.  
  3. for k, v in pairs(_G) do
  4.     globalsEnd[k] = v
  5. end
  6.  
  7. for k, v in pairs(globalsEnd) do
  8.     if globalsEnd[k] ~= globalsStart[k] then
  9.         print("Global key", k, "value", v)
  10.     end
  11. end
  Reply With Quote
01-15-14, 06:13 AM   #3
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,360
Use this: FindGlobals

After following the instructions to have the script working I'm also using this batch file to be able to drag and drop lua files on it for testing (windows).
Code:
%cd%\luac-wow.exe -l %1 | %cd%\lua-wow.exe globals.lua %1 >globals.txt
You can also set it up as an external tool in your preferred IDE or advanced text editor, or as a shell extension to files and folders with a little more preparation, but I find the batch file sufficient for my needs.

Last edited by Dridzt : 01-15-14 at 06:23 AM.
  Reply With Quote
01-15-14, 07:44 AM   #4
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
I've tried to set it up for SubLime but i'm getting this error on scriptrun:

[Decode error - output not utf-8]
[Finished in 0.0s with exit code 255]

Edit: Got it working now, it's somehow doesn't eat non-UTF folder names. (It's the ****en 21st century and we still on goddamn ANSI/ASCII.)

But thanks for the suggestion.

Last edited by Resike : 01-15-14 at 07:59 AM.
  Reply With Quote
01-15-14, 08:50 AM   #5
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
Find Globals works great, but I find the wrapper app much easier to use.
  Reply With Quote
01-15-14, 09:32 AM   #6
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by myrroddin View Post
Find Globals works great, but I find the wrapper app much easier to use.
That could come handy too, but if you set a system script with Sublime you can get the same results from the current file you working on just by running the script with 1 button.

  Reply With Quote
01-15-14, 10:18 AM   #7
Vlad
A Molten Giant
 
Vlad's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 793
I personally use Notepad++ and the lua global finder program, so when I hit F5 to execute the lua file it actually parses it and prints what globals I reference, create, e.g.
__________________
Profile: Curse | Wowhead
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Get Globals from a file/scope


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

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