page2.lp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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="http://code.google.com/p/civetweb">Civetweb web server</a>.
  6. </p><p>
  7. The following features are available:
  8. <ul>
  9. <?
  10. -- function in one Lua tag should still be available in the next one
  11. function test(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. mg.write("<li>" .. _VERSION .. " with the following standard libraries</li>\n")
  31. mg.write("<ul>")
  32. libs = {"string", "math", "table", "io", "os", "bit32", "package", "coroutine", "debug"};
  33. for _,n in ipairs(libs) do
  34. test(_G[n], n);
  35. end
  36. mg.write("</ul>\n")
  37. test(sqlite3, "sqlite3 binding")
  38. test(lfs,"lua file system")
  39. libname = "mg"
  40. test(_G[libname], libname .. " library")
  41. recurse(_G[libname])
  42. ?>
  43. </ul></p>
  44. <p> Today is <? mg.write(os.date("%A")) ?>
  45. <p>
  46. <?
  47. -- for k,v in pairs(_G) do mg.write(k, '\n') end
  48. if lfs then
  49. mg.write("Files in " .. lfs.currentdir())
  50. mg.write("\n<ul>\n")
  51. for f in lfs.dir(".") do
  52. mg.write("<li>" .. f .. "</li>\n")
  53. local at = lfs.attributes(f);
  54. recurse(at)
  55. end
  56. mg.write("</ul>\n")
  57. end
  58. ?>
  59. </p>
  60. </body></html>