diff src/luan/modules/Luan.luan @ 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
line wrap: on
line diff
--- 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