Improve calling convention handling when the number of arguments doesn't match the expected number, and the number of return values doesn't match those needed.

This commit is contained in:
James Roseborough
2007-06-11 04:30:03 +00:00
parent de763e0a1e
commit 05cfdaa33b
7 changed files with 52 additions and 15 deletions

View File

@@ -4,6 +4,7 @@
package lua;
import lua.value.LFunction;
import lua.value.LNil;
import lua.value.LString;
import lua.value.LTable;
import lua.value.LValue;
@@ -30,7 +31,7 @@ final class Builtin extends LFunction {
}
// perform a lua call
public void luaStackCall(StackState state, int base, int nargs) {
public int luaStackCall(StackState state, int base, int nargs) {
switch ( id ) {
case PRINT:
for ( int i=0; i<nargs; i++ ) {
@@ -39,13 +40,14 @@ final class Builtin extends LFunction {
System.out.print( String.valueOf(state.stack[base+1+i]) );
}
System.out.println();
return;
return 0;
case PAIRS:
LValue value = state.stack[base+1].luaPairs();
state.stack[base] = value;
return;
return 1;
default:
luaUnsupportedOperation();
return 0;
}
}

View File

@@ -17,7 +17,8 @@ public class Closure extends LValue {
// perform a lua call
public void luaStackCall(StackState state, int base, int nresults) {
state.vmExecute( this, base+1 );
public int luaStackCall(StackState state, int base, int nargs) {
state.clear( base+1+nargs, p.numparams-nargs );
return state.vmExecute( this, base+1 );
}
}

View File

@@ -50,15 +50,14 @@ public class LTable extends LValue {
}
// perform a lua call
public void luaStackCall(StackState state, int base, int nresults) {
public int luaStackCall(StackState state, int base, int nargs) {
if ( e.hasMoreElements() ) {
LValue key = (LValue) e.nextElement();
state.stack[base] = key;
state.stack[base+1] = t.luaGetTable(key);
} else {
state.stack[base] = LNil.NIL;
return 2;
}
return 0;
}
}

View File

@@ -14,9 +14,10 @@ public class LValue {
return true;
}
// perform a lua call
public void luaStackCall(StackState state, int base, int nargs) {
// perform a lua call, return number of results actually produced
public int luaStackCall(StackState state, int base, int nargs) {
luaUnsupportedOperation();
return 0;
}
// unsupported except for numbers