Lua Inspect

lua-users home
wiki

LuaInspect is a tool that does Lua code analysis. The result of this analysis can also be rendered as HTML. A plugin is also included for the SciTE text editor for real-time source code analysis, intelligent highlighting, and refactoring. The code is in working condition but still preliminary.

The tool operates by both static and dynamic analysis, using the AST converted via MetaLua (pure Lua portions).

Examples

[sputnik-9.03.16/lua/sputnik/init.lua] (HTML)
[video of SciTE plugin] (1 minute, Flash) (old version lacking many of the new features)
Usage example for HTML output: lua luainspectlib/luainspect/command.lua examples.lua > test-output/examples.html

Features

    * analysis:
        * identifies global (red) and local variables (blue), including locals that are
	   function arguments (dark blue) and upvalues (light blue)
        * identifies unused local variables: e.g. `do local x=1 end` (white-on-blue)
        * identifies local variables masking other locals (same name): e.g. `local x=1; local x=2`
	   (strikethrough and squiggle line)
        * identifies local variables that have non-constant binding (`local x = 1; x = 2`) (italic)
        * identifies unknown global variables (white-on-red) and table fields (red), inferred by
	   static and dynamic evaluation.
        * infers values of variables (e.g. `local sum = math.pi + 2` is 5.14.
           and defined-ness of members of imported modules
          (`local mt = require "math"; math.sqrtt(2) -- undefined`)
        * infers signatures of functions (including local, global, and module functions)
        * checks number of function arguments against signatures (SciTE only)
        * cross-references variables (locals and module fields) with their definitions and uses
	  (pink highlight), identifies range of lines/scope where the local is defined
	   (currently SciTE only), and supports jump-to-definition and jump-to-uses (SciTE only)
        * identifies all keywords in selected block (underline)
        * evaluate special comments (prefixed by '!') to inject semantic information into analysis
           (similar to luaanalyze / lint).
    * refactoring:
        * command to rename all occurrences of selected variable (SciTE only)
    * browsing:
        * inspect members of selected table.
        * select statement or comment containing current cursor selection (SciTE only)
        * display real-time annotations of all local variables, like an Excel/Mathcad worksheet
          (experimental feature via ANNOTATE_ALL_LOCALS) (currently SciTE only)
    * auto-complete typing support (SciTE only) (experimental)
    * interfaces: SciTE plugin, VIM plugin, and HTML output.

Features not implemented (but probably should be):

Download

The latest version is available on [github].

Note: A patched version of SciteExtMan is bundled (the older 2006-11-10 version on SciteExtMan won't work fully).

Dependencies

Tested with SciTE version 2.12 (older versions might not work) and SciteExtMan (as of 2010-07-20). ctagsdx.lua from the full SciteExtMan is optional (allows "goto mark" command to return to previous location following a "go to definition").

Ideas

This could be used on the lua-users wiki and on [snippets.luacode.org] to display Lua code.

--DavidManura

See Also


RecentChanges · preferences
edit · history
Last edited November 15, 2012 7:20 am GMT (diff)