changeset 591:790d5de23042

add "strict" param to Io.repr(); add Lucene.index.ensure_open();
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 30 Aug 2015 11:37:39 -0600
parents f050c30952c0
children 1c64b1fd882b
files core/src/luan/modules/Io.luan lucene/src/luan/modules/lucene/Lucene.luan lucene/src/luan/modules/lucene/LuceneIndex.java
diffstat 3 files changed, 16 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
diff -r f050c30952c0 -r 790d5de23042 core/src/luan/modules/Io.luan
--- a/core/src/luan/modules/Io.luan	Thu Aug 27 08:35:03 2015 -0600
+++ b/core/src/luan/modules/Io.luan	Sun Aug 30 11:37:39 2015 -0600
@@ -72,10 +72,11 @@
 
 -- repr
 
-local function do_repr(obj,done)
+local function do_repr(obj,strict,done)
 	local tp = type(obj)
 	if tp == "table" then
 		if done[obj] == true then
+			strict and error "circular reference"
 			%><circular reference><%
 			return
 		end
@@ -85,7 +86,7 @@
 		local in_list = {}
 		for key, value in ipairs(obj) do
 			if is_first then is_first = false else %>, <% end
-			do_repr(value,done)
+			do_repr(value,strict,done)
 			in_list[key] = true
 		end
 		for key, value in pairs(obj) do
@@ -96,9 +97,9 @@
 				elseif type(key) == "table" then
 					%>[<<%=key%>>]<%
 				else
-					%>[<%do_repr(key,done)%>]<%
+					%>[<%do_repr(key,strict,done)%>]<%
 				end
-				%>=<% do_repr(value,done)
+				%>=<% do_repr(value,strict,done)
 			end
 		end
 		%>}<%
@@ -107,12 +108,13 @@
 	elseif tp == "nil" or tp == "boolean" or tp == "number" then
 		%><%=obj%><%
 	else
+		strict and error("can't repr type '"..tp.."' of "..obj)
 		%><<%=obj%>><%
 	end
 end
 
-function M.repr(obj)
-	return M.output_of(do_repr,obj,{})
+function M.repr(obj,strict)
+	return M.output_of(do_repr,obj,strict or false,{})
 end
 
 
diff -r f050c30952c0 -r 790d5de23042 lucene/src/luan/modules/lucene/Lucene.luan
--- a/lucene/src/luan/modules/lucene/Lucene.luan	Thu Aug 27 08:35:03 2015 -0600
+++ b/lucene/src/luan/modules/lucene/Lucene.luan	Sun Aug 30 11:37:39 2015 -0600
@@ -17,9 +17,10 @@
 
 M.literal = SaneQueryParser.literal
 
-function M.index(indexDir)
+function M.index(index_dir)
 	local index = {}
-	local java_index = LuceneIndex.new(indexDir)
+	index.dir = index_dir
+	local java_index = LuceneIndex.new(index_dir)
 	index.indexed_fields = java_index.indexedFieldsMeta.newTable()
 	index.to_string = java_index.to_string
 	index.backup = java_index.backup
@@ -30,6 +31,7 @@
 	index.save = java_index.save
 	index.update_in_transaction = java_index.update_in_transaction
 	index.close = java_index.close
+	index.ensure_open = java_index.ensure_open
 
 	function index.search(query, from, to, sort)
 		local results = {}
diff -r f050c30952c0 -r 790d5de23042 lucene/src/luan/modules/lucene/LuceneIndex.java
--- a/lucene/src/luan/modules/lucene/LuceneIndex.java	Thu Aug 27 08:35:03 2015 -0600
+++ b/lucene/src/luan/modules/lucene/LuceneIndex.java	Sun Aug 30 11:37:39 2015 -0600
@@ -299,6 +299,10 @@
 		searcher.getIndexReader().decRef();
 	}
 
+	public void ensure_open() throws IOException {
+		close(openSearcher());
+	}
+
 	public int advanced_search( final LuanState luan, String queryStr, LuanFunction fn, Integer n, String sortStr ) throws LuanException, IOException, ParseException {
 		Utils.checkNotNull(luan,queryStr);
 		Query query = SaneQueryParser.parseQuery(mfp,queryStr);