comparison website/src/examples/hi2.luan @ 503:92c3d22745b8

make _ENV optional
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 20 May 2015 23:24:46 -0600
parents 55f9f74f1e55
children 7bc63886d4f2
comparison
equal deleted inserted replaced
502:d3183a330ff5 503:92c3d22745b8
1 local Io = require "luan:Io" 1 local Io = require "luan:Io"
2 local Http = require "luan:http/Http" 2 local Http = require "luan:http/Http"
3 3
4 local M = {}
4 5
5 local function form() 6 local function form()
6 %> 7 %>
7 <html> 8 <html>
8 <body> 9 <body>
15 </body> 16 </body>
16 </html> 17 </html>
17 <% 18 <%
18 end 19 end
19 20
20 local function hello() 21 local function hello(name)
21 %> 22 %>
22 <html> 23 <html>
23 <body> 24 <body>
24 <h1>Hello</h1> 25 <h1>Hello</h1>
25 <p>Hi <%= name %>!</p> 26 <p>Hi <%= name %>!</p>
26 </body> 27 </body>
27 </html> 28 </html>
28 <% 29 <%
29 end 30 end
30 31
31 function respond() 32 function M.respond()
32 Io.stdout = Http.response.text_writer() 33 Io.stdout = Http.response.text_writer()
33 name = Http.request.parameter.name 34 local name = Http.request.parameter.name
34 if name == nil then 35 if name == nil then
35 form() 36 form()
36 else 37 else
37 hello() 38 hello(name)
38 end 39 end
39 end 40 end
41
42 return M