changeset 1464:465b4a0dae4a

empty list vs map
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 03 Apr 2020 10:04:52 -0600
parents fb003c4003dd
children 5e3870618377
files src/luan/Luan.java src/luan/LuanTable.java src/luan/impl/LuanImpl.java src/luan/modules/Table.luan
diffstat 4 files changed, 15 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
diff -r fb003c4003dd -r 465b4a0dae4a src/luan/Luan.java
--- a/src/luan/Luan.java	Mon Mar 30 18:31:18 2020 -0600
+++ b/src/luan/Luan.java	Fri Apr 03 10:04:52 2020 -0600
@@ -322,7 +322,7 @@
 		if( !(obj instanceof LuanTable) )
 			return obj;
 		LuanTable tbl = (LuanTable)obj;
-		if( tbl.isList() ) {
+		if( !tbl.isMap() ) {
 			List list = new ArrayList();
 			for( Object el : tbl.asList() ) {
 				list.add( toJava(el) );
diff -r fb003c4003dd -r 465b4a0dae4a src/luan/LuanTable.java
--- a/src/luan/LuanTable.java	Mon Mar 30 18:31:18 2020 -0600
+++ b/src/luan/LuanTable.java	Fri Apr 03 10:04:52 2020 -0600
@@ -28,6 +28,7 @@
 
 	public LuanTable(Luan luan,List list){
 		this.luan = luan;
+		list();
 		int n = list.size();
 		for( int i=0; i<n; i++ ) {
 			Object val = list.get(i);
@@ -123,6 +124,10 @@
 		return map==null || map.isEmpty();
 	}
 
+	boolean isMap() {
+		return map!=null || list==null;
+	}
+
 	public List<Object> asList() {
 		check();
 		return list!=null ? list : Collections.emptyList();
@@ -550,4 +555,8 @@
 	public static void setSecurity(LuanTable tbl,String security) {
 		tbl.security = security;
 	}
+
+	public static void debug(LuanTable table) {
+		System.out.println("isMap "+table.isMap());
+	}
 }
diff -r fb003c4003dd -r 465b4a0dae4a src/luan/impl/LuanImpl.java
--- a/src/luan/impl/LuanImpl.java	Mon Mar 30 18:31:18 2020 -0600
+++ b/src/luan/impl/LuanImpl.java	Fri Apr 03 10:04:52 2020 -0600
@@ -240,8 +240,7 @@
 					table.rawPut(key,value);
 			} else {
 				i++;
-				if( fld != null )
-					table.rawPut(i,fld);
+				table.rawPut(i,fld);
 			}
 		}
 		return table;
diff -r fb003c4003dd -r 465b4a0dae4a src/luan/modules/Table.luan
--- a/src/luan/modules/Table.luan	Mon Mar 30 18:31:18 2020 -0600
+++ b/src/luan/modules/Table.luan	Fri Apr 03 10:04:52 2020 -0600
@@ -21,6 +21,7 @@
 local type = Luan.type or error()
 local pairs = Luan.pairs or error()
 local toTable = TableLuan.toTable or error()
+local copy = Table.copy or error()
 
 function Table.java_to_table_shallow(obj)
 	local rtn = toTable(obj)
@@ -41,13 +42,12 @@
 end
 
 function deepen(tbl,java_to_table_shallow)
-	local rtn = {}
-	for key, value in pairs(tbl) do
+	for key, value in pairs(copy(tbl)) do
 		key = to_luan(key,java_to_table_shallow)
 		value = to_luan(value,java_to_table_shallow)
-		rtn[key] = value
+		tbl[key] = value
 	end
-	return rtn
+	return tbl
 end
 
 function Table.java_to_table_deep(obj,java_to_table_shallow)