diff --git a/src/main/java/lua/io/Closure.java b/src/main/java/lua/io/Closure.java index a05d37da..da650e0b 100644 --- a/src/main/java/lua/io/Closure.java +++ b/src/main/java/lua/io/Closure.java @@ -1,6 +1,8 @@ package lua.io; import lua.StackState; +import lua.value.LInteger; +import lua.value.LNil; import lua.value.LValue; public class Closure extends LValue { @@ -18,8 +20,26 @@ 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 ); + // skip over closure + base++; + 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