comparison web/src/luan/modules/web/web_run.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_run.luan@9169581dc8fc
children 58c6ca5d4524
comparison
equal deleted inserted replaced
169:9169581dc8fc 170:7c792a328a83
1 import "Http"
2
3 local function lines(s)
4 local matcher = String.gmatch(s,"([^\n]*)\n|([^\n])+$")
5 return function()
6 local m1, m2 = matcher()
7 return m1 or m2
8 end
9 end
10
11 local function print_with_line_numbers(s)
12 i = 1
13 for line in lines(s) do
14 print(i,line)
15 i = i + 1
16 end
17 end
18
19 function page()
20 local content_type = Http.request.get_parameter("content_type")
21 if content_type ~= nil then
22 Http.response.set_content_type(content_type)
23 end
24 Io.stdout = Http.response.text_writer()
25 local code = Http.request.get_parameter "code"
26 local env = {
27 request = Http.request;
28 response = Http.response;
29 }
30 try
31 local run = load(code,"<web_run>",env)
32 run()
33 catch e do
34 Http.response.set_content_type "text/plain"
35 print(e)
36 print()
37 print()
38 print_with_line_numbers(code)
39 end
40 end