Fix compatibility vararg support when 'arg' variable is used.
This commit is contained in:
@@ -58,11 +58,6 @@ public class LuaC extends Lua implements LuaCompiler {
|
|||||||
static final int LUAI_MAXVARS = 200;
|
static final int LUAI_MAXVARS = 200;
|
||||||
static final int NO_REG = MAXARG_A;
|
static final int NO_REG = MAXARG_A;
|
||||||
|
|
||||||
/* masks for new-style vararg */
|
|
||||||
static final int VARARG_HASARG = 1;
|
|
||||||
static final int VARARG_ISVARARG = 2;
|
|
||||||
static final int VARARG_NEEDSARG = 4;
|
|
||||||
|
|
||||||
|
|
||||||
/* OpMode - basic instruction format */
|
/* OpMode - basic instruction format */
|
||||||
static final int
|
static final int
|
||||||
|
|||||||
@@ -33,6 +33,10 @@ public class Lua {
|
|||||||
/** use return values from previous op */
|
/** use return values from previous op */
|
||||||
public static final int LUA_MULTRET = -1;
|
public static final int LUA_MULTRET = -1;
|
||||||
|
|
||||||
|
/** masks for new-style vararg */
|
||||||
|
public static final int VARARG_HASARG = 1;
|
||||||
|
public static final int VARARG_ISVARARG = 2;
|
||||||
|
public static final int VARARG_NEEDSARG = 4;
|
||||||
|
|
||||||
// from lopcodes.h
|
// from lopcodes.h
|
||||||
|
|
||||||
|
|||||||
@@ -171,12 +171,22 @@ public class LuaState extends Lua {
|
|||||||
int nfix = Math.min(narg, npar);
|
int nfix = Math.min(narg, npar);
|
||||||
int nvar = Math.max(0, narg-nfix);
|
int nvar = Math.max(0, narg-nfix);
|
||||||
|
|
||||||
|
|
||||||
// must copy args into position, add number parameter
|
// must copy args into position, add number parameter
|
||||||
stack[top] = LInteger.valueOf(nvar);
|
stack[top] = LInteger.valueOf(nvar);
|
||||||
System.arraycopy(stack, base+1, stack, top+1, nfix);
|
System.arraycopy(stack, base+1, stack, top+1, nfix);
|
||||||
base = top + 1;
|
base = top + 1;
|
||||||
top = base + nfix;
|
top = base + nfix;
|
||||||
luaV_adjusttop( base + npar );
|
luaV_adjusttop( base + npar );
|
||||||
|
|
||||||
|
// add 'arg' compatibility variable
|
||||||
|
if ( (c.p.is_vararg & VARARG_NEEDSARG) != 0 ) {
|
||||||
|
LTable arg = new LTable();
|
||||||
|
for ( int i=1,j=base-nvar-1; i<=nvar; i++, j++ )
|
||||||
|
arg.put(i, stack[j]);
|
||||||
|
arg.put("n", nvar);
|
||||||
|
pushlvalue( arg );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
final int newcc = cc + 1;
|
final int newcc = cc + 1;
|
||||||
if ( newcc >= calls.length ) {
|
if ( newcc >= calls.length ) {
|
||||||
|
|||||||
@@ -5,18 +5,16 @@ function p(a,...)
|
|||||||
print("...,a",...,a)
|
print("...,a",...,a)
|
||||||
print("a,...",a,...)
|
print("a,...",a,...)
|
||||||
end
|
end
|
||||||
--[[ -- these have semantics that depend on compatibity flags
|
|
||||||
function q(a,...)
|
function q(a,...)
|
||||||
print("a,arg[1],arg[2],arg[3]",a,arg[1],arg[2],arg[3])
|
print("a,arg[1],arg[2],arg[3]",a,arg.n,arg[1],arg[2],arg[3])
|
||||||
end
|
end
|
||||||
function r(a,...)
|
function r(a,...)
|
||||||
print("a,arg[1],arg[2],arg[3]",a,arg[1],arg[2],arg[3])
|
print("a,arg",a,arg)
|
||||||
print("a",a)
|
print("a",a)
|
||||||
print("...",...)
|
print("...",...)
|
||||||
print("...,a",...,a)
|
print("...,a",...,a)
|
||||||
print("a,...",a,...)
|
print("a,...",a,...)
|
||||||
end
|
end
|
||||||
--]]
|
|
||||||
function s(a)
|
function s(a)
|
||||||
local arg = { '1', '2', '3' }
|
local arg = { '1', '2', '3' }
|
||||||
print("a,arg[1],arg[2],arg[3]",a,arg[1],arg[2],arg[3])
|
print("a,arg[1],arg[2],arg[3]",a,arg[1],arg[2],arg[3])
|
||||||
@@ -43,7 +41,7 @@ function tryall(f,name)
|
|||||||
print( ' ->', pcall( f, "q", "r", "s" ) )
|
print( ' ->', pcall( f, "q", "r", "s" ) )
|
||||||
end
|
end
|
||||||
tryall(p,'p')
|
tryall(p,'p')
|
||||||
-- tryall(q,'q')
|
tryall(q,'q')
|
||||||
-- tryall(r,'r')
|
tryall(r,'r')
|
||||||
tryall(s,'s')
|
tryall(s,'s')
|
||||||
tryall(t,'t')
|
tryall(t,'t')
|
||||||
|
|||||||
Reference in New Issue
Block a user