Mercurial Hosting > luan
comparison core/src/luan/modules/BasicLuan.java @ 426:23a93c118042
fix LuanTable.get() to use metatables
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Fri, 01 May 2015 18:44:20 -0600 |
parents | 1eafb11a150d |
children | dae264ad6a7b |
comparison
equal
deleted
inserted
replaced
425:0a2fb80907f9 | 426:23a93c118042 |
---|---|
104 public static boolean raw_equal(Object v1,Object v2) { | 104 public static boolean raw_equal(Object v1,Object v2) { |
105 return v1 == v2 || v1 != null && v1.equals(v2); | 105 return v1 == v2 || v1 != null && v1.equals(v2); |
106 } | 106 } |
107 | 107 |
108 public static Object raw_get(LuanTable table,Object index) { | 108 public static Object raw_get(LuanTable table,Object index) { |
109 return table.get(index); | 109 return table.rawGet(index); |
110 } | 110 } |
111 | 111 |
112 public static LuanTable raw_set(LuanTable table,Object index,Object value) { | 112 public static LuanTable raw_set(LuanTable table,Object index,Object value) { |
113 table.put(index,value); | 113 table.put(index,value); |
114 return table; | 114 return table; |
216 return obj instanceof LuanFunction ? (LuanFunction)obj : null; | 216 return obj instanceof LuanFunction ? (LuanFunction)obj : null; |
217 } | 217 } |
218 | 218 |
219 public static Object try_(LuanState luan,LuanTable blocks) throws LuanException { | 219 public static Object try_(LuanState luan,LuanTable blocks) throws LuanException { |
220 Utils.checkNotNull(luan,blocks); | 220 Utils.checkNotNull(luan,blocks); |
221 Object obj = blocks.get(1); | 221 Object obj = blocks.get(luan,1); |
222 if( obj == null ) | 222 if( obj == null ) |
223 throw luan.exception("missing 'try' value"); | 223 throw luan.exception("missing 'try' value"); |
224 if( !(obj instanceof LuanFunction) ) | 224 if( !(obj instanceof LuanFunction) ) |
225 throw luan.exception("bad 'try' value (function expected, got "+Luan.type(obj)+")"); | 225 throw luan.exception("bad 'try' value (function expected, got "+Luan.type(obj)+")"); |
226 LuanFunction tryFn = (LuanFunction)obj; | 226 LuanFunction tryFn = (LuanFunction)obj; |
227 LuanFunction catchFn = null; | 227 LuanFunction catchFn = null; |
228 obj = blocks.get("catch"); | 228 obj = blocks.get(luan,"catch"); |
229 if( obj != null ) { | 229 if( obj != null ) { |
230 if( !(obj instanceof LuanFunction) ) | 230 if( !(obj instanceof LuanFunction) ) |
231 throw luan.exception("bad 'catch' value (function expected, got "+Luan.type(obj)+")"); | 231 throw luan.exception("bad 'catch' value (function expected, got "+Luan.type(obj)+")"); |
232 catchFn = (LuanFunction)obj; | 232 catchFn = (LuanFunction)obj; |
233 } | 233 } |
234 LuanFunction finallyFn = null; | 234 LuanFunction finallyFn = null; |
235 obj = blocks.get("finally"); | 235 obj = blocks.get(luan,"finally"); |
236 if( obj != null ) { | 236 if( obj != null ) { |
237 if( !(obj instanceof LuanFunction) ) | 237 if( !(obj instanceof LuanFunction) ) |
238 throw luan.exception("bad 'finally' value (function expected, got "+Luan.type(obj)+")"); | 238 throw luan.exception("bad 'finally' value (function expected, got "+Luan.type(obj)+")"); |
239 finallyFn = (LuanFunction)obj; | 239 finallyFn = (LuanFunction)obj; |
240 } | 240 } |