Refactor call stack and its use throughout. CallFrame now does all bytecode processing, and the callframe is reinitialized anytime something might have changed, like a function call.

This commit is contained in:
James Roseborough
2007-06-27 06:43:33 +00:00
parent 93fc4699a9
commit c8e1934916
20 changed files with 548 additions and 136 deletions

View File

@@ -2,13 +2,13 @@
import java.io.IOException;
import java.io.InputStream;
import lua.GlobalState;
import lua.StackState;
import lua.addon.luajava.LuaJava;
import lua.io.Closure;
import lua.io.LoadState;
import lua.io.Proto;
import lua.value.LString;
import lua.value.LValue;
/**
* Program to run a compiled lua chunk for test purposes,
@@ -30,20 +30,18 @@ public class LuaJavaAppRunner {
// new lua state
StackState state = new StackState();
// push args onto stack
// convert args to lua
LValue[] vargs = new LValue[args.length];
for ( int i=1; i<args.length; i++ )
state.push(new LString(args[i]));
vargs[i] = new LString(args[i]);
// load the file
InputStream is = LuaJavaAppRunner.class.getResourceAsStream( script );
Proto p = LoadState.undump(state, is, script);
// create closure to execute
// create closure and execute
Closure c = new Closure( state, p );
state.push( c );
for ( int i=0; i<args.length; i++ )
state.push( new LString(args[i]) );
state.docall(args.length, 0);
state.doCall(c, vargs, 0);
}
}

View File

@@ -7,6 +7,7 @@ import lua.io.Closure;
import lua.io.LoadState;
import lua.io.Proto;
import lua.value.LString;
import lua.value.LValue;
/**
* Program to run a compiled lua chunk for test purposes
@@ -24,25 +25,17 @@ public class LuacRunner {
// new lua state
StackState state = new StackState();
// push args onto stack
// convert args to lua
LValue[] vargs = new LValue[args.length];
for ( int i=1; i<args.length; i++ )
state.push(new LString(args[i]));
vargs[i] = new LString(args[i]);
// load the file
InputStream is = LuacRunner.class.getResourceAsStream( script );
Proto p = LoadState.undump(state, is, script);
// create closure to execute
// create closure and execute
Closure c = new Closure( state, p );
state.push( c );
for ( int i=0; i<args.length; i++ )
state.push( new LString(args[i]) );
state.docall(args.length, 0);
// print result?
System.out.println("stack:");
for ( int i=0; i<state.top; i++ )
System.out.println(" ["+i+"]="+state.stack[i] );
state.doCall(c, vargs, 0);
}
}