Post your best Lua script examples here

User avatar
By gerardwr
#3843 This POLL is now closed!

The work is done.

Have a look over here!
http://www.esp8266.com/viewtopic.php?f=19&t=702

===============================================
Some of you may know that I have been busy developing a webserver for the nodeMcu firmware. Current status is "maybe not perfect, but at least working". The goal to have a webserver that serves html files with embedded Lua statements to a browser is (almost) achieved. Special thanks to zeroday and alonewolfx2 for their advice and support during the slippery path I have travelled.

Progress is listed in the Examples sections here:
http://www.esp8266.com/viewtopic.php?f=19&t=611

In this (now loooooooong topic) I got the following tip, thanks to user wififofum:
wififofum wrote:Just wondering if you guys have looked at http://wiki.eluaproject.net/lhttpd


OMG !!!!

I had a first look at this site today and here's what I read:
The full list of features is given below:

completely written in Lua
can handle a single connection at a time (for now)
can serve text and images (so far)
gets its files from the ROM file system (this will be extended when more filesystems are added)
can execute embedded Lua code and replace it with its output (via "print" statements). Embed Lua code in your HTML files between tags
if a file with ".lua" extension is requested, it doesn't send the file, but executes it and sends its output (via "print" statements)


It looks like the documentation of my webserver code :shock:

Had I seen this sooner it would have saved me many hours of programming and debugging. Then again, I would have missed out on the fun of learning another programming language.

Perhaps a joined effort here to migrate this webserver to the ESP would make interesting community effort.

I'm interested i what you think. Please take 10 seconds to answer the poll. I'll let it run for 7 days. If anyone has migrated the elua webserver within this week, I'll be happy too ;)
Last edited by gerardwr on Tue Dec 02, 2014 7:25 pm, edited 2 times in total.
User avatar
By alonewolfx2
#3846 i am trying many different way but i couldnt find any solution for lua code embed webserver.simple webserver can be migrate with nodeMcu. but is it necessary?
User avatar
By gerardwr
#3847
alonewolfx2 wrote:i am trying many different way but i couldnt find any solution for lua code embed webserver.simple webserver can be migrate with nodeMcu. but is it necessary?


No migration is not really necessary. I guess in the end the webserver code will work OK.

But migration is an interesting challenge, I think.

Anyway, in the elua webserver they have a solution for the execution a lua command, and return the result in a string. Is based on load string and replacing the built-in "print" function by another one that prints to a string.
User avatar
By alonewolfx2
#3849 yes. it could work. good idea

gerardwr wrote:Anyway, in the elua webserver they have a solution for the execution a lua command, and return the result in a string. Is based on load string and replacing the built-in "print" function by another one that prints to a string.