forked from dail8859/LuaScript
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLuaSyntaxChecker.lua
More file actions
Latest commit
25 lines (19 loc) · 784 Bytes
/
Copy pathLuaSyntaxChecker.lua
File metadata and controls
25 lines (19 loc) · 784 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
-- Any time a lua file is saved, this compiles it and checks for
-- syntax errors. Errors are added as inline annotations
editor1.AnnotationVisible=ANNOTATION_BOXED
editor2.AnnotationVisible=ANNOTATION_BOXED
npp.AddEventHandler("OnSave", function(filename, bufferid)
ifnpp:GetExtPart() ~=".lua" thenreturnfalseend
editor:AnnotationClearAll()
-- Try to compile the lua code
local_, err=load(editor:GetText(0, editor.Length), npp:GetFileName(), "t")
-- See if it worked
iferr==nilthenreturnfalseend
print(err)
localline=tonumber(err:match(":(%d+):")) -1
editor.AnnotationText[line] =err
editor.AnnotationStyle[line] =STYLE_BRACELIGHT
editor:GotoLine(line)
editor:VerticalCentreCaret()
returnfalse
end)