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
25 lines (19 loc) · 784 Bytes
/
LuaSyntaxChecker.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)
if npp:GetExtPart() ~= ".lua" then return false end
editor:AnnotationClearAll()
-- Try to compile the lua code
local _, err = load(editor:GetText(0, editor.Length), npp:GetFileName(), "t")
-- See if it worked
if err == nil then return false end
print(err)
local line = tonumber(err:match(":(%d+):")) - 1
editor.AnnotationText[line] = err
editor.AnnotationStyle[line] = STYLE_BRACELIGHT
editor:GotoLine(line)
editor:VerticalCentreCaret()
return false
end)