changeset 1361:9eba6bf0163b

improve Run.luan
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 22 Apr 2019 00:38:11 -0600
parents ee0f0e6c89a0
children 77f2d091f17f
files src/luan/modules/http/tools/Run.luan
diffstat 1 files changed, 22 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
diff -r ee0f0e6c89a0 -r 9eba6bf0163b src/luan/modules/http/tools/Run.luan
--- a/src/luan/modules/http/tools/Run.luan	Sun Apr 21 02:32:41 2019 -0600
+++ b/src/luan/modules/http/tools/Run.luan	Mon Apr 22 00:38:11 2019 -0600
@@ -12,7 +12,7 @@
 local Run = {}
 
 local function lines(s)
-	local matcher = gmatch(s,"([^\n]*)\n|([^\n])+$")
+	local matcher = gmatch(s,"([^\n]*)\n|([^\n]+)$")
 	return function()
 		local m1, m2 = matcher()
 		return m1 or m2
@@ -67,6 +67,26 @@
 </html>
 <% end
 
+function Run.run(code,source_name)
+	return try {
+		function()
+			local run = load(code,source_name)
+			run()
+			return true
+		end
+		catch = function(e)
+			Http.response.reset()
+			Http.response.headers["content-type"] = "text/plain; charset=utf-8"
+			Io.stdout = Http.response.text_writer()
+			print(e)
+			print()
+			print()
+			print_with_line_numbers(code)
+			return false
+		end
+	}
+end
+
 function Run.respond()
 	local content_type = Http.request.parameters.content_type
 	if content_type ~= nil then
@@ -78,21 +98,7 @@
 		form()
 		return
 	end
-	try {
-		function()
-			local run = load(code,"<web_run>")
-			run()
-		end
-		catch = function(e)
-			Http.response.reset()
-			Http.response.headers["content-type"] = "text/plain; charset=utf-8"
-			Io.stdout = Http.response.text_writer()
-			print(e)
-			print()
-			print()
-			print_with_line_numbers(code)
-		end
-	}
+	Run.run(code,"<web_run>")
 end
 
 return Run