Mercurial Hosting > luan
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/luan/tools/web_run.luan Thu Jun 12 08:20:48 2014 +0000 @@ -0,0 +1,32 @@ +import "Http" + +local function lines(s) + local matcher = String.gmatch(s,"([^\n]*)\n|([^\n])+$") + return function() + local m1, m2 = matcher() + return m1 or m2 + end +end + +local function print_with_line_numbers(s) + i = 1 + for line in lines(s) do + print(i,line) + i = i + 1 + end +end + +return function() + Http.response.set_content_type "text/plain" + Io.stdout = Http.response.text_writer() + local code = Http.request.get_parameter "code" + try + local fn = load(code,"<web_run>") + fn() + catch e do + print(e) + print() + print() + print_with_line_numbers(code) + end +end