Rework the main API"s that implement the calling convention. Provide utility methods to get arguments that were supplied, and provide return values. Add a VM interface to clarify the relationship between the VM, things that call the VM, and things that are called by the VM. Make the code more closely aligned with the C++ version.
This commit is contained in:
@@ -30,18 +30,13 @@ public class LuaJavaAppRunner {
|
||||
// new lua state
|
||||
StackState state = new StackState();
|
||||
|
||||
// convert args to lua
|
||||
LValue[] vargs = new LValue[args.length];
|
||||
for ( int i=1; i<args.length; 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 and execute
|
||||
Closure c = new Closure( state, p );
|
||||
state.doCall(c, vargs, 0);
|
||||
state.doCall(c, new LValue[0]);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import lua.StackState;
|
||||
import lua.VM;
|
||||
import lua.io.Closure;
|
||||
import lua.io.LoadState;
|
||||
import lua.io.Proto;
|
||||
@@ -19,23 +20,21 @@ public class LuacRunner {
|
||||
public static void main( String[] args ) throws IOException {
|
||||
|
||||
// get script name
|
||||
String script = (args.length>0? args[0]: "/test1.luac");
|
||||
String script = (args.length>0? args[0]: "/test2.luac");
|
||||
System.out.println("loading '"+script+"'");
|
||||
|
||||
// new lua state
|
||||
StackState state = new StackState();
|
||||
VM vm = state;
|
||||
|
||||
// convert args to lua
|
||||
LValue[] vargs = new LValue[args.length];
|
||||
for ( int i=1; i<args.length; 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 and execute
|
||||
Closure c = new Closure( state, p );
|
||||
state.doCall(c, vargs, 0);
|
||||
|
||||
// do the call
|
||||
vm.doCall( c, new LValue[0] );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ public class LuaJTest extends TestCase {
|
||||
try {
|
||||
// create closure and execute
|
||||
Closure c = new Closure( state, p );
|
||||
state.doCall(c, new LValue[0], 0);
|
||||
state.doCall(c, new LValue[0]);
|
||||
|
||||
final String actualOutput = new String( outputStream.toByteArray() );
|
||||
final String expectedOutput = getExpectedOutput( testName );
|
||||
|
||||
@@ -78,14 +78,14 @@ public class StandardTest extends TestCase {
|
||||
Builtin.redirectOutput( output );
|
||||
try {
|
||||
try {
|
||||
state.doCall( c, new LValue[0], 0 );
|
||||
state.doCall( c, new LValue[0] );
|
||||
} catch ( RuntimeException exn ) {
|
||||
StackTraceElement[] stackTrace = new StackTraceElement[state.cc+1];
|
||||
for ( int i = 0; i <= state.cc; ++i ) {
|
||||
CallFrame call = state.calls[i];
|
||||
Proto p = call.p;
|
||||
CallInfo call = state.calls[i];
|
||||
Proto p = call.closure.p;
|
||||
int line = p.lineinfo[call.pc];
|
||||
String func = call.cl.luaAsString();
|
||||
String func = call.closure.luaAsString();
|
||||
stackTrace[state.cc - i] = new StackTraceElement(getName(), func, getName()+".lua", line );
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user