Mercurial Hosting > luan
annotate 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 |
rev | line source |
---|---|
382 | 1 local Io = require "luan:Io" |
494
2b9bc97f0439
change luan:web to luan:http
Franklin Schmidt <fschmidt@gmail.com>
parents:
388
diff
changeset
|
2 local Http = require "luan:http/Http" |
382 | 3 |
503 | 4 local M = {} |
388 | 5 |
382 | 6 local function form() |
7 %> | |
8 <html> | |
9 <body> | |
10 <h1>Hello</h1> | |
11 <form> | |
497
55f9f74f1e55
Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
12 What is your name? |
388 | 13 <input name="name"> |
14 <input type=submit> | |
382 | 15 </form> |
16 </body> | |
17 </html> | |
18 <% | |
19 end | |
20 | |
503 | 21 local function hello(name) |
382 | 22 %> |
23 <html> | |
24 <body> | |
25 <h1>Hello</h1> | |
26 <p>Hi <%= name %>!</p> | |
27 </body> | |
28 </html> | |
29 <% | |
30 end | |
31 | |
503 | 32 function M.respond() |
382 | 33 Io.stdout = Http.response.text_writer() |
503 | 34 local name = Http.request.parameter.name |
382 | 35 if name == nil then |
36 form() | |
37 else | |
503 | 38 hello(name) |
382 | 39 end |
40 end | |
503 | 41 |
42 return M |