Post your best Lua script examples here

User avatar
By alonewolfx2
#3404 no longer crash with the wrong request. not anymore :)
Attachments
(2.43 KiB) Downloaded 622 times
User avatar
By gerardwr
#3420
alonewolfx2 wrote:tadaa :) it crashed with tcp request :D
[code]GET / TCP\r\n\r\n


Yep, I tested it only with a browser that does GET /.……..HTTP requests. I get the filename (the …….) by getting the string op to the HTTP part, if that's not there, kaboooom! This Lua string handling is a pain in the …….

Thanks for testing, and the updated version.
User avatar
By alonewolfx2
#3421 i am trying with small js and css file but "This Lua string handling is a pain in the ……." as you said
User avatar
By gerardwr
#3424 Said earlier that I intend .lua files that are "clicked" in the homepage will be executed with
Code: Select alldofile("filename.lua")


I think i'm going for another approach, following the concept of PHP, as "extension" to HTML.

PHP
Code: Select all<html>
<head>
<title>My first PHP page</title>
</head>
<body>
   <?php   
   echo "<h1>Hello World!</h1>";
   ?>
</body>
</html>


LUA
Code: Select all<html>
<head>
<title>My first LUA page</title>
</head>
<body>
   <?lua   
       conn:send("<h1>Hello World!</h1>")
       conn:send("Your Ip is : " .. wifi.sta.getip())
       print("This debug lines goes to the serial port")
       dofile("somecode.lua","param1","param2")
       ?>
</body>
</html>


I think this is much more useful than just executing all statements in a .lua file.

Implementation seems "easy". Send all (HTML) lines to browser (as is now) until the line is "<?lua". Then execute each of the flowing (lua) lines until the line is ">?". Then, again HTML lines will follow.

So, what do you think?