Mercurial Hosting > luan
comparison src/luan/modules/TableLuan.java @ 1562:b89212fd04b5
remove table.luan
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 08 Nov 2020 16:50:59 -0700 |
parents | 225808b90cee |
children | 8fbcc4747091 |
comparison
equal
deleted
inserted
replaced
1561:e1a13e707bf3 | 1562:b89212fd04b5 |
---|---|
11 import luan.LuanRuntimeException; | 11 import luan.LuanRuntimeException; |
12 | 12 |
13 | 13 |
14 public final class TableLuan { | 14 public final class TableLuan { |
15 | 15 |
16 public static String concat(LuanTable list,String sep,Integer i,Integer j) throws LuanException { | 16 public static String concat(Luan luan,LuanTable list,String sep,Integer i,Integer j) throws LuanException { |
17 int first = i==null ? 1 : i; | 17 int first = i==null ? 1 : i; |
18 int last = j==null ? list.length() : j; | 18 int last = j==null ? list.length() : j; |
19 StringBuilder buf = new StringBuilder(); | 19 StringBuilder buf = new StringBuilder(); |
20 for( int k=first; k<=last; k++ ) { | 20 for( int k=first; k<=last; k++ ) { |
21 Object val = list.get(k); | 21 Object val = list.get(luan,k); |
22 if( val==null ) | 22 if( val==null ) |
23 break; | 23 break; |
24 if( sep!=null && k > first ) | 24 if( sep!=null && k > first ) |
25 buf.append(sep); | 25 buf.append(sep); |
26 String s = Luan.luanToString(val); | 26 String s = Luan.luanToString(val); |
80 } catch(LuanRuntimeException e) { | 80 } catch(LuanRuntimeException e) { |
81 throw (LuanException)e.getCause(); | 81 throw (LuanException)e.getCause(); |
82 } | 82 } |
83 } | 83 } |
84 | 84 |
85 public static LuanTable pack(Luan luan,Object... args) throws LuanException { | 85 public static LuanTable pack(Object... args) throws LuanException { |
86 LuanTable tbl = new LuanTable(luan,Arrays.asList(args)); | 86 LuanTable tbl = new LuanTable(Arrays.asList(args)); |
87 tbl.rawPut( "n", args.length ); | 87 tbl.rawPut( "n", args.length ); |
88 return tbl; | 88 return tbl; |
89 } | 89 } |
90 | 90 |
91 public static Object[] unpack(LuanTable tbl,Integer iFrom,Integer iTo) throws LuanException { | 91 public static Object[] unpack(Luan luan,LuanTable tbl,Integer iFrom,Integer iTo) throws LuanException { |
92 int from = iFrom!=null ? iFrom : 1; | 92 int from = iFrom!=null ? iFrom : 1; |
93 int to; | 93 int to; |
94 if( iTo != null ) { | 94 if( iTo != null ) { |
95 to = iTo; | 95 to = iTo; |
96 } else { | 96 } else { |
97 Integer n = Luan.asInteger( tbl.get("n") ); | 97 Integer n = Luan.asInteger( tbl.get(luan,"n") ); |
98 to = n!=null ? n : tbl.length(); | 98 to = n!=null ? n : tbl.length(); |
99 } | 99 } |
100 List<Object> list = new ArrayList<Object>(); | 100 List<Object> list = new ArrayList<Object>(); |
101 for( int i=from; i<=to; i++ ) { | 101 for( int i=from; i<=to; i++ ) { |
102 list.add( tbl.get(i) ); | 102 list.add( tbl.get(luan,i) ); |
103 } | 103 } |
104 return list.toArray(); | 104 return list.toArray(); |
105 } | 105 } |
106 | 106 |
107 public static LuanTable copy(LuanTable list,Integer from,Integer to) { | 107 public static LuanTable copy(LuanTable list,Integer from,Integer to) { |