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 使用者 wiki 和 [snippets.luacode.org] 來顯示 Lua 程式碼。

--DavidManura

另請參閱


RecentChanges · 喜好設定
編輯 · 歷史
最後編輯於 2012 年 11 月 15 日格林威治時間上午 7:20 (diff)