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