lua-users home
lua-l archive

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

Den 2013-01-23 13:45, skrev steve donovan:
On Wed, Jan 23, 2013 at 12:56 PM, Luiz Henrique de Figueiredo
<> wrote:
Nice. See also
Well, it was not difficult to update the code to work with both 5.1
and 5.2, using the interestingly named GETTABUP instruction instead,
and allowing for a somewhat different instruction presentation.

One of the cool things about this script is that it can detect more
than plain undeclared access, but warn against potentially evil

-- globs2.lua
next = 3

table.who = 1

function ()
    local k = 1

$ globals globs2.lua
globals: globs2.lua:2: redefining global next
globals: globs2.lua:4: redefining global table.who
globals: globs2.lua:6: redefining global

This required a further extension of David's trick for detecting field
access (by relaxing the requirement that the SETTABLE instruction had
to _immediately_ follow any global table access.)

Behaves almost identically for 5.1 or 5.2, but please change 'luac52'
to 'luac' (this was only way I could keep testing sane on my side)

BTW, I note that GETTABUP  is not only used for _ENV?  There are
definite limits on how far one can track variable usage, once
everything becomes locals, and I was wondering if we had extra
information that could be used.

steve d.

Also see  previously announced.

It does not follow require/loads, has no options. But it does allow passing a list of files as arguments , so you can do

 globals.lua /usr/local/share/lua/5.1/pl/*.lua

The name of luac can be overridden with environment variable LUAC. So to use luac52,  from a usable shell do

LUAC=luac52 globals.lua /usr/local/share/lua/5.1/pl/*.lua