changeset 1260:4b5b84853f6f

replace Table.as_table with Luan.to_table
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 23 Sep 2018 22:32:34 -0600
parents e8020216dee7
children 198d6af7330a
files conv.txt src/luan/Luan.java src/luan/modules/Luan.luan src/luan/modules/Rpc.luan src/luan/modules/Table.luan src/luan/modules/http/Http.luan src/luan/modules/http/tools/Luan_threads.luan
diffstat 7 files changed, 20 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
diff -r e8020216dee7 -r 4b5b84853f6f conv.txt
--- a/conv.txt	Sun Sep 23 17:58:40 2018 -0600
+++ b/conv.txt	Sun Sep 23 22:32:34 2018 -0600
@@ -1,3 +1,5 @@
+remove "as_table"
+
 "Thread.schedule"
 
 "Thread.safe"
diff -r e8020216dee7 -r 4b5b84853f6f src/luan/Luan.java
--- a/src/luan/Luan.java	Sun Sep 23 17:58:40 2018 -0600
+++ b/src/luan/Luan.java	Sun Sep 23 22:32:34 2018 -0600
@@ -196,12 +196,12 @@
 			return map;
 		}
 	}
-
+/*
 	public static LuanTable table(LuanTable v) throws LuanException {
 		Utils.checkNotNull(v);
 		return v;
 	}
-
+*/
 	public static LuanTable toTable(Object obj) {
 		if( obj == null )
 			return null;
diff -r e8020216dee7 -r 4b5b84853f6f src/luan/modules/Luan.luan
--- a/src/luan/modules/Luan.luan	Sun Sep 23 17:58:40 2018 -0600
+++ b/src/luan/modules/Luan.luan	Sun Sep 23 22:32:34 2018 -0600
@@ -43,28 +43,25 @@
 local type = Luan.type or error()
 local pairs = Luan.pairs or error()
 
--- tries to convert to luan
-function Luan.java_to_luan(obj)
-	return LuanJava.toTable(obj) or obj
-end
+Luan.to_table = LuanJava.toTable
 
-function Luan.to_luan(obj,java_to_luan)
+local function to_luan(obj,to_table)
 	if type(obj) ~= "java" then
 		return obj
 	end
-	java_to_luan = java_to_luan or Luan.java_to_luan
-	obj = java_to_luan(obj)
-	type(obj) ~= "java" or error("can't convert type "..obj.getClass().getName().." to luan")
-	if type(obj) ~= "table" then
-		return obj
-	end
+	obj = to_table(obj) or error("can't convert type "..obj.getClass().getName().." to luan")
 	local tbl = {}
 	for key, value in pairs(obj) do
-		key = Luan.to_luan(key,java_to_luan)
-		value = Luan.to_luan(value,java_to_luan)
+		key = to_luan(key,to_table)
+		value = to_luan(value,to_table)
 		tbl[key] = value
 	end
 	return tbl
 end
 
+function Luan.to_luan(obj,to_table)
+	to_table = to_table or Luan.to_table
+	return to_luan(obj,to_table)
+end
+
 return Luan
diff -r e8020216dee7 -r 4b5b84853f6f src/luan/modules/Rpc.luan
--- a/src/luan/modules/Rpc.luan	Sun Sep 23 17:58:40 2018 -0600
+++ b/src/luan/modules/Rpc.luan	Sun Sep 23 22:32:34 2018 -0600
@@ -54,10 +54,7 @@
 end
 
 local function luan_args(list,binary_in)
-	list = LuanJava.table(list)
-	for i,v in ipairs(list) do
-		list[i] = to_luan(v)
-	end
+	list = to_luan(list)
 	if binary_in ~= nil then
 		local i_in = list[#list]
 		list[#list] = nil
diff -r e8020216dee7 -r 4b5b84853f6f src/luan/modules/Table.luan
--- a/src/luan/modules/Table.luan	Sun Sep 23 17:58:40 2018 -0600
+++ b/src/luan/modules/Table.luan	Sun Sep 23 22:32:34 2018 -0600
@@ -1,10 +1,8 @@
 java()
 local TableLuan = require "java:luan.modules.TableLuan"
-local LuanJava = require "java:luan.Luan"
 
 local Table = {}
 
-Table.as_table = LuanJava.table
 Table.clear = TableLuan.clear
 Table.concat = TableLuan.concat
 Table.copy = TableLuan.copy
diff -r e8020216dee7 -r 4b5b84853f6f src/luan/modules/http/Http.luan
--- a/src/luan/modules/http/Http.luan	Sun Sep 23 17:58:40 2018 -0600
+++ b/src/luan/modules/http/Http.luan	Sun Sep 23 22:32:34 2018 -0600
@@ -25,10 +25,9 @@
 
 local Http = {}
 
-local old_java_to_luan = Luan.java_to_luan or error()
+local old_to_table = Luan.to_table or error()
 
-local function java_to_luan(obj)
-	obj = old_java_to_luan(obj)
+local function to_table(obj)
 	if type(obj)=="java" and obj.instanceof(Request.MultipartFile) then
 		return {
 			filename = obj.filename
@@ -36,7 +35,7 @@
 			content = obj.content
 		}
 	end
-	return obj
+	return old_to_table(obj)
 end
 
 function Http.new_request(java)
@@ -57,7 +56,7 @@
 		this.protocol = java.protocol or error()
 		this.scheme = java.scheme or error()
 		this.headers = to_luan(java.headers)
-		this.parameters = to_luan(java.parameters,java_to_luan)
+		this.parameters = to_luan(java.parameters,to_table)
 		this.cookies = to_luan(java.cookies)
 	end
 
diff -r e8020216dee7 -r 4b5b84853f6f src/luan/modules/http/tools/Luan_threads.luan
--- a/src/luan/modules/http/tools/Luan_threads.luan	Sun Sep 23 17:58:40 2018 -0600
+++ b/src/luan/modules/http/tools/Luan_threads.luan	Sun Sep 23 22:32:34 2018 -0600
@@ -6,7 +6,6 @@
 java()
 local Thread = require "java:java.lang.Thread"
 local LuanException = require "java:luan.LuanException"
-local JavaLuan = require "java:luan.Luan"
 
 
 local Luan_threads = {}
@@ -32,7 +31,7 @@
 		<%
 		local count = 0
 		for _, thread in Luan.ipairs(threads) do
-			local luan_trace = JavaLuan.table(LuanException.justLuan(thread.trace))
+			local luan_trace = Luan.to_table(LuanException.justLuan(thread.trace)) or error()
 			if #luan_trace > 0 then
 				%>
 				<p><%=thread.string%> <%=thread.state%>