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:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user