page2.lua 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. mg.write("HTTP/1.0 200 OK\r\n")
  2. mg.write("Content-Type: text/html\r\n")
  3. mg.write("\r\n")
  4. mg.write([[<html><body>
  5. <p>This is another example of a Lua server page, served by
  6. <a href="http://code.google.com/p/civetweb">Civetweb web server</a>.
  7. </p><p>
  8. The following features are available:
  9. <ul>
  10. ]])
  11. -- function in one Lua tag should still be available in the next one
  12. function test(tab, name)
  13. if tab then
  14. mg.write("<li>" .. name .. "</li>\n")
  15. end
  16. end
  17. function recurse(tab)
  18. mg.write("<ul>\n")
  19. for k,v in pairs(tab) do
  20. if type(v) == "table" then
  21. mg.write("<li>" .. tostring(k) .. ":</li>\n")
  22. recurse(v)
  23. else
  24. mg.write("<li>" .. tostring(k) .. " = " .. tostring(v) .. "</li>\n")
  25. end
  26. end
  27. mg.write("</ul>\n")
  28. end
  29. mg.write("<li>" .. _VERSION .. " with the following standard libraries</li>\n")
  30. mg.write("<ul>\n")
  31. libs = {"string", "math", "table", "io", "os", "bit32", "package", "coroutine", "debug"};
  32. for _,n in ipairs(libs) do
  33. test(_G[n], n);
  34. end
  35. mg.write("</ul>\n")
  36. test(sqlite3, "sqlite3 binding")
  37. test(lfs,"lua file system")
  38. libname = "mg"
  39. test(_G[libname], libname .. " library")
  40. recurse(_G[libname])
  41. mg.write("</ul></p>\n");
  42. mg.write("<p> Today is " .. os.date("%A") .. "</p>\n");
  43. mg.write("<p>\n");
  44. if lfs then
  45. mg.write("Files in " .. lfs.currentdir())
  46. mg.write("\n<ul>\n")
  47. for f in lfs.dir(".") do
  48. mg.write("<li>" .. f .. "</li>\n")
  49. local at = lfs.attributes(f);
  50. recurse(at)
  51. end
  52. mg.write("</ul>\n")
  53. end
  54. mg.write([[
  55. </p>
  56. </body></html>
  57. ]])