Mercurial Hosting > luan
diff core/src/luan/modules/TableLuan.java @ 221:ec016471c6eb
make LuanTable an interface
git-svn-id: https://luan-java.googlecode.com/svn/trunk@222 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Thu, 17 Jul 2014 07:49:26 +0000 |
parents | 3dcb0f9bee82 |
children | b76fcb72d97d |
line wrap: on
line diff
--- a/core/src/luan/modules/TableLuan.java Wed Jul 16 04:59:45 2014 +0000 +++ b/core/src/luan/modules/TableLuan.java Thu Jul 17 07:49:26 2014 +0000 @@ -18,7 +18,7 @@ public static final LuanFunction LOADER = new LuanFunction() { @Override public Object call(LuanState luan,Object[] args) { - LuanTable module = new LuanTable(); + LuanTable module = Luan.newTable(); try { add( module, "concat", LuanState.class, LuanTable.class, String.class, Integer.class, Integer.class ); add( module, "insert", LuanState.class, LuanTable.class, Integer.TYPE, Object.class ); @@ -111,7 +111,20 @@ } public static LuanTable pack(Object... args) { - return new LuanTable(new ArrayList<Object>(Arrays.asList(args))); + LuanTable tbl = Luan.newTable(); + boolean hasNull = false; + for( int i=0; i<args.length; i++ ) { + Object v = args[i]; + if( v==null ) { + hasNull = true; + } else if( !hasNull ) { + tbl.add(v); + } else { + tbl.put(i+1,v); + } + } + tbl.put( "n", args.length ); + return tbl; } public static Object[] unpack(LuanTable tbl,Integer iFrom,Integer iTo) {