I have been struggling all day with getting node.input and node.output working in my webserver code.
I give up, I need help from a REAL expert.
What do I want to do:
Build a webserver that can:
1. display html files in a browser (done)
2. execute Lua statements embedded in a html file and display the result (normally going to the serial console) in the browser (the problem).
This is the file htmllua.html. Note the <?lua and ?> lines aroound the lua statements
Hello. This HTML page contains a lua script<BR>
print("Lua executor : All lines in HTML file excuted")
This is the interesting part of the code.
54 local line=file.readline()
55 if line then
56 -- strip the \n at the end of the line
57 line = string.gsub(line,"\n","")
58 if line == "<?lua" then
60 while line ~= "?>" do
61 line=file.readline() line = string.gsub(line,"\n","")
66 -- read the next line to process
68 line = string.gsub(line,"\n","")
71 print("Html:"..line) conn:send(line)
73 until not line
This the console output. Note that the Lua lines are recognised, BUT only the 1st Lua statement (the GPIO) is executed, and the result is displayed at the end of the output. Then a „>” follows, the prompt?
GET /htmllua.html HTTP/1.1
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/<snip>
Html:Hello. This HTML page contains a lua script<BR>
Lua:print("Lua executor : All lines in HTML file excuted")|
Here is the entire lua code
My specific questions are:
- Why is just ONE lua statement correctly processed, and following ones NOT
- Why is the output of the processed statement at the END of the output, and not at the output position when the statement was recognized and executed.
I can imagine making a stupid mistake, my entire Lua experience is based on the working the last weeks with nodeMcu.
Help me find the „stupid mistake”. Please!