Vix VARARGS passing by adjusting stack on varargs call to bury varargs + length of varargs under base of stack
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
package lua.io;
|
package lua.io;
|
||||||
|
|
||||||
import lua.StackState;
|
import lua.StackState;
|
||||||
|
import lua.value.LInteger;
|
||||||
|
import lua.value.LNil;
|
||||||
import lua.value.LValue;
|
import lua.value.LValue;
|
||||||
|
|
||||||
public class Closure extends LValue {
|
public class Closure extends LValue {
|
||||||
@@ -18,8 +20,26 @@ 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) {
|
||||||
if ( (! p.is_vararg) || (state.top < base+1+p.numparams) )
|
// skip over closure
|
||||||
state.adjustTop( base+1+p.numparams );
|
base++;
|
||||||
state.vmExecute( this, base+1 );
|
if ( p.is_vararg ) {
|
||||||
|
|
||||||
|
// adjust stack to bury varargs under base
|
||||||
|
int top = state.top;
|
||||||
|
int nsupplied = top-base;
|
||||||
|
int nrequired = p.numparams;
|
||||||
|
int nvarargs = Math.max( 0, nsupplied - nrequired );
|
||||||
|
for ( int i=0; i<nrequired; i++ )
|
||||||
|
state.stack[top+i+1] = (i<nsupplied? state.stack[base+i]: LNil.NIL);
|
||||||
|
state.stack[top] = new LInteger( nvarargs );
|
||||||
|
state.top = top + nrequired + 1;
|
||||||
|
base = top+1;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
// normal non-varargs call
|
||||||
|
state.adjustTop( base+p.numparams );
|
||||||
|
}
|
||||||
|
state.vmExecute( this, base );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,14 +42,12 @@ print( func(func(32,33,34), func(45,46,47), func(58,59,50)) )
|
|||||||
--[[
|
--[[
|
||||||
function p(a,...)
|
function p(a,...)
|
||||||
print("a",a)
|
print("a",a)
|
||||||
print("a,...",a,...)
|
|
||||||
print("...",...)
|
print("...",...)
|
||||||
print("...,a",...,a)
|
print("...,a",...,a)
|
||||||
|
print("a,...",a,...)
|
||||||
end
|
end
|
||||||
local aa,bb,cc,dd
|
|
||||||
p()
|
p()
|
||||||
p("q")
|
p("q")
|
||||||
p("q","r")
|
p("q","r")
|
||||||
p("q","r","s")
|
p("q","r","s")
|
||||||
print(aa,bb,cc,dd)
|
|
||||||
--]]
|
--]]
|
||||||
Reference in New Issue
Block a user