Handling the form data string is working quite well now. I can pass any key and value to a local database. I am still working on letting the webpage itself define what resources lua needs to allocate in terms of database for form data and variables that need to be passed into the html.
I found this neat way of deciphering the first line of the http request to seprate the method (i.e. GET, POST etc), the path and also the major and minor html version type (if you so wish). A side effect of this is that by looking for this pattern you can automatically check the basic validitiy of the request also. (See here for more good tricks: http://www.steve.org.uk/Software/lua/lua-httpd/)
Here's what it now looks like:
.......
.......
.......
conn:on("receive",function(conn,payload)
--print(payload)
-- Look for a http request
_, _, method, path, major, minor = string.find(request, "([A-Z]+) (.+) HTTP/(%d).(%d)")
if (method == nil) then
-- Bad request
conn:send("Bad Request") print("Bad Request"..payload) conn:on("sent",function(conn) conn:close() end)
-- Valid request
else
-- Was it a POST method request?
if (method == "POST") then
.......
.......
.......
The string library, and in particular the pattern and capture features, of LUA are awesome but quite confusing. This seems to be a serious coding "weapon" for LUA so the more we can work understand this the more we can do with LUA. Smaller functions, execution and memory usage can all be improved with utilizing the correct string function.
I like what you are doing with embedding lua code into a html. I can see where that can come in handy in many applications. Keep at it and if I can add anything I will.