comparison core/src/luan/modules/StringLuan.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
13 13
14 14
15 public final class StringLuan { 15 public final class StringLuan {
16 16
17 public static Object __index(LuanState luan,final String s,Object key) throws LuanException { 17 public static Object __index(LuanState luan,final String s,Object key) throws LuanException {
18 LuanTable mod = (LuanTable)PackageLuan.loaded(luan).get("luan:String"); 18 LuanTable mod = (LuanTable)luan.require("luan:String");
19 if( mod!=null ) { 19 Object obj = mod.get(key);
20 Object obj = mod.get(key); 20 if( obj instanceof LuanFunction ) {
21 if( obj instanceof LuanFunction ) { 21 final LuanFunction fn = (LuanFunction)obj;
22 final LuanFunction fn = (LuanFunction)obj; 22 return new LuanFunction() {
23 return new LuanFunction() { 23 @Override public Object call(LuanState luan,Object[] args) throws LuanException {
24 @Override public Object call(LuanState luan,Object[] args) throws LuanException { 24 Object[] a = new Object[args.length+1];
25 Object[] a = new Object[args.length+1]; 25 a[0] = s;
26 a[0] = s; 26 System.arraycopy(args,0,a,1,args.length);
27 System.arraycopy(args,0,a,1,args.length); 27 return fn.call(luan,a);
28 return fn.call(luan,a); 28 }
29 } 29 };
30 };
31 }
32 } 30 }
33 return null; 31 return null;
34 } 32 }
35 33
36 static int start(String s,int i) { 34 static int start(String s,int i) {