Improve vararg handling logic.
This commit is contained in:
@@ -32,6 +32,7 @@ final class Builtin extends LFunction {
|
||||
|
||||
// perform a lua call
|
||||
public void luaStackCall(StackState state, int base) {
|
||||
int returnValues = 0;
|
||||
switch ( id ) {
|
||||
case PRINT:
|
||||
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.println();
|
||||
return;
|
||||
break;
|
||||
case PAIRS:
|
||||
state.adjustTop(base+2);
|
||||
LValue value = state.stack[base+1].luaPairs();
|
||||
state.stack[base] = value;
|
||||
state.adjustTop(base+1);
|
||||
return;
|
||||
returnValues = 1;
|
||||
break;
|
||||
default:
|
||||
luaUnsupportedOperation();
|
||||
}
|
||||
state.adjustTop(base-1+returnValues);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,6 +18,7 @@ public class Closure extends LValue {
|
||||
|
||||
// perform a lua call
|
||||
public void luaStackCall(StackState state, int base) {
|
||||
if ( (! p.is_vararg) || (state.top < base+1+p.numparams) )
|
||||
state.adjustTop( base+1+p.numparams );
|
||||
state.vmExecute( this, base+1 );
|
||||
}
|
||||
|
||||
@@ -39,3 +39,17 @@ print( func(11, 12, 13) )
|
||||
print( func(23, 22, 21) )
|
||||
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