2
0

test_main.lua 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. cgilua.htmlheader()
  2. cgilua.put[[
  3. <html>
  4. <head><title>Script Lua Test</title></head>
  5. <body>
  6. cgi = {
  7. ]]
  8. for i,v in pairs (cgi) do
  9. if type(v) == "table" then
  10. local vv = "{"
  11. for a,b in pairs(v) do
  12. vv = string.format ("%s%s = %s<br>\n", vv, a, tostring(b))
  13. end
  14. v = vv.."}"
  15. end
  16. cgilua.put (string.format ("%s = %s<br>\n", i, tostring(v)))
  17. end
  18. cgilua.put "}<br>\n"
  19. cgilua.put ("Remote address: "..cgilua.servervariable"REMOTE_ADDR")
  20. cgilua.put "<br>\n"
  21. cgilua.put ("Is persistent = "..tostring (SAPI.Info.ispersistent).."<br>\n")
  22. cgilua.put ("ap="..tostring(ap).."<br>\n")
  23. cgilua.put ("lfcgi="..tostring(lfcgi).."<br>\n")
  24. -- Checking Virtual Environment
  25. local my_output = cgilua.put
  26. cgilua.put = nil
  27. local status, err = pcall (function ()
  28. assert (cgilua.put == nil, "cannot change cgilua.put value")
  29. end)
  30. cgilua.put = my_output
  31. assert (status == true, err)
  32. -- Checking require
  33. local status, err = pcall (function () require"unknown_module" end)
  34. assert (status == false, "<tt>unknown_module</tt> loaded!")
  35. -- assert (package == nil, "Access to <tt>package</tt> table allowed!")
  36. cgilua.put[[
  37. <p>
  38. </body>
  39. </html>
  40. ]]
  41. cgilua = nil