Mercurial Hosting > luan
diff src/luan/modules/ThreadLuan.java @ 1267:9fa8b8389578
add LuanTable.luan;
support metatable __gc();
add luan.sql;
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 12 Nov 2018 02:10:41 -0700 |
parents | 3ffc7c4a3b85 |
children | a9cc35c71eb0 |
line wrap: on
line diff
--- a/src/luan/modules/ThreadLuan.java Sun Sep 30 19:10:48 2018 -0600 +++ b/src/luan/modules/ThreadLuan.java Mon Nov 12 02:10:41 2018 -0700 @@ -125,17 +125,17 @@ } } - private static Object makeSafe(Object v) { + private static Object makeSafe(LuanState luan,Object v) { if( v instanceof LuanTable ) { LuanTable tbl = (LuanTable)v; if( tbl.getMetatable() != null ) return new Unsafe("table with metatable"); - LuanTable rtn = new LuanTable(); + LuanTable rtn = new LuanTable(luan); for( Map.Entry entry : tbl.rawIterable() ) { - Object key = makeSafe( entry.getKey() ); + Object key = makeSafe( luan, entry.getKey() ); if( key instanceof Unsafe ) return key; - Object value = makeSafe( entry.getValue() ); + Object value = makeSafe( luan, entry.getValue() ); if( value instanceof Unsafe ) return value; rtn.rawPut(key,value); @@ -144,7 +144,7 @@ } else if( v instanceof Object[] ) { Object[] a = (Object[])v; for( int i=0; i<a.length; i++ ) { - Object obj = makeSafe(a[i]); + Object obj = makeSafe(luan,a[i]); if( obj instanceof Unsafe ) return obj; a[i] = obj; @@ -167,19 +167,19 @@ this.fns = (LuanTable)cloner.get(fns); } - public synchronized Object call(String fnName,Object... args) throws LuanException { - Object obj = makeSafe(args); + public synchronized Object call(LuanState callerLuan,String fnName,Object... args) throws LuanException { + Object obj = makeSafe(luan,args); if( obj instanceof Unsafe ) throw new LuanException("can't pass "+((Unsafe)obj).reason+" to global_callable "+Arrays.asList(args)); args = (Object[])obj; - Object f = fns.get(luan,fnName); + Object f = fns.get(fnName); if( f == null ) throw new LuanException("function '"+fnName+"' not found in global_callable"); if( !(f instanceof LuanFunction) ) throw new LuanException("value of '"+fnName+"' not a function in global_callable"); LuanFunction fn = (LuanFunction)f; Object rtn = fn.call(luan,args); - rtn = makeSafe(rtn); + rtn = makeSafe(callerLuan,rtn); if( rtn instanceof Unsafe ) throw new LuanException("can't return "+((Unsafe)rtn).reason+" from global_callable"); return rtn;