From 1284b6363ea81e9b4f0f5a2d0dc5b0900624910d Mon Sep 17 00:00:00 2001 From: Marcos Kirsch Date: Sun, 8 Mar 2015 19:45:43 -0500 Subject: [PATCH] Add compilation of server files. --- init.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/init.lua b/init.lua index 9f46060..a79a6eb 100644 --- a/init.lua +++ b/init.lua @@ -6,6 +6,25 @@ print('chip: ',node.chipid()) print('heap: ',node.heap()) wifi.sta.config("Internet","") +-- Compile server code and remove original .lua files. +-- This only happens the first time afer the .lua files are uploaded. + +local compileAndRemoveIfNeeded = function(f) + if file.open(f) then + file.close() + node.compile(f) + file.remove(f) + end +end + +local serverFiles = {'httpserver.lua', 'httpserver-static.lua', 'httpserver-error.lua'} +for i, f in ipairs(serverFiles) do compileAndRemoveIfNeeded(f) end + +compileAndRemoveIfNeeded = nil +serverFiles = nil + +-- Connect to the WiFi access point. Once the device is connected, +-- you may start the HTTP server. tmr.alarm(0, 3000, 1, function() if wifi.sta.getip() == nil then print("Connecting to AP...")