Posted 11 March 2014 - 01:49 PM
cclint is an outside MC lua linter with CC-specified features. It uses luac's bytecode listing and reports all accesses to global variables, which catches many typing errors in variable names.
Examples
lua code:
Example 2
lua code:
Example 3 (CC-specified)
lua code:
If luac cannot compile code, cclint reports error.
lua code:
Global variable can be declared by
Linter supports some control directives:
Download: https://github.com/Shura1oplot/cclint
How to install
On windows:
Similar projects:
There is an experimental SublimeText 3 plugin: https://github.com/S...-contrib-cclint
It can be installed only by git clone to ~/.config/sublime-text-3/Packages directory.
Tested on linux, may work on OSX and should not work on windows without some changes in plugin code.
If windows support is needed, add issue or pull request in github project page.
Examples
Spoiler
Example 1lua code:
local function f()
count = 0
for i = 1, 10 do
-- do some useful
count = count + 1
end
end
cclint output:
W:2: global set of 'count'
W:5: global get of 'count'
W:5: global set of 'count'
Example 2
lua code:
local function doSomeUseful()
end
local function main()
doSoneUseful()
end
cclint outout:
W:4: global get of 'doSoneUseful'
Example 3 (CC-specified)
lua code:
local function main()
lama.forward()
end
cclint outout:
W:2: global get of 'lama'
solution:
os.loadAPI("apis/lama")
local function main()
lama.forward()
end
If luac cannot compile code, cclint reports error.
Spoiler
Example 4lua code:
local function f(a, B)/>/>/>/>/>
if a > b
return true
end
return false
end
cclint outout:
E:3: 'then' expected near 'return'
Global variable can be declared by
os.loadAPI("path/NAME")
bapil.loadAPI("path/NAME")
Linter supports some control directives:
- lint-ignore-global-get: foo,bar,baz - ignore global get for listed names,
- lint-ignore-global-set: foo,bar,baz - ignore global set for listed names,
- lint-ignore-global: foo,bar,baz - ignore global get or set for listed names,
- lint-set-globals-in-main-chunk - ignore globals set in main chunk,
- lint-check-globals-cached - report on getting globals outside main chunk.
Spoiler
-- lint-ignore-global-set: varX
varX = 0
-- lint-set-globals-in-main-chunk
function f1()
end
function f2()
end
-- lint-check-globals-cached
local function main(...)
local n = select("#", ...)
end
cclint output:
W:3: global get of 'select'
solution:
-- lint-check-globals-cached
local select = select
local function main(...)
local n = select("#", ...)
end
Download: https://github.com/Shura1oplot/cclint
How to install
On windows:
- create C:\cclint
- copy cclint.py to C:\cclint
- install python >= 3.3 (http://python.org/downloads/)
- download lua 5.1 windows binaries (http://luabinaries.s...t/download.html)
- copy luac5.1.exe to C:\cclint
- run it in windows terminal by typing "C:\cclint\cclint.py lua_file"
- install lua 5.1 from repository (for debian based distros: apt-get install lua5.1)
- copy cclint.py to ~/bin
- ensure ~/bin is in PATH environment variable
- use it in terminal emulator by typing "cclint.py lua_file"
- install lua 5.1 somehow (I have never use OSX)
- copy cclint.py to ~/bin
- ensure ~/bin is in PATH variable
- if directory with luac5.1 is not in PATH environment variable, set LUAC51 environment variable to full path to luac5.1.
- use it in terminal emulator by typing "cclint.py lua_file"
- in LUAC51 environment variable,
- in the directory with cclint.py [only on Windows],
- in directories in PATH environment variable.
Similar projects:
There is an experimental SublimeText 3 plugin: https://github.com/S...-contrib-cclint
It can be installed only by git clone to ~/.config/sublime-text-3/Packages directory.
Tested on linux, may work on OSX and should not work on windows without some changes in plugin code.
If windows support is needed, add issue or pull request in github project page.
Spoiler
Screenshot 1Edited on 11 March 2014 - 02:01 PM