Post your best Lua script examples here

User avatar
By gerardwr
#3760 @alonewolfx2

Here's some TEST code for you
AND
a friendly request for solving the last major bug!

(2.93 KiB) Downloaded 280 times


Select file htmllua.html in your browser. It contains a mix of HTML and LUA statements. The LUA statements are nicely executed and the results printed in the serial console. Like this:
Code: Select allHtml:Hello. This HTML page contains a lua script<BR>
Lua-input:print("GPIO0="..gpio.read(8))
GPIO0=1
Lua-input:print("Chip="..node.chipid())
Chip=10116099
Lua-input:print("Heap="..node.heap())
Heap=6184
Lua-input:print("Lua executor : All lines in HTML file excuted")
Lua executor : All lines in HTML file excuted


The relevant code from init.lua is:
Code: Select all    61                 print("Lua-output:"..ln)
    62                 conn:send(ln)


Output from line 61 is visible in the serial console as the result from the executed Lua statement. That's excellent.

Output from line 61 refers the same variable and should be visible in the browser, but IT IS NOT.

I have a feeling that it is caused by "hidden" \r and or \n codes. I tried many things, but could not solve it yet.

Have a look please, maybe you will see something I have missed.

UPDATE : The resultline from the Lua execution does not come from line 61 !! It's from line 58. The lines 60/61/62 are never executed now! Line 58 executes the Lua statement OK, but does not return the result to the string, but prints it at the console. Grrrrrrrrrrrrr. Don't know how to fix it yet.
Code: Select all    54               while line ~= "?>" do
    55               if line then
    56                 print("Lua-input:"..line)
    57                 linef=loadstring(line)
    58                 ln=linef()
    59                 if ln then
    60                 ln = string.gsub(ln,"\n","")
    61                 print("Lua-output:"..ln)
    62                 conn:send(ln)
    63               end
User avatar
By alonewolfx2
#3766 loadstring() function like just input function. i am adding edited line and output.

Code: Select allwhile line ~= "?>" do
            if line then
              print("Lua-input:"..line)
              linef=loadstring(line)
              ln=linef()
           print("[debug]"..line)
              if ln then
              ln = string.gsub(ln,"\n","")
              print("Lua-output:"..ln)
              conn:send(ln)
            end


Code: Select allHtml:<html>
Html:<body>
Html:<BR>
Html:Hello. This HTML page contains a lua script<BR>
Lua-input:print("GPIO0="..gpio.read(8))
GPIO0=1
[debug]print("GPIO0="..gpio.read(8))
Lua-input:print("Chip="..node.chipid())
Chip=9988634
[debug]print("Chip="..node.chipid())
Lua-input:print("Heap="..node.heap())
Heap=7200
[debug]print("Heap="..node.heap())
Lua-input:print("Lua executor : All lines in HTML file excuted")
Lua executor : All lines in HTML file excuted
[debug]print("Lua executor : All lines in HTML file excuted")
Html:This is a HTML line. THE END!
Html:</body>
Html:</html>
name:init.lua,size:480
name:htmllua.html,size:265
name:webserver.lua,size:2422
User avatar
By gwizz
#3789 Greetings Gerardwr, Alonewolfx2 and others contributing to development

I haven't got delivery of my esp8266 modules yet otherwise I would be chipping in with you.

Just wanted to say that it might feel that you are all alone here hacking away in the dark....

But don't forget that there are thousands of people all around the world who think that this chip presents an opportunity to make things that couldn't be made before. Its a real game changer compared to other options.

Your good work here is being noted and appreciated - I'm sure we'll see some projects and even products based on it soon enough.

Anyhow, for every one person speaking up there are at least a hundred silently reading and you should consider yourselves hacker's hackers - people making the stuff of the 21st century!

Gareth
User avatar
By gerardwr
#3796
gwizz wrote:Just wanted to say that it might feel that you are all alone here hacking away in the dark....
<snip>
Your good work here is being noted and appreciated - I'm sure we'll see some projects and even products based on it soon enough.

Anyhow, for every one person speaking up there are at least a hundred silently reading and you should consider yourselves hacker's hackers - people making the stuff of the 21st century!

Gareth


Thanks for your nice words, they are heartwarming!

In general hackers do not often mind (happily) "hacking in the dark". They are often in for the personal fun, like me!

[fustration mode ON]
However if you're trying to combine personal fun, with giving something back to "the community", it CAN be a little frustrating when only few actively join the conversation. You start wondering if you're working on something sensible.
[frustration mode OFF]

Your thumbs-up made my day, gives me fuel for the next stretch.

Hope you get your ESP delivered soon, and then come and join the fun.

Have a nice day Gareth.