comparison src/luan/tools/web_run.luan @ 138:06159094b802

replace WebRun.java with web_run.luan git-svn-id: https://luan-java.googlecode.com/svn/trunk@139 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Thu, 12 Jun 2014 08:20:48 +0000
parents
children 3b384dc5ca91
comparison
equal deleted inserted replaced
137:573ce091ae00 138:06159094b802
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 return function()
20 Http.response.set_content_type "text/plain"
21 Io.stdout = Http.response.text_writer()
22 local code = Http.request.get_parameter "code"
23 try
24 local fn = load(code,"<web_run>")
25 fn()
26 catch e do
27 print(e)
28 print()
29 print()
30 print_with_line_numbers(code)
31 end
32 end