page2.lp 1.8 KB

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