Post your best Lua script examples here

User avatar
By gerardwr
jim121049 wrote:What's supposed to happen when I click on "htmllua.html" in the webserver's list of files?

htmllua.html contains:
Code: Select all<html>
    Hello. This HTML page contains a lua script<BR>
print("Lua line in HTML file excuted")
rint("Error in Lua lined")

The OBJECTIVE (does NOT do that now in the current version yet) is that it outputs:
Code: Select all 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:
Code: Select allif 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.:
- 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.
User avatar
By alonewolfx2
#3544 it have ram problem on the android tablet or phone.
its dropping every request from mobile and restarting. i dont know why
User avatar
By gerardwr
alonewolfx2 wrote:it have ram problem on the android tablet or phone.
its dropping every request from mobile and restarting. i dont know why

Can confirm that there's a problem with the latest update. I got my HW working again for 1 minute :( and tested what the result was after the correction published by jim121049.

Schermafbeelding 2014-11-30 om 00.31.40.png
Schermafbeelding 2014-11-30 om 00.31.40.png (53.28 KiB) Viewed 1212 times

File htmllua showed OK, but the recognition on the embedded lua cod is not a 100%

When I clicked helloesp.html the ESP restarted.

Will report back when I have a working version again. For tinkerers, use the previous version, that was ok for me and alonewolfx2.