view src/luan/tools/web_run.luan @ 139:3b384dc5ca91

replace WebShell.java with web_shell.luan git-svn-id: https://luan-java.googlecode.com/svn/trunk@140 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Fri, 13 Jun 2014 12:26:44 +0000
parents 06159094b802
children 925ba2d59b9d
line wrap: on
line source

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

function page()
	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