Mercurial Hosting > luan
diff core/src/luan/LuanBit.java @ 404:d55e873e1f0d
metatables now only apply to tables
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 29 Apr 2015 07:04:40 -0600 |
parents | 2456ef7ada02 |
children | 91af5337b9ae |
line wrap: on
line diff
--- a/core/src/luan/LuanBit.java Tue Apr 28 22:49:33 2015 -0600 +++ b/core/src/luan/LuanBit.java Wed Apr 29 07:04:40 2015 -0600 @@ -88,34 +88,40 @@ } public String toString(Object obj) throws LuanException { - LuanFunction fn = getHandlerFunction("__tostring",obj); - if( fn != null ) - return checkString( Luan.first( call(fn,"__tostring",new Object[]{obj}) ) ); + if( obj instanceof LuanTable ) { + LuanFunction fn = getHandlerFunction("__tostring",(LuanTable)obj); + if( fn != null ) + return checkString( Luan.first( call(fn,"__tostring",new Object[]{obj}) ) ); + } return Luan.toString(obj); } public String repr(Object obj) throws LuanException { - LuanFunction fn = getHandlerFunction("__repr",obj); - if( fn != null ) - return checkString( Luan.first( call(fn,"__repr",new Object[]{obj}) ) ); + if( obj instanceof LuanTable ) { + LuanFunction fn = getHandlerFunction("__repr",(LuanTable)obj); + if( fn != null ) + return checkString( Luan.first( call(fn,"__repr",new Object[]{obj}) ) ); + } String repr = Luan.repr(obj); if( repr==null ) throw exception( "value '" + obj + "' doesn't support repr()" ); return repr; } - public LuanFunction getHandlerFunction(String op,Object obj) throws LuanException { - Object f = luan.getHandler(op,obj); + public LuanFunction getHandlerFunction(String op,LuanTable t) throws LuanException { + Object f = luan.getHandler(op,t); if( f == null ) return null; return checkFunction(f); } public LuanFunction getBinHandler(String op,Object o1,Object o2) throws LuanException { - LuanFunction f1 = getHandlerFunction(op,o1); - if( f1 != null ) - return f1; - return getHandlerFunction(op,o2); + if( o1 instanceof LuanTable ) { + LuanFunction f1 = getHandlerFunction(op,(LuanTable)o1); + if( f1 != null ) + return f1; + } + return o2 instanceof LuanTable ? getHandlerFunction(op,(LuanTable)o2) : null; } public boolean isLessThan(Object o1,Object o2) throws LuanException {