Fix calling convention by managing top of stack and adjusting on way in and out of function calls.
This commit is contained in:
@@ -31,23 +31,23 @@ final class Builtin extends LFunction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// perform a lua call
|
// perform a lua call
|
||||||
public int luaStackCall(StackState state, int base, int nargs) {
|
public void luaStackCall(StackState state, int base) {
|
||||||
switch ( id ) {
|
switch ( id ) {
|
||||||
case PRINT:
|
case PRINT:
|
||||||
for ( int i=0; i<nargs; i++ ) {
|
for ( int i=base+1, n=state.top; i<n; i++ ) {
|
||||||
if ( i > 0 )
|
System.out.print( String.valueOf(state.stack[i]) );
|
||||||
System.out.print( "\t" );
|
System.out.print( "\t" );
|
||||||
System.out.print( String.valueOf(state.stack[base+1+i]) );
|
|
||||||
}
|
}
|
||||||
System.out.println();
|
System.out.println();
|
||||||
return 0;
|
return;
|
||||||
case PAIRS:
|
case PAIRS:
|
||||||
|
state.adjustTop(base+2);
|
||||||
LValue value = state.stack[base+1].luaPairs();
|
LValue value = state.stack[base+1].luaPairs();
|
||||||
state.stack[base] = value;
|
state.stack[base] = value;
|
||||||
return 1;
|
state.adjustTop(base+1);
|
||||||
|
return;
|
||||||
default:
|
default:
|
||||||
luaUnsupportedOperation();
|
luaUnsupportedOperation();
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ public class Closure extends LValue {
|
|||||||
|
|
||||||
|
|
||||||
// perform a lua call
|
// perform a lua call
|
||||||
public int luaStackCall(StackState state, int base, int nargs) {
|
public void luaStackCall(StackState state, int base) {
|
||||||
state.clear( base+1+nargs, p.numparams-nargs );
|
state.adjustTop( base+1+p.numparams );
|
||||||
return state.vmExecute( this, base+1 );
|
state.vmExecute( this, base+1 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,14 +50,15 @@ public class LTable extends LValue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// perform a lua call
|
// perform a lua call
|
||||||
public int luaStackCall(StackState state, int base, int nargs) {
|
public void luaStackCall(StackState state, int base) {
|
||||||
if ( e.hasMoreElements() ) {
|
if ( e.hasMoreElements() ) {
|
||||||
LValue key = (LValue) e.nextElement();
|
LValue key = (LValue) e.nextElement();
|
||||||
|
state.adjustTop(base+2);
|
||||||
state.stack[base] = key;
|
state.stack[base] = key;
|
||||||
state.stack[base+1] = t.luaGetTable(key);
|
state.stack[base+1] = t.luaGetTable(key);
|
||||||
return 2;
|
} else {
|
||||||
|
state.adjustTop(base);
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,9 +15,8 @@ public class LValue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// perform a lua call, return number of results actually produced
|
// perform a lua call, return number of results actually produced
|
||||||
public int luaStackCall(StackState state, int base, int nargs) {
|
public void luaStackCall(StackState state, int base) {
|
||||||
luaUnsupportedOperation();
|
luaUnsupportedOperation();
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// unsupported except for numbers
|
// unsupported except for numbers
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
function f0() print( "f0:" ) end
|
function f0() print( "f0:" ) end
|
||||||
function f1(a) print( "f1:", a ) end
|
function f1(a) print( "f1:", a ) end
|
||||||
function f2(a,b) print( "f2:", a, b ) end
|
function f2(a,b) print( "f2:", a, b ) end
|
||||||
@@ -24,7 +25,7 @@ z = g4("c4.1/4", "c4.2/4", "c4.3/4", "c4.4/4")
|
|||||||
print( "z4:", z )
|
print( "z4:", z )
|
||||||
|
|
||||||
a,b,c,d = g0( "c0.1/4", "c0.2/4", "c0.3/4", "c0.4/4" )
|
a,b,c,d = g0( "c0.1/4", "c0.2/4", "c0.3/4", "c0.4/4" )
|
||||||
print( "g0:", a, b, c, d, "(eol" )
|
print( "g0:", a, b, c, d, "(eol)" )
|
||||||
a,b,c,d = g2( "b2.1/4", "b2.2/4", "b2.3/4", "b2.4/4" )
|
a,b,c,d = g2( "b2.1/4", "b2.2/4", "b2.3/4", "b2.4/4" )
|
||||||
print( "g2:", a, b, c, d, "(eol)" )
|
print( "g2:", a, b, c, d, "(eol)" )
|
||||||
a,b,c,d = g4( "b4.1/4", "b4.2/4", "b4.3/4", "b4.4/4" )
|
a,b,c,d = g4( "b4.1/4", "b4.2/4", "b4.3/4", "b4.4/4" )
|
||||||
|
|||||||
Reference in New Issue
Block a user