Mercurial Hosting > luan
diff src/luan/interp/Chunk.java @ 21:c93d8c781853
add functions
git-svn-id: https://luan-java.googlecode.com/svn/trunk@22 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Tue, 04 Dec 2012 09:16:03 +0000 |
parents | 09d41f7490a8 |
children | 2446c1755d9b |
line wrap: on
line diff
--- a/src/luan/interp/Chunk.java Sun Dec 02 10:51:18 2012 +0000 +++ b/src/luan/interp/Chunk.java Tue Dec 04 09:16:03 2012 +0000 @@ -2,24 +2,37 @@ import luan.LuaState; import luan.LuaException; +import luan.LuaClosure; -final class Chunk implements Stmt { - private final Stmt block; - private final int stackSize; +public final class Chunk implements Expr { + public final Stmt block; + public final int stackSize; + public final int numArgs; - Chunk(Stmt block,int stackSize) { + Chunk(Stmt block,int stackSize,int numArgs) { this.block = block; this.stackSize = stackSize; - } - - @Override public void eval(LuaState lua) throws LuaException { - lua.newStack(stackSize); - try { - block.eval(lua); - } finally { - lua.popStack(); + this.numArgs = numArgs; + Stmt stmt = block; + while( stmt instanceof Block ) { + Block b = (Block)stmt; + if( b.stmts.length==0 ) + break; + stmt = b.stmts[b.stmts.length-1]; + } + if( stmt instanceof ReturnStmt ) { + ReturnStmt rs = (ReturnStmt)stmt; + rs.throwReturnException = false; } } + public LuaClosure newClosure(LuaState lua) { + return new LuaClosure(this,lua); + } + + @Override public Object eval(LuaState lua) { + return newClosure(lua); + } + }