Mercurial Hosting > luan
comparison src/luan/interp/Closure.java @ 49:8ede219cd111
add WebShell
git-svn-id: https://luan-java.googlecode.com/svn/trunk@50 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Fri, 28 Dec 2012 19:35:04 +0000 |
parents | 64ecb7a3aad7 |
children | 4bf3d0c0b6b9 |
comparison
equal
deleted
inserted
replaced
48:64ecb7a3aad7 | 49:8ede219cd111 |
---|---|
9 final class Closure extends LuanFunction { | 9 final class Closure extends LuanFunction { |
10 private final Chunk chunk; | 10 private final Chunk chunk; |
11 final UpValue[] upValues; | 11 final UpValue[] upValues; |
12 private final static UpValue[] NO_UP_VALUES = new UpValue[0]; | 12 private final static UpValue[] NO_UP_VALUES = new UpValue[0]; |
13 | 13 |
14 Closure(Chunk chunk,LuanStateImpl lua) { | 14 Closure(LuanStateImpl luan,Chunk chunk) { |
15 this.chunk = chunk; | 15 this.chunk = chunk; |
16 UpValue.Getter[] upValueGetters = chunk.upValueGetters; | 16 UpValue.Getter[] upValueGetters = chunk.upValueGetters; |
17 if( upValueGetters.length==0 ) { | 17 if( upValueGetters.length==0 ) { |
18 upValues = NO_UP_VALUES; | 18 upValues = NO_UP_VALUES; |
19 } else { | 19 } else { |
20 upValues = new UpValue[upValueGetters.length]; | 20 upValues = new UpValue[upValueGetters.length]; |
21 for( int i=0; i<upValues.length; i++ ) { | 21 for( int i=0; i<upValues.length; i++ ) { |
22 upValues[i] = upValueGetters[i].get(lua); | 22 upValues[i] = upValueGetters[i].get(luan); |
23 } | 23 } |
24 } | 24 } |
25 } | 25 } |
26 | 26 |
27 public Object[] call(LuanState lua,Object[] args) throws LuanException { | 27 public Object[] call(LuanState luan,Object[] args) throws LuanException { |
28 return call(this,(LuanStateImpl)lua,args); | 28 return call(this,(LuanStateImpl)luan,args); |
29 } | 29 } |
30 | 30 |
31 private static Object[] call(Closure closure,LuanStateImpl lua,Object[] args) throws LuanException { | 31 private static Object[] call(Closure closure,LuanStateImpl luan,Object[] args) throws LuanException { |
32 while(true) { | 32 while(true) { |
33 Chunk chunk = closure.chunk; | 33 Chunk chunk = closure.chunk; |
34 Object[] varArgs = null; | 34 Object[] varArgs = null; |
35 if( chunk.isVarArg ) { | 35 if( chunk.isVarArg ) { |
36 if( args.length > chunk.numArgs ) { | 36 if( args.length > chunk.numArgs ) { |
40 } | 40 } |
41 } else { | 41 } else { |
42 varArgs = LuanFunction.EMPTY_RTN; | 42 varArgs = LuanFunction.EMPTY_RTN; |
43 } | 43 } |
44 } | 44 } |
45 Object[] stack = lua.newFrame(closure,chunk.stackSize,varArgs); | 45 Object[] stack = luan.newFrame(closure,chunk.stackSize,varArgs); |
46 final int n = Math.min(args.length,chunk.numArgs); | 46 final int n = Math.min(args.length,chunk.numArgs); |
47 for( int i=0; i<n; i++ ) { | 47 for( int i=0; i<n; i++ ) { |
48 stack[i] = args[i]; | 48 stack[i] = args[i]; |
49 } | 49 } |
50 Object[] returnValues; | 50 Object[] returnValues; |
51 Closure tailFn; | 51 Closure tailFn; |
52 try { | 52 try { |
53 chunk.block.eval(lua); | 53 chunk.block.eval(luan); |
54 } catch(ReturnException e) { | 54 } catch(ReturnException e) { |
55 } finally { | 55 } finally { |
56 returnValues = lua.returnValues; | 56 returnValues = luan.returnValues; |
57 closure = lua.tailFn; | 57 closure = luan.tailFn; |
58 lua.popFrame(); | 58 luan.popFrame(); |
59 } | 59 } |
60 if( closure == null ) | 60 if( closure == null ) |
61 return returnValues; | 61 return returnValues; |
62 args = returnValues; | 62 args = returnValues; |
63 } | 63 } |