changeset 580:1e69d9c21461

add Table.clear(); add Http.response.reset(); fix http/run;
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 21 Jul 2015 14:56:41 -0600
parents f22a09e98b04
children 5d4652d78ce0
files core/src/luan/modules/Table.luan core/src/luan/modules/TableLuan.java http/src/luan/modules/http/Http.luan http/src/luan/modules/http/Http_test.luan http/src/luan/modules/http/run.luan website/src/manual.html.luan
diffstat 6 files changed, 37 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/core/src/luan/modules/Table.luan	Thu Jul 16 15:14:31 2015 -0600
+++ b/core/src/luan/modules/Table.luan	Tue Jul 21 14:56:41 2015 -0600
@@ -3,6 +3,7 @@
 
 local M = {}
 
+M.clear = TableLuan.clear
 M.concat = TableLuan.concat
 M.copy = TableLuan.copy
 M.insert = TableLuan.insert
--- a/core/src/luan/modules/TableLuan.java	Thu Jul 16 15:14:31 2015 -0600
+++ b/core/src/luan/modules/TableLuan.java	Tue Jul 21 14:56:41 2015 -0600
@@ -111,4 +111,9 @@
 	public static LuanTable new_property_table() {
 		return LuanPropertyMeta.INSTANCE.newTable();
 	}
+
+	public static void clear(LuanTable tbl) {
+		tbl.rawClear();
+	}
+
 }
--- a/http/src/luan/modules/http/Http.luan	Thu Jul 16 15:14:31 2015 -0600
+++ b/http/src/luan/modules/http/Http.luan	Tue Jul 21 14:56:41 2015 -0600
@@ -7,6 +7,8 @@
 local Io = require "luan:Io"
 local Html = require "luan:Html"
 local url_encode = Html.url_encode or error()
+local Table = require "luan:Table"
+local clear = Table.clear or error()
 local HttpServicer = require "java:luan.modules.http.HttpServicer"
 local IoLuan = require "java:luan.modules.IoLuan"
 
@@ -35,8 +37,12 @@
 	error "headers are not accessible after you start writing content"
 end
 
-M.sent_error_metatable = { __index=sent_error, __new_index=sent_error }
+local sent_error_metatable = { __index=sent_error, __new_index=sent_error }
 
+function M.sent_headers(headers)
+	clear(headers)
+	set_metatable(headers,sent_error_metatable)
+end
 
 
 local function new_common(this)
@@ -111,7 +117,7 @@
 
 		function this.set()
 			HttpServicer.setResponse(this,this.java)
-			set_metatable(this.headers,M.sent_error_metatable)
+			M.sent_headers(this.headers)
 		end
 
 		function this.text_writer()
@@ -123,6 +129,11 @@
 			this.set()
 			return IoLuan.binaryWriter(this.java.getOutputStream())
 		end
+
+		function this.reset()
+			this.java.reset()
+			set_metatable(this.headers,nil)
+		end
 	end
 	return this
 end
--- a/http/src/luan/modules/http/Http_test.luan	Thu Jul 16 15:14:31 2015 -0600
+++ b/http/src/luan/modules/http/Http_test.luan	Tue Jul 21 14:56:41 2015 -0600
@@ -31,7 +31,7 @@
 	Http.response = Http.new_response{
 
 		text_writer = function()
-			set_metatable(Http.response.headers,M.sent_error_metatable)
+			Http.sent_headers(Http.response.headers)
 			M.result = Io.uri "string:"
 			M.text_writer = M.result.text_writer()
 			return M.text_writer
--- a/http/src/luan/modules/http/run.luan	Thu Jul 16 15:14:31 2015 -0600
+++ b/http/src/luan/modules/http/run.luan	Tue Jul 21 14:56:41 2015 -0600
@@ -4,11 +4,13 @@
 local try = Luan.try or error()
 local Io = require "luan:Io"
 local print = Io.print or error()
+local String = require "luan:String"
+local gmatch = String.gmatch or error()
 local Http = require "luan:http/Http"
 
 
 local function lines(s)
-	local matcher = s.gmatch "([^\n]*)\n|([^\n])+$"
+	local matcher = gmatch(s,"([^\n]*)\n|([^\n])+$")
 	return function()
 		local m1, m2 = matcher()
 		return m1 or m2
@@ -72,16 +74,16 @@
 <% end
 
 return function()
+	local content_type = Http.request.parameter.content_type
+	if content_type ~= nil then
+		Http.response.header.content_type = content_type
+	end
 	Io.stdout = Http.response.text_writer()
 	local code = Http.request.parameter.code
 	if code == nil then
 		form()
 		return
 	end
-	local content_type = Http.request.parameter.content_type
-	if content_type ~= nil then
-		Http.response.header.content_type = content_type
-	end
 	local env = {
 		request = Http.request;
 		response = Http.response;
@@ -92,10 +94,12 @@
 			run()
 		end;
 		catch = function(e)
+			Http.response.reset()
 			Http.response.header.content_type = "text/plain"
+			Io.stdout = Http.response.text_writer()
 			print(e)
-			print()
-			print()
+			print""
+			print""
 			print_with_line_numbers(code)
 		end;
 	}
--- a/website/src/manual.html.luan	Thu Jul 16 15:14:31 2015 -0600
+++ b/website/src/manual.html.luan	Tue Jul 21 14:56:41 2015 -0600
@@ -2710,6 +2710,12 @@
 
 
 
+<h4 heading><a name="Table.clear"><code>Table.clear (tbl)</code></a></h4>
+
+<p>
+Clears the table.
+
+
 <h4 heading><a name="Table.concat"><code>Table.concat (list [, sep [, i [, j]]])</code></a></h4>
 
 <p>