comparison core/src/luan/modules/BinaryLuan.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 cbb94a7c7a9e
children abce9b0041b0
comparison
equal deleted inserted replaced
403:637f7ad85654 404:d55e873e1f0d
9 9
10 10
11 public final class BinaryLuan { 11 public final class BinaryLuan {
12 12
13 public static Object __index(LuanState luan,final byte[] binary,Object key) throws LuanException { 13 public static Object __index(LuanState luan,final byte[] binary,Object key) throws LuanException {
14 LuanTable mod = (LuanTable)PackageLuan.loaded(luan).get("luan:Binary"); 14 LuanTable mod = (LuanTable)luan.require("luan:Binary");
15 if( mod!=null ) { 15 Object obj = mod.get(key);
16 Object obj = mod.get(key); 16 if( obj instanceof LuanFunction ) {
17 if( obj instanceof LuanFunction ) { 17 final LuanFunction fn = (LuanFunction)obj;
18 final LuanFunction fn = (LuanFunction)obj; 18 return new LuanFunction() {
19 return new LuanFunction() { 19 @Override public Object call(LuanState luan,Object[] args) throws LuanException {
20 @Override public Object call(LuanState luan,Object[] args) throws LuanException { 20 Object[] a = new Object[args.length+1];
21 Object[] a = new Object[args.length+1]; 21 a[0] = binary;
22 a[0] = binary; 22 System.arraycopy(args,0,a,1,args.length);
23 System.arraycopy(args,0,a,1,args.length); 23 return fn.call(luan,a);
24 return fn.call(luan,a); 24 }
25 } 25 };
26 };
27 }
28 } 26 }
29 return null; 27 return null;
30 } 28 }
31 29
32 static int start(byte[] binary,int i) { 30 static int start(byte[] binary,int i) {