- Mon Dec 01, 2014 4:06 am
#3660
alonewolfx2 wrote:i changed this line.
Code: Select allline = string.gsub(line,"\n","")
if line == "<?lua" then node.input(file.readline().."\r\n") function s_output(str) if (conn~=nil) then conn:send(str) end end node.output(s_output,1) end
if line == "?>" then end
conn:send(line)
I added your code to mine. Looks simple but I did not understand it at first. I have split the "one-liner" to separate lines for better understanding.
Code: Select all repeat
local line=file.readline()
if line then
-- strip the \n at the end of the line
line = string.gsub(line,"\n","")
if line == "<?lua" then
node.input(file.readline().."\r\n")
function s_output(str)
if (conn~=nil) then conn:send(str) end
end
node.output(s_output,1)
end
if line == "?>" then end
end
until not line
1.It seems that in your code the 1st line AFTER the "<?lua" line is executed, but the remaining lines are just printed, is that correct?
2.It seems that result from the executed line is just printed to the console, not to send to the browser.
Can you confirm my assumptions 1. and 2.?
I want all of the lua lines between "<?lua" and "?>" executed and the result of each executed line printed to the serial console and to the browser.
For testing I now use the following htmllua.html file
Code: Select all<html>
<body>
<BR>
Hello. This HTML page contains a lua script<BR>
<?lua
print("Lua line in HTML file excuted")
print("GPIO0="..gpio.read(8))
print("Chip="..node.chipid())
print("Heap="..node.heap())
?>
</body>
</html>
Then I would expect as output in the browser:
Code: Select all Hello. This HTML page contains a lua script
Lua line in HTML executed
GPIO0=1
Chip=123456
Heap=1234
If you have any time, would you have look at it too, together we can crack this egg!
Almost there……..but not quite yet!