test-sqpage.lua 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. --local fd = io.open("/dev/null", "w")
  2. function myprint(...)
  3. for i = 1, select("#",...) do
  4. --fd:write(tostring(select(i,...)));
  5. tostring(select(i,...));
  6. end
  7. --print.acall2(this, vargv);
  8. end
  9. function read()
  10. return "some reading";
  11. end
  12. local request_info = {
  13. request_method = "POST",
  14. remote_ip="localhost",
  15. remote_port="8080",
  16. uri="http://www.dad.dad/",
  17. http_version="1.1",
  18. http_headers={
  19. name="carl marks",
  20. age="200",
  21. high="1.8",
  22. country="urss",
  23. language="english",
  24. },
  25. };
  26. local now = os.clock();
  27. for i=0, 100000 do
  28. myprint([[<html>
  29. <p>Prime numbers from 0 to 100, calculated by Squirrel:</p>
  30. ]]);
  31. function is_prime(n)
  32. if( n <= 0 ) then return false end;
  33. if( n <= 2 ) then return true end;
  34. if (n % 2 == 0) then return false end;
  35. for i = 3, n / 2, 2 do
  36. if (n % i == 0) then return false end;
  37. end
  38. return true;
  39. end
  40. for i = 1, 100 do
  41. if( is_prime(i) ) then myprint("<span>", i , "</span>&nbsp;") end;
  42. end
  43. myprint([[
  44. <p>Reading POST data from Squirrel (click submit):</p>
  45. <form method=""POST""><input type=""text"" name=""t1""/><input type=""submit""></form>
  46. <pre>
  47. POST data: []]);
  48. local post_data = read(); myprint(post_data);
  49. myprint([[]
  50. request method: []]);
  51. myprint(request_info.request_method);
  52. myprint([[]
  53. IP/port: []]);
  54. myprint(request_info.remote_ip, ":", request_info.remote_port);
  55. myprint([[]
  56. URI: []]);
  57. myprint(request_info.uri);
  58. myprint([[]
  59. HTTP version []]);
  60. myprint(request_info.http_version);
  61. myprint([[]
  62. HEADERS:
  63. ]]);
  64. for name, value in pairs(request_info.http_headers) do
  65. myprint(name, ":", value, "\n");
  66. end
  67. myprint([[
  68. </pre>
  69. </html>
  70. ]]);
  71. end
  72. print(os.clock()-now);