page.lp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <html>
  2. <p>Prime numbers from 0 to 100, calculated by Lua:</p>
  3. <?
  4. function is_prime(n)
  5. if n <= 0 then return false end
  6. if n <= 2 then return true end
  7. if (n % 2 == 0) then return false end
  8. for i = 3, n / 2, 2 do
  9. if (n % i == 0) then return false end
  10. end
  11. return true
  12. end
  13. for i = 1, 100 do
  14. if is_prime(i) then print('<span>' .. i .. '</span>&nbsp;') end
  15. end
  16. ?>
  17. <p>Reading POST data from Lua (click submit):</p>
  18. <form method="POST"><input type="text" name="t1"/><input type="submit"></form>
  19. <pre>
  20. POST data: [<? post_data = read() print(post_data) ?>]
  21. request method: [<? print(request_info.request_method) ?>]
  22. IP/port: [<? print(request_info.remote_ip, ':', request_info.remote_port) ?>]
  23. URI: [<? print(request_info.uri) ?>]
  24. HTTP version [<? print(request_info.http_version) ?>]
  25. HEADERS:
  26. <?
  27. for name, value in pairs(request_info.http_headers) do
  28. print(name, ':', value, '\n')
  29. end
  30. ?>
  31. </pre>
  32. </html>