Fixed table.unpack
This commit is contained in:
@@ -898,6 +898,11 @@ public class LuaTable extends LuaValue implements Metatable {
|
|||||||
|
|
||||||
/** Unpack the elements from i to j inclusive */
|
/** Unpack the elements from i to j inclusive */
|
||||||
public Varargs unpack(int i, int j) {
|
public Varargs unpack(int i, int j) {
|
||||||
|
if (j < i) return NONE;
|
||||||
|
int count = j - i;
|
||||||
|
if (count < 0) throw new LuaError("too many results to unpack: greater " + Integer.MAX_VALUE); // integer overflow
|
||||||
|
int max = 0x00ffffff;
|
||||||
|
if (count >= max) throw new LuaError("too many results to unpack: " + count + " (max is " + max + ')');
|
||||||
int n = j + 1 - i;
|
int n = j + 1 - i;
|
||||||
switch (n) {
|
switch (n) {
|
||||||
case 0: return NONE;
|
case 0: return NONE;
|
||||||
@@ -906,10 +911,14 @@ public class LuaTable extends LuaValue implements Metatable {
|
|||||||
default:
|
default:
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
return NONE;
|
return NONE;
|
||||||
LuaValue[] v = new LuaValue[n];
|
try {
|
||||||
while (--n >= 0)
|
LuaValue[] v = new LuaValue[n];
|
||||||
v[n] = get(i+n);
|
while (--n >= 0)
|
||||||
return varargsOf(v);
|
v[n] = get(i+n);
|
||||||
|
return varargsOf(v);
|
||||||
|
} catch (OutOfMemoryError e) {
|
||||||
|
throw new LuaError("too many results to unpack [out of memory]: " + n);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user