jim121049 wrote:What's supposed to happen when I click on "htmllua.html" in the webserver's list of files?
htmllua.html contains:
<html>
<body>
<BR>
Hello. This HTML page contains a lua script<BR>
<?lua
print("Lua line in HTML file excuted")
rint("Error in Lua lined")
?>
</body>
</html>
The OBJECTIVE (does NOT do that now in the current version yet) is that it outputs:
Hello. This HTML page contains a lua script
Lua line in HTML file excited
lua: stdin:1: attempt to call global 'rint' (a nil value)
The principle is like PHP embedded in html. Meaning, the lines in the HTML file with lua statements (contained within the "?>lua" and "?>" lines) are executed and the result is integrated in the HTML output, and thus made visible in the browser.
Current code (for testing) should prove that the "?>lua" and "?>" lines are recognized and that the lines between are meant to be literally executed:
if line == "<?lua" then print("<?lua : lua ON") conn:send("<?lua : lua ON") end
if line == "?>" then print("?> : lua OFF") conn:send("?> : lua OFF") end
print(line) conn:send(line)
I'm still searching for a (best) way to process the input lines and inject the result from these statements into the html, that's being sent to the browser. Courrent idea, still to be tested is:
- get the lua line in a string (f.i. in the variable line)
- execute the content of the string with : loadstring(line) (ref.: http://www.gammon.com.au/scripts/doc.php?lua=assert
- result from the executed line in a string (like outputstring)
- send the output from the string execution to the browser with : conn:send(outputstring)
For performance reasons it would be great to execute all lua lines in 1 go, and get the combines results back in string, to be sent to the browser. Not sure how that do that yet. I'm sure there's a way, but am new to Lua too.
Does that make sense to you? Anyone?
Any suggestions or test are welcome.