annotate website/src/examples/hi2.luan @ 388:12ee9a336b95

add more examples
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 23 Apr 2015 18:54:35 -0600
parents 8557581740db
children 2b9bc97f0439
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
382
8557581740db added tutorial
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 local Io = require "luan:Io"
8557581740db added tutorial
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 local Http = require "luan:web/Http"
8557581740db added tutorial
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3
388
12ee9a336b95 add more examples
Franklin Schmidt <fschmidt@gmail.com>
parents: 382
diff changeset
4
382
8557581740db added tutorial
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 local function form()
8557581740db added tutorial
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 %>
8557581740db added tutorial
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 <html>
8557581740db added tutorial
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 <body>
8557581740db added tutorial
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 <h1>Hello</h1>
8557581740db added tutorial
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 <form>
388
12ee9a336b95 add more examples
Franklin Schmidt <fschmidt@gmail.com>
parents: 382
diff changeset
11 What is you name?
12ee9a336b95 add more examples
Franklin Schmidt <fschmidt@gmail.com>
parents: 382
diff changeset
12 <input name="name">
12ee9a336b95 add more examples
Franklin Schmidt <fschmidt@gmail.com>
parents: 382
diff changeset
13 <input type=submit>
382
8557581740db added tutorial
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14 </form>
8557581740db added tutorial
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 </body>
8557581740db added tutorial
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 </html>
8557581740db added tutorial
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 <%
8557581740db added tutorial
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18 end
8557581740db added tutorial
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19
8557581740db added tutorial
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20 local function hello()
8557581740db added tutorial
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21 %>
8557581740db added tutorial
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 <html>
8557581740db added tutorial
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 <body>
8557581740db added tutorial
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 <h1>Hello</h1>
8557581740db added tutorial
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 <p>Hi <%= name %>!</p>
8557581740db added tutorial
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 </body>
8557581740db added tutorial
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27 </html>
8557581740db added tutorial
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28 <%
8557581740db added tutorial
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29 end
8557581740db added tutorial
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30
8557581740db added tutorial
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 function service()
8557581740db added tutorial
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32 Io.stdout = Http.response.text_writer()
8557581740db added tutorial
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
33 name = Http.request.parameters.name
8557581740db added tutorial
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
34 if name == nil then
8557581740db added tutorial
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35 form()
8557581740db added tutorial
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
36 else
8557581740db added tutorial
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
37 hello()
8557581740db added tutorial
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
38 end
8557581740db added tutorial
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
39 end