comparison core/src/luan/impl/$Luan.java @ 652:067d9470184d

compile SetStmt and ForStmt
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 04 Apr 2016 23:26:06 -0600
parents 140cc5191b7a
children
comparison
equal deleted inserted replaced
651:140cc5191b7a 652:067d9470184d
38 public static Stmt getStmt(int i) { 38 public static Stmt getStmt(int i) {
39 return listStmt.get(i); 39 return listStmt.get(i);
40 } 40 }
41 41
42 42
43 private static List<Settable> listSettable = new ArrayList<Settable>();
44
45 static int addSettable(Settable settable) {
46 int i = listSettable.size();
47 listSettable.add(settable);
48 return i;
49 }
50
51 public static Settable getSettable(int i) {
52 return listSettable.get(i);
53 }
54
55
43 public static Object first(Object obj) { 56 public static Object first(Object obj) {
44 return Luan.first(obj); 57 return Luan.first(obj);
45 } 58 }
46 59
47 public static int len(LuanState luan,Object o) throws LuanException { 60 public static int len(LuanState luan,Object o) throws LuanException {
72 throw new LuanException("attempt to perform arithmetic on a "+Luan.type(o)+" value"); 85 throw new LuanException("attempt to perform arithmetic on a "+Luan.type(o)+" value");
73 } 86 }
74 87
75 public static boolean checkBoolean(Object o) throws LuanException { 88 public static boolean checkBoolean(Object o) throws LuanException {
76 return Luan.checkBoolean(o); 89 return Luan.checkBoolean(o);
90 }
91
92 public static LuanFunction checkFunction(Object o) throws LuanException {
93 return Luan.checkFunction(o);
77 } 94 }
78 95
79 public static boolean not(Object o) throws LuanException { 96 public static boolean not(Object o) throws LuanException {
80 return !checkBoolean(o); 97 return !checkBoolean(o);
81 } 98 }
192 return !(o == null || Boolean.FALSE.equals(o)); 209 return !(o == null || Boolean.FALSE.equals(o));
193 } 210 }
194 211
195 public static void nop(Object o) {} 212 public static void nop(Object o) {}
196 213
214
215 public static void set(LuanStateImpl luan,Settable[] vars,Object obj) throws LuanException {
216 if( obj instanceof Object[] ) {
217 Object[] vals = (Object[])obj;
218 for( int i=0; i<vars.length; i++ ) {
219 Object val = i < vals.length ? vals[i] : null;
220 vars[i].set(luan,val);
221 }
222 } else {
223 vars[0].set(luan,obj);
224 for( int i=1; i<vars.length; i++ ) {
225 vars[i].set(luan,null);
226 }
227 }
228 }
229
197 } 230 }