changeset 1261:198d6af7330a

rename Luan.to_table to Table.java_to_table_shallow and Luan.to_luan to Table.java_to_table_deep
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 24 Sep 2018 13:09:16 -0600
parents 4b5b84853f6f
children 81d3a01fbd09
files src/luan/modules/Luan.luan src/luan/modules/Parsers.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 6 files changed, 52 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/src/luan/modules/Luan.luan	Sun Sep 23 22:32:34 2018 -0600
+++ b/src/luan/modules/Luan.luan	Mon Sep 24 13:09:16 2018 -0600
@@ -1,6 +1,5 @@
 java()
 local BasicLuan = require "java:luan.modules.BasicLuan"
-local LuanJava = require "java:luan.Luan"
 
 local Luan = {}
 
@@ -38,30 +37,4 @@
 	return Luan.load( "return "..s, source_name or "eval" )()
 end
 
-
-local error = Luan.error
-local type = Luan.type or error()
-local pairs = Luan.pairs or error()
-
-Luan.to_table = LuanJava.toTable
-
-local function to_luan(obj,to_table)
-	if type(obj) ~= "java" 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 = 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
--- a/src/luan/modules/Parsers.luan	Sun Sep 23 22:32:34 2018 -0600
+++ b/src/luan/modules/Parsers.luan	Mon Sep 24 13:09:16 2018 -0600
@@ -12,13 +12,18 @@
 Parsers.theme_to_luan = Theme.toLuan
 
 local Luan = require "luan:Luan.luan"
+local error = Luan.error
+local type = Luan.type or error()
+local Table = require "luan:Table.luan"
+local java_to_table_deep = Table.java_to_table_deep or error()
 local LuanJava = require "java:luan.Luan"
 local JsonParser = require "java:luan.lib.json.JsonParser"
 local JsonToString = require "java:luan.lib.json.JsonToString"
 
 -- converts json string to luan object
 function Parsers.json_parse(s)
-	return Luan.to_luan(JsonParser.parse(s))
+	local obj = JsonParser.parse(s)
+	return type(obj)=="java" and java_to_table_deep(obj) or obj
 end
 
 -- converts luan object to json string
--- a/src/luan/modules/Rpc.luan	Sun Sep 23 22:32:34 2018 -0600
+++ b/src/luan/modules/Rpc.luan	Mon Sep 24 13:09:16 2018 -0600
@@ -19,10 +19,10 @@
 local try = Luan.try or error()
 local ipairs = Luan.ipairs or error()
 local type = Luan.type or error()
-local to_luan = Luan.to_luan or error()
 local Io = require "luan:Io.luan"
 local Thread = require "luan:Thread.luan"
 local Table = require "luan:Table.luan"
+local java_to_table_deep = Table.java_to_table_deep or error()
 local unpack = Table.unpack or error()
 local Logging = require "luan:logging/Logging.luan"
 local logger = Logging.logger "Rpc"
@@ -54,7 +54,7 @@
 end
 
 local function luan_args(list,binary_in)
-	list = to_luan(list)
+	list = java_to_table_deep(list)
 	if binary_in ~= nil then
 		local i_in = list[#list]
 		list[#list] = nil
--- a/src/luan/modules/Table.luan	Sun Sep 23 22:32:34 2018 -0600
+++ b/src/luan/modules/Table.luan	Mon Sep 24 13:09:16 2018 -0600
@@ -15,4 +15,38 @@
 Table.sort = TableLuan.sort
 Table.unpack = TableLuan.unpack
 
+
+local Luan = require "luan:Luan.luan"
+local error = Luan.error
+local type = Luan.type or error()
+local pairs = Luan.pairs or error()
+local LuanJava = require "java:luan.Luan"
+local toTable = LuanJava.toTable or error()
+
+function Table.java_to_table_shallow(obj)
+	return toTable(obj) or error("can't convert type "..obj.getClass().getName().." to table")
+end
+
+local to_luan, deepen
+
+function to_luan(obj,java_to_table_shallow)
+	return type(obj)=="java" and deepen(java_to_table_shallow(obj),java_to_table_shallow) or obj
+end
+
+function deepen(tbl,java_to_table_shallow)
+	local rtn = {}
+	for key, value in pairs(tbl) do
+		key = to_luan(key,java_to_table_shallow)
+		value = to_luan(value,java_to_table_shallow)
+		rtn[key] = value
+	end
+	return rtn
+end
+
+function Table.java_to_table_deep(obj,java_to_table_shallow)
+	java_to_table_shallow = java_to_table_shallow or Table.java_to_table_shallow
+	return deepen(java_to_table_shallow(obj),java_to_table_shallow)
+end
+
+
 return Table
--- a/src/luan/modules/http/Http.luan	Sun Sep 23 22:32:34 2018 -0600
+++ b/src/luan/modules/http/Http.luan	Mon Sep 24 13:09:16 2018 -0600
@@ -4,11 +4,11 @@
 local ipairs = Luan.ipairs or error()
 local pairs = Luan.pairs or error()
 local type = Luan.type or error()
-local to_luan = Luan.to_luan or error()
 local Io = require "luan:Io.luan"
 local Html = require "luan:Html.luan"
 local Table = require "luan:Table.luan"
 local clear = Table.clear or error()
+local java_to_table_deep = Table.java_to_table_deep or error()
 local Package = require "luan:Package.luan"
 local String = require "luan:String.luan"
 local lower = String.lower or error()
@@ -25,9 +25,9 @@
 
 local Http = {}
 
-local old_to_table = Luan.to_table or error()
+local old_java_to_table_shallow = Table.java_to_table_shallow or error()
 
-local function to_table(obj)
+local function java_to_table_shallow(obj)
 	if type(obj)=="java" and obj.instanceof(Request.MultipartFile) then
 		return {
 			filename = obj.filename
@@ -35,7 +35,7 @@
 			content = obj.content
 		}
 	end
-	return old_to_table(obj)
+	return old_java_to_table_shallow(obj)
 end
 
 function Http.new_request(java)
@@ -55,9 +55,9 @@
 		this.path = java.path or error()
 		this.protocol = java.protocol or error()
 		this.scheme = java.scheme or error()
-		this.headers = to_luan(java.headers)
-		this.parameters = to_luan(java.parameters,to_table)
-		this.cookies = to_luan(java.cookies)
+		this.headers = java_to_table_deep(java.headers)
+		this.parameters = java_to_table_deep(java.parameters,java_to_table_shallow)
+		this.cookies = java_to_table_deep(java.cookies)
 	end
 
 	function this.url()
--- a/src/luan/modules/http/tools/Luan_threads.luan	Sun Sep 23 22:32:34 2018 -0600
+++ b/src/luan/modules/http/tools/Luan_threads.luan	Mon Sep 24 13:09:16 2018 -0600
@@ -1,5 +1,7 @@
 local Luan = require "luan:Luan.luan"
 local error = Luan.error
+local Table = require "luan:Table.luan"
+local java_to_table_shallow = Table.java_to_table_shallow or error()
 local Io = require "luan:Io.luan"
 local Time = require "luan:Time.luan"
 local Http = require "luan:http/Http.luan"
@@ -31,7 +33,7 @@
 		<%
 		local count = 0
 		for _, thread in Luan.ipairs(threads) do
-			local luan_trace = Luan.to_table(LuanException.justLuan(thread.trace)) or error()
+			local luan_trace = java_to_table_shallow(LuanException.justLuan(thread.trace))
 			if #luan_trace > 0 then
 				%>
 				<p><%=thread.string%> <%=thread.state%>