comparison core/src/luan/modules/BasicLuan.java @ 572:f1601a4ce1aa

fix stack when calling meta-methods
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 12 Jul 2015 21:34:23 -0600
parents 5fed3de0aac7
children 6cc2f047019b
comparison
equal deleted inserted replaced
571:cd944b010f25 572:f1601a4ce1aa
43 return load(luan,src,fileName,null,false); 43 return load(luan,src,fileName,null,false);
44 } 44 }
45 45
46 public static LuanFunction pairs(final LuanState luan,final LuanTable t) throws LuanException { 46 public static LuanFunction pairs(final LuanState luan,final LuanTable t) throws LuanException {
47 Utils.checkNotNull(luan,t); 47 Utils.checkNotNull(luan,t);
48 return t.pairs(luan); 48 return t.pairs(luan.JAVA);
49 } 49 }
50 50
51 public static LuanFunction ipairs(LuanState luan,final LuanTable t) throws LuanException { 51 public static LuanFunction ipairs(LuanState luan,final LuanTable t) throws LuanException {
52 Utils.checkNotNull(luan,t); 52 Utils.checkNotNull(luan,t);
53 return new LuanFunction() { 53 return new LuanFunction() {
103 } 103 }
104 throw luan.exception( "bad argument #1 to 'raw_len' (table or string expected)" ); 104 throw luan.exception( "bad argument #1 to 'raw_len' (table or string expected)" );
105 } 105 }
106 106
107 public static String to_string(LuanState luan,Object v) throws LuanException { 107 public static String to_string(LuanState luan,Object v) throws LuanException {
108 return luan.toString(v); 108 return luan.JAVA.toString(v);
109 } 109 }
110 110
111 public static LuanTable new_error(LuanState luan,Object msg) throws LuanException { 111 public static LuanTable new_error(LuanState luan,Object msg) throws LuanException {
112 return luan.exception(msg).table(); 112 return luan.exception(msg).table();
113 } 113 }
181 return obj instanceof LuanFunction ? (LuanFunction)obj : null; 181 return obj instanceof LuanFunction ? (LuanFunction)obj : null;
182 } 182 }
183 183
184 public static Object try_(LuanState luan,LuanTable blocks) throws LuanException { 184 public static Object try_(LuanState luan,LuanTable blocks) throws LuanException {
185 Utils.checkNotNull(luan,blocks); 185 Utils.checkNotNull(luan,blocks);
186 Object obj = blocks.get(luan,1); 186 Object obj = blocks.get(luan.JAVA,1);
187 if( obj == null ) 187 if( obj == null )
188 throw luan.exception("missing 'try' value"); 188 throw luan.exception("missing 'try' value");
189 if( !(obj instanceof LuanFunction) ) 189 if( !(obj instanceof LuanFunction) )
190 throw luan.exception("bad 'try' value (function expected, got "+Luan.type(obj)+")"); 190 throw luan.exception("bad 'try' value (function expected, got "+Luan.type(obj)+")");
191 LuanFunction tryFn = (LuanFunction)obj; 191 LuanFunction tryFn = (LuanFunction)obj;
192 LuanFunction catchFn = null; 192 LuanFunction catchFn = null;
193 obj = blocks.get(luan,"catch"); 193 obj = blocks.get(luan.JAVA,"catch");
194 if( obj != null ) { 194 if( obj != null ) {
195 if( !(obj instanceof LuanFunction) ) 195 if( !(obj instanceof LuanFunction) )
196 throw luan.exception("bad 'catch' value (function expected, got "+Luan.type(obj)+")"); 196 throw luan.exception("bad 'catch' value (function expected, got "+Luan.type(obj)+")");
197 catchFn = (LuanFunction)obj; 197 catchFn = (LuanFunction)obj;
198 } 198 }
199 LuanFunction finallyFn = null; 199 LuanFunction finallyFn = null;
200 obj = blocks.get(luan,"finally"); 200 obj = blocks.get(luan.JAVA,"finally");
201 if( obj != null ) { 201 if( obj != null ) {
202 if( !(obj instanceof LuanFunction) ) 202 if( !(obj instanceof LuanFunction) )
203 throw luan.exception("bad 'finally' value (function expected, got "+Luan.type(obj)+")"); 203 throw luan.exception("bad 'finally' value (function expected, got "+Luan.type(obj)+")");
204 finallyFn = (LuanFunction)obj; 204 finallyFn = (LuanFunction)obj;
205 } 205 }