ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   Dev Tools (https://www.esoui.com/forums/forumdisplay.php?f=173)
-   -   LuaEcoSearch - fighting global namespace pollution (https://www.esoui.com/forums/showthread.php?t=4891)

merlight 07/15/15 07:04 AM

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.

votan 07/16/15 12:10 AM

Ah. It's great. :)

Typos and missing declaration happens very easy without a compiler warning you.
What about passing the manifest file to get the list of Lua files?
This way wrong paths can be found quicker.
And an extra loop filling $(language) with all (unoffical) supported languages to find syntax errors in language files one normally does not use. (Already happend)

The list was very useful.

Thanks!

merlight 07/16/15 03:02 AM

Quote:

Originally Posted by votan (Post 22036)
What about passing the manifest file to get the list of Lua files?
This way wrong paths can be found quicker.
And an extra loop filling $(language) with all (unoffical) supported languages to find syntax errors in language files one normally does not use. (Already happend)

I didn't even think about parsing add-on manifest. The script just checks all .lua files it finds, there's no ESO specific logic (except stripping UTF-8 BOM). That's how I once found a broken string in french translation, which I don't understand ;)

As for finding missing/misspelled files, here you go:

bash Code:
  1. find -name '*.txt' -exec perl -ne '
  2.    chomp;
  3.    next unless /^\w/;
  4.    for $lang (qw( en de fr ru es pt )) {
  5.        $fn = $_;
  6.        $rep = ($fn =~ s/\$\(language\)/$lang/);
  7.        print "missing $fn\n" unless -f $fn;
  8.        last unless $rep;
  9.    }
  10. ' '{}' +

Lodur 07/16/15 12:03 PM

Would love to see you filter out the reads (?) of the LUA system functions and ZOS API Functions.

Ayantir 07/16/15 12:37 PM

To update the wiki I'm writing some kind of similar script (but in lua). I'll try to update it aswell next zos patches come.

Lodur 07/16/15 07:45 PM

And thanks! You found me two bugs in my current addon.

merlight 07/17/15 02:24 AM

Quote:

Originally Posted by Lodur (Post 22043)
Would love to see you filter out the reads (?) of the LUA system functions and ZOS API Functions.

Yea that should be easy. The hardest part will be getting a clean and complete list :)

merlight 07/18/15 05:09 AM

Added a filtered list. Shouldn't contain read-only globals available ingame without add-ons (functions, tables, controls, enums).

Lodur 07/20/15 10:17 AM

Will there be a new luaEcoSearch.sh released that does the filter? The link is still to the old one.

merlight 07/20/15 10:31 AM

This was kinda an afternoon fun demo, but if I return to it, I'll put it up on github with all the parts. I did the filtering with another script, which extracts a list of names from a dumper add-on (which will need to be included) and then essentially does grep -xf

Lodur 07/29/15 11:36 PM

Thanks again for another pre-reason bug found...

merlight 09/03/15 08:24 AM

Updated dump as of 3 Sep 2015 http://ge.tt/3zjp9QK2/v/7


All times are GMT -6. The time now is 04:01 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI