lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Le 02/07/2014 08:40, Choonster TheMage a écrit :
On 2 July 2014 16:20, David Demelier <> wrote:

Le 01/07/2014 16:33, Choonster TheMage a écrit :
On 2 July 2014 00:04, David Demelier <> wrote:
Le 01/07/2014 15:08, Andrew Starks a écrit :

Told from the perspective of _javascript_, but most of it applies to Lua, as well.


For me, one of the only thing I do agree is that the lack of static analysis can lead to bugs. In Lua if I type:


The code will obviously load as there are no syntax error, but will fail at the execution since unexistant is not a defined variable. In C++, you will actually have an error at the compilation. For that issue, you can only check at runtime and personally, it's the only problem I have when I develop irccd [1] plugins.



There are tools like FindGlobals[1] that analyse the output of luac to detect global variable access (intentional or otherwise). FindGlobals also allows you to whitelist certain global names so they don't show up in the output.

FindGlobals is only for Lua 5.1, but it could probably be easily adapted for 5.2. I'm pretty sure there are existing alternatives for 5.2, but I can't think of their names at the moment.

Although FindGlobals is distributed from a World of Warcraft AddOn site, it's meant to run in a standard Lua 5.1 environment (and in fact can't run inside WoW's embedded Lua due to sandbox restrictions).

It does not seems to work for 5.2 unfortunately:

~/test $ cat test.lua
~/test $ luac52 -l -p test.lua|lua52 findglobals/globals.lua test.lua
~/test $


That's because it's looking for the G/SETGLOBAL opcodes instead of their replacements G/SETTABUP. (I did mention it was 5.1 only in my post)

I adapted for 5.2 last night, though:


I have no idea what I'm doing wrong

~/test $ luac52 -l test.lua | lua52 FindGlobals52.lua test.lua
~/test $ cat test.lua
~/test $ head -n 5 FindGlobals52.lua


globals.lua (FindGlobals), a useful script to find global variable access in
.lua files, placed in the public domain by Mikk in 2009.