Improve vararg handling logic.
This commit is contained in:
@@ -32,6 +32,7 @@ final class Builtin extends LFunction {
|
|||||||
|
|
||||||
// perform a lua call
|
// perform a lua call
|
||||||
public void luaStackCall(StackState state, int base) {
|
public void luaStackCall(StackState state, int base) {
|
||||||
|
int returnValues = 0;
|
||||||
switch ( id ) {
|
switch ( id ) {
|
||||||
case PRINT:
|
case PRINT:
|
||||||
for ( int i=base+1, n=state.top; i<n; i++ ) {
|
for ( int i=base+1, n=state.top; i<n; i++ ) {
|
||||||
@@ -39,16 +40,17 @@ final class Builtin extends LFunction {
|
|||||||
System.out.print( "\t" );
|
System.out.print( "\t" );
|
||||||
}
|
}
|
||||||
System.out.println();
|
System.out.println();
|
||||||
return;
|
break;
|
||||||
case PAIRS:
|
case PAIRS:
|
||||||
state.adjustTop(base+2);
|
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;
|
||||||
state.adjustTop(base+1);
|
returnValues = 1;
|
||||||
return;
|
break;
|
||||||
default:
|
default:
|
||||||
luaUnsupportedOperation();
|
luaUnsupportedOperation();
|
||||||
}
|
}
|
||||||
|
state.adjustTop(base-1+returnValues);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -18,7 +18,8 @@ public class Closure extends LValue {
|
|||||||
|
|
||||||
// perform a lua call
|
// perform a lua call
|
||||||
public void luaStackCall(StackState state, int base) {
|
public void luaStackCall(StackState state, int base) {
|
||||||
state.adjustTop( base+1+p.numparams );
|
if ( (! p.is_vararg) || (state.top < base+1+p.numparams) )
|
||||||
|
state.adjustTop( base+1+p.numparams );
|
||||||
state.vmExecute( this, base+1 );
|
state.vmExecute( this, base+1 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,3 +39,17 @@ print( func(11, 12, 13) )
|
|||||||
print( func(23, 22, 21) )
|
print( func(23, 22, 21) )
|
||||||
print( func(func(32,33,34), func(45,46,47), func(58,59,50)) )
|
print( func(func(32,33,34), func(45,46,47), func(58,59,50)) )
|
||||||
|
|
||||||
|
--[[
|
||||||
|
function p(a,...)
|
||||||
|
print("a",a)
|
||||||
|
print("a,...",a,...)
|
||||||
|
print("...",...)
|
||||||
|
print("...,a",...,a)
|
||||||
|
end
|
||||||
|
local aa,bb,cc,dd
|
||||||
|
p()
|
||||||
|
p("q")
|
||||||
|
p("q","r")
|
||||||
|
p("q","r","s")
|
||||||
|
print(aa,bb,cc,dd)
|
||||||
|
--]]
|
||||||
|
|||||||
Reference in New Issue
Block a user