Lua Inspect

lua-users home
wiki

LuaInspect 是一款用于 Lua 代码分析的工具。分析结果也可以渲染成 HTML 格式。该工具还包含一个 SciTE 文本编辑器的插件,用于实时源代码分析、智能高亮和重构。代码处于工作状态,但仍处于初步阶段。

该工具通过静态和动态分析来运作,使用通过 MetaLua(纯 Lua 部分)转换的 AST。

示例

[sputnik-9.03.16/lua/sputnik/init.lua] (HTML)
[SciTE 插件视频] (1 分钟,Flash) (旧版本缺少许多新功能)
HTML 输出的用法示例:lua luainspectlib/luainspect/command.lua examples.lua > test-output/examples.html

功能

    * 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.

未实现的功能(但可能应该实现)

下载

最新版本可在 [github] 上获取。

注意:捆绑了 SciteExtMan 的修补版本(SciteExtMan 上的旧版本 2006-11-10 将无法完全工作)。

依赖项

已在 SciTE 版本 2.12(较旧的版本可能无法工作)和 SciteExtMan(截至 2010-07-20)上测试。来自完整 SciteExtMan 的 ctagsdx.lua 是可选的(允许“转到标记”命令在“转到定义”后返回到先前的位置)。

想法

这可以在 lua-users wiki 和 [snippets.luacode.org] 上用于显示 Lua 代码。

--DavidManura

另请参阅


最近更改 · 首选项
编辑 · 历史记录
最后编辑于 2012 年 11 月 15 日上午 7:20 GMT (差异)