comparison core/src/luan/impl/LenExpr.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 3dcb0f9bee82
children d9df6d6cb927
comparison
equal deleted inserted replaced
403:637f7ad85654 404:d55e873e1f0d
23 if( o instanceof byte[] ) { 23 if( o instanceof byte[] ) {
24 byte[] a = (byte[])o; 24 byte[] a = (byte[])o;
25 return a.length; 25 return a.length;
26 } 26 }
27 LuanBit bit = luan.bit(se); 27 LuanBit bit = luan.bit(se);
28 LuanFunction fn = bit.getHandlerFunction("__len",o); 28 if( !(o instanceof LuanTable) )
29 throw bit.exception( "attempt to get length of a " + Luan.type(o) + " value" );
30 LuanTable t = (LuanTable)o;
31 LuanFunction fn = bit.getHandlerFunction("__len",t);
29 if( fn != null ) 32 if( fn != null )
30 return Luan.first(bit.call(fn,"__len",new Object[]{o})); 33 return Luan.first(bit.call(fn,"__len",new Object[]{o}));
31 if( o instanceof LuanTable ) { 34 return t.length();
32 LuanTable t = (LuanTable)o;
33 return t.length();
34 }
35 throw bit.exception( "attempt to get length of a " + Luan.type(o) + " value" );
36 } 35 }
37 } 36 }