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:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/bin/bash
|
||||
LUA_HOME=/cygdrive/c/programs/lua5.1
|
||||
TESTS="test1 test2 test3 test4 test5"
|
||||
#TESTS="test5"
|
||||
TESTS="test3"
|
||||
for x in $TESTS
|
||||
do
|
||||
echo compiling $x
|
||||
|
||||
@@ -1,6 +1,40 @@
|
||||
a = func(1, 2, 3)
|
||||
a = func(3, 2, 1)
|
||||
a = func(func(),func(),func())
|
||||
function f0() print( "f0:" ) end
|
||||
function f1(a) print( "f1:", a ) end
|
||||
function f2(a,b) print( "f2:", a, b ) end
|
||||
function f3(a,b,c) print( "f3:", a, b, c ) end
|
||||
function f4(a,b,c,d) print( "f4:", a, b, c, d ) end
|
||||
|
||||
f0() f0( "a1/1" ) f0( "a1/2", "a2/2" ) f0( "a1/3", "a2/3", "a3/3" ) f0( "a1/4", "a2/4", "a3/4", "a4/4" )
|
||||
f1() f1( "a1/1" ) f1( "a1/2", "a2/2" ) f1( "a1/3", "a2/3", "a3/3" ) f1( "a1/4", "a2/4", "a3/4", "a4/4" )
|
||||
f2() f2( "a1/1" ) f2( "a1/2", "a2/2" ) f2( "a1/3", "a2/3", "a3/3" ) f2( "a1/4", "a2/4", "a3/4", "a4/4" )
|
||||
f3() f3( "a1/1" ) f3( "a1/2", "a2/2" ) f3( "a1/3", "a2/3", "a3/3" ) f3( "a1/4", "a2/4", "a3/4", "a4/4" )
|
||||
f4() f4( "a1/1" ) f4( "a1/2", "a2/2" ) f4( "a1/3", "a2/3", "a3/3" ) f4( "a1/4", "a2/4", "a3/4", "a4/4" )
|
||||
|
||||
function g0(a,b,c,d) return end
|
||||
function g1(a,b,c,d) return d end
|
||||
function g2(a,b,c,d) return c, d end
|
||||
function g3(a,b,c,d) return b, c, d end
|
||||
function g4(a,b,c,d) return a, b, c, d end
|
||||
|
||||
z = g0("c0.1/4", "c0.2/4", "c0.3/4", "c0.4/4")
|
||||
print( "z0:", z )
|
||||
z = g2("c2.1/4", "c2.2/4", "c2.3/4", "c2.4/4")
|
||||
print( "z2:", z )
|
||||
z = g4("c4.1/4", "c4.2/4", "c4.3/4", "c4.4/4")
|
||||
print( "z4:", z )
|
||||
|
||||
a,b,c,d = g0( "c0.1/4", "c0.2/4", "c0.3/4", "c0.4/4" )
|
||||
print( "g0:", a, b, c, d, "(eol" )
|
||||
a,b,c,d = g2( "b2.1/4", "b2.2/4", "b2.3/4", "b2.4/4" )
|
||||
print( "g2:", a, b, c, d, "(eol)" )
|
||||
a,b,c,d = g4( "b4.1/4", "b4.2/4", "b4.3/4", "b4.4/4" )
|
||||
print( "g4:", a, b, c, d, "(eol)" )
|
||||
|
||||
function func(a,b,c)
|
||||
return a, b, c
|
||||
end
|
||||
|
||||
print( func(11, 12, 13) )
|
||||
print( func(23, 22, 21) )
|
||||
print( func(func(32,33,34), func(45,46,47), func(58,59,50)) )
|
||||
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user