Mercurial Hosting > luan
comparison src/luan/modules/ThreadLuan.java @ 1562:b89212fd04b5
remove table.luan
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 08 Nov 2020 16:50:59 -0700 |
parents | 78d937870762 |
children | 8fbcc4747091 |
comparison
equal
deleted
inserted
replaced
1561:e1a13e707bf3 | 1562:b89212fd04b5 |
---|---|
155 Unsafe(String reason) { | 155 Unsafe(String reason) { |
156 this.reason = reason; | 156 this.reason = reason; |
157 } | 157 } |
158 } | 158 } |
159 | 159 |
160 private static Object makeSafe(Luan luan,Object v) throws LuanException { | 160 private static Object makeSafe(Object v) throws LuanException { |
161 if( v instanceof LuanTable ) { | 161 if( v instanceof LuanTable ) { |
162 LuanTable tbl = (LuanTable)v; | 162 LuanTable tbl = (LuanTable)v; |
163 if( tbl.getMetatable() != null ) | 163 if( tbl.getMetatable() != null ) |
164 return new Unsafe("table with metatable"); | 164 return new Unsafe("table with metatable"); |
165 LuanTable rtn = new LuanTable(luan); | 165 LuanTable rtn = new LuanTable(); |
166 for( Map.Entry entry : tbl.rawIterable() ) { | 166 for( Map.Entry entry : tbl.rawIterable() ) { |
167 Object key = makeSafe( luan, entry.getKey() ); | 167 Object key = makeSafe( entry.getKey() ); |
168 if( key instanceof Unsafe ) | 168 if( key instanceof Unsafe ) |
169 return key; | 169 return key; |
170 Object value = makeSafe( luan, entry.getValue() ); | 170 Object value = makeSafe( entry.getValue() ); |
171 if( value instanceof Unsafe ) | 171 if( value instanceof Unsafe ) |
172 return value; | 172 return value; |
173 rtn.rawPut(key,value); | 173 rtn.rawPut(key,value); |
174 } | 174 } |
175 return rtn; | 175 return rtn; |
176 } else if( v instanceof Object[] ) { | 176 } else if( v instanceof Object[] ) { |
177 Object[] a = (Object[])v; | 177 Object[] a = (Object[])v; |
178 for( int i=0; i<a.length; i++ ) { | 178 for( int i=0; i<a.length; i++ ) { |
179 Object obj = makeSafe(luan,a[i]); | 179 Object obj = makeSafe(a[i]); |
180 if( obj instanceof Unsafe ) | 180 if( obj instanceof Unsafe ) |
181 return obj; | 181 return obj; |
182 a[i] = obj; | 182 a[i] = obj; |
183 } | 183 } |
184 return a; | 184 return a; |
198 LuanCloner cloner = new LuanCloner(LuanCloner.Type.COMPLETE); | 198 LuanCloner cloner = new LuanCloner(LuanCloner.Type.COMPLETE); |
199 this.fns = (LuanTable)cloner.get(fns); | 199 this.fns = (LuanTable)cloner.get(fns); |
200 } | 200 } |
201 | 201 |
202 public synchronized Object call(Luan callerLuan,String fnName,Object... args) throws LuanException { | 202 public synchronized Object call(Luan callerLuan,String fnName,Object... args) throws LuanException { |
203 Object obj = makeSafe(luan,args); | 203 Object obj = makeSafe(args); |
204 if( obj instanceof Unsafe ) | 204 if( obj instanceof Unsafe ) |
205 throw new LuanException("can't pass "+((Unsafe)obj).reason+" to global_callable "+Arrays.asList(args)); | 205 throw new LuanException("can't pass "+((Unsafe)obj).reason+" to global_callable "+Arrays.asList(args)); |
206 args = (Object[])obj; | 206 args = (Object[])obj; |
207 Object f = fns.get(fnName); | 207 Object f = fns.get(luan,fnName); |
208 if( f == null ) | 208 if( f == null ) |
209 throw new LuanException("function '"+fnName+"' not found in global_callable"); | 209 throw new LuanException("function '"+fnName+"' not found in global_callable"); |
210 if( !(f instanceof LuanFunction) ) | 210 if( !(f instanceof LuanFunction) ) |
211 throw new LuanException("value of '"+fnName+"' not a function in global_callable"); | 211 throw new LuanException("value of '"+fnName+"' not a function in global_callable"); |
212 LuanFunction fn = (LuanFunction)f; | 212 LuanFunction fn = (LuanFunction)f; |
213 Object rtn = fn.call(args); | 213 Object rtn = fn.call(args); |
214 rtn = makeSafe(callerLuan,rtn); | 214 rtn = makeSafe(rtn); |
215 if( rtn instanceof Unsafe ) | 215 if( rtn instanceof Unsafe ) |
216 throw new LuanException("can't return "+((Unsafe)rtn).reason+" from global_callable"); | 216 throw new LuanException("can't return "+((Unsafe)rtn).reason+" from global_callable"); |
217 return rtn; | 217 return rtn; |
218 } | 218 } |
219 } | 219 } |