Form Handling
Entering values on this form should display them as values in the first submission, and as a cookie in the next submission
The values should show the previous POST
Values: Username = <%= cgilua.POST.user or "(not set)"%>, Password = <%= cgilua.POST.pass or "(not set)"%>
Cookies test
Here you should see the values posted before the ones shown above
cookie_kepler = <%= cgilua.cookies.get("cookie_kepler") or "(not set)" %>
File Upload
Choose a file to upload, press "Upload" and a link to the file should appear below with the corresponding "Remove" button.
<% local f = cgilua.POST.file if f and next(f) then local _, name = cgilua.splitonlast(f.filename) local file = f.file local dest = io.open(name, "wb") if dest then local bytes = file:read("*a") dest:write(bytes) dest:close() cgilua.print(""..name.."\n") cgilua.print([[]]) end end %> <% if cgilua.POST.remove then os.remove(cgilua.POST.filename) end %> <% local function showtable(t) cgilua.put "{" for i,v in pairs (t) do cgilua.put("\n") if type(v) == "table" then local vv = "{\n" for a,b in pairs(v) do vv = string.format ("%s %s = [[%s]],\n", vv, a, tostring(b)) end v = vv.." }," cgilua.put (string.format (" %s = %s", i, tostring(v))) else cgilua.put (string.format (" %s = [[%s]],", i, tostring(v))) end end if next(t) then cgilua.put "\n" end cgilua.put "}\n" end %>cgilua.QUERY
<% showtable (cgilua.QUERY) %>
cgilua.POST
<% showtable (cgilua.POST) %>
CGILua Variables
cgilua.<%= v %> | <%= tostring(cgilua[v]) %> |
Server Variables
<%= v %> | <%= tostring(cgilua.servervariable(v)) %> |
Multiple Output
The next test should show numbers, from 1 to 3, and the string "OK" together. The first line should show the results without spaces and the second should separate them with tabs.
cgilua.put(1, 2, 3, "OK") --> <% cgilua.put(1, 2, 3, "OK") %>
The next test should show numbers, from 1 to 3, and the string "OK" separated by tabs.
cgilua.print(1, 2, 3, "OK") --> <% cgilua.print(1, 2, 3, "OK") %>
Date
Today is: <%= os.date() %>
Image test
Here should be a small image:
FileSystem test
<%
local d = lfs.currentdir () or ""
cgilua.put("Iterating over "..d.."
")
for file in lfs.dir(d) do cgilua.put(" "..file.."
") end
%>
Containment test
<% if (x == nil) then x = 1 else x = x + 1 end %> Expected value: 1, actual value: <%= x %>.