comparison web/src/luan/modules/web/web_shell.luan @ 170:7c792a328a83

add web component git-svn-id: https://luan-java.googlecode.com/svn/trunk@171 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Sun, 22 Jun 2014 05:20:30 +0000
parents src/luan/modules/web/web_shell.luan@9169581dc8fc
children 58c6ca5d4524
comparison
equal deleted inserted replaced
169:9169581dc8fc 170:7c792a328a83
1 import "Http"
2
3 per_session = true
4
5 local history = {}
6 local env = {}
7
8 Io.stdout = {}
9 function Io.stdout.write(...)
10 for _,v in Basic.values(...) do
11 history[#history+1] = v
12 end
13 end
14
15 function page()
16 if Http.request.get_parameter("clear") ~= nil then
17 history = {}
18 else
19 local cmd = Http.request.get_parameter("cmd")
20 if cmd ~= nil then
21 print( "% "..cmd )
22 try
23 local line = load(cmd,"<web_shell>",env,true);
24 Debug.print_if_something( line() )
25 catch e do
26 Io.print_to(Io.stderr,e)
27 print(e)
28 end
29 end
30 end
31
32 local write = Http.response.text_writer().write
33 write %>
34 <html>
35 <title>Luan Shell</title>
36 <body>
37 <p>This is a command shell. Enter commands below.
38 <pre><%
39 for _,v in ipairs(history) do
40 write(v)
41 end
42 write %></pre>
43 <form name='theForm' method='post'>
44 % <input name='cmd' size=60>
45 <input type=submit value=run>
46 <input type=submit name=clear value=clear>
47 </form>
48
49 <script>document.theForm.cmd.focus();</script>
50
51 <p/>
52 </body>
53 </html>
54 <%
55
56 end