View Single Post
07/15/15, 07:04 AM   #1
merlight
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 671
LuaEcoSearch - fighting global namespace pollution

I wrote a script that looks for global symbols used in add-ons. It's far from perfect, yet its output might already prove useful, so here you are

http://ge.tt/3zjp9QK2

luaEcoSearch.sh is a Unix shell script, it requires perl, luac5.1 (Lua 5.1 compiler) and optionally 7-zip. You give it a bunch of directories and/or zip files and it prints globals it finds to stdout.
Code:
$ sh luaEcoSearch.sh SomeAddonFolder AnotherAddon.zip ...
Assuming not everyone will be able to run it, I also included gzipped output generated from the latest versions of most of the add-ons here on esoui. I can't promise keeping it up to date, though.

Sample output:
Code:
cache/AddonProfiles+1416618983.zip

 +? AddonProfilesComboBox_ObjectFromContainer   AddonProfiles/AddonProfilesComboBox.lua +1
 +? AddonProfiles_CreateProfile                 AddonProfiles/AddonProfiles.lua +1
 +? AddonProfiles_DeleteProfile                 AddonProfiles/AddonProfiles.lua +1
 +? AddonProfiles_SavedVariables2               AddonProfiles/AddonProfiles.lua +185
 +  AddonProfiles_SwitchToProfile               AddonProfiles/AddonProfiles.lua +1
  ? AddMenuItem
  ? AnchorMenu
  ? ClearMenu
  ? CreateControlFromVirtual
The first line contains the file given on the command line.

The remaining lines begin with FLAGS:
+ marks a symbol that the add-on SETS
? marks a symbol that the add-on GETS

The second column is the symbol name, and the third column (if present) is the location of the start of the function in which the symbol is SET (luac doesn't tell the line number of the actual assignment).

If there is a + but no ? in front of a symbol, it may mean that it is unused, but not always. AddonProfiles_SwitchToProfile in the above sample is actually used from XML, which the script doesn't check.

Like I said, it's far from perfect, and here is why - it only finds simple, unqualified accesses/assigments. For example, when run on this code:
Lua Code:
  1. foo = bar
  2. _G.chop = _G.wood
  3. _G["cook"] = _G["food"]

The output would be:
Code:
/tmp/foo/

 +  foo                                         foo/bar.lua +1
  ? _G
  ? bar
That is, only foo, bar and _G got caught. The script can't detect you're also reading globals wood and food, and setting globals chop and cook.
  Reply With Quote