forked from devyte/nodemcu-platform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compile.lua
31 lines (28 loc) · 827 Bytes
/
compile.lua
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
26
27
28
29
30
31
-- Compile code and remove original .lua files.
-- This only happens the first time afer the .lua files are uploaded.
-- Skip init.lua!
return function(filename)
local function compileAndRemoveIfNeeded(f)
if file.exists(f) then
print('Compiling:', f)
tmr.wdclr()
node.compile(f)
file.remove(f)
print("done")
collectgarbage()
end
end
if filename then
compileAndRemoveIfNeeded(filename)
else
local allFiles = file.list()
for f,s in pairs(allFiles) do
if f~="init.lua" and #f >= 4 and string.sub(f, -4, -1) == ".lua" then
compileAndRemoveIfNeeded(f)
end
end
allFiles = nil
end
compileAndRemoveIfNeeded = nil
collectgarbage()
end