[NOTHING CHANGED] Assorted fixes #48
@@ -99,7 +99,7 @@ package org.luaj.vm2;
|
||||
* {@link #INDEX}, {@link #NEWINDEX}, {@link #CALL}, {@link #MODE}, {@link #METATABLE},
|
||||
* {@link #ADD}, {@link #SUB}, {@link #DIV}, {@link #MUL}, {@link #POW},
|
||||
* {@link #MOD}, {@link #UNM}, {@link #LEN}, {@link #EQ}, {@link #LT},
|
||||
* {@link #LE}, {@link #TOSTRING}, and {@link #CONCAT}.
|
||||
* {@link #LE}, {@link #TOSTRING}, {@link #CONCAT}, {@link PAIRS} and {@link IPAIRS}.
|
||||
*
|
||||
* @see org.luaj.vm2.lib.jse.JsePlatform
|
||||
* @see org.luaj.vm2.lib.jme.JmePlatform
|
||||
@@ -243,6 +243,12 @@ public class LuaValue extends Varargs {
|
||||
/** LuaString constant with value "__concat" for use as metatag */
|
||||
public static final LuaString CONCAT = valueOf("__concat");
|
||||
|
||||
/** LuaString constant with value "__pairs" for use as metatag */
|
||||
public static final LuaString PAIRS = valueOf("__pairs");
|
||||
|
||||
/** LuaString constant with value "__ipairs" for use as metatag */
|
||||
public static final LuaString IPAIRS = valueOf("__ipairs");
|
||||
|
||||
/** LuaString constant with value "" */
|
||||
public static final LuaString EMPTYSTRING = valueOf("");
|
||||
|
||||
|
||||
@@ -113,8 +113,8 @@ public class BaseLib extends TwoArgFunction implements ResourceFinder {
|
||||
|
||||
next next;
|
||||
env.set("next", next = new next());
|
||||
env.set("pairs", new pairs(next));
|
||||
env.set("ipairs", new ipairs());
|
||||
env.set("pairs", new pairsbase(PAIRS, NIL, next));
|
||||
env.set("ipairs", new pairsbase(IPAIRS, ZERO, new inext()));
|
||||
|
||||
return env;
|
||||
}
|
||||
@@ -396,22 +396,25 @@ public class BaseLib extends TwoArgFunction implements ResourceFinder {
|
||||
}
|
||||
}
|
||||
|
||||
// "pairs" (t) -> iter-func, t, nil
|
||||
static final class pairs extends VarArgFunction {
|
||||
final next next;
|
||||
pairs(next next) {
|
||||
this.next = next;
|
||||
}
|
||||
public Varargs invoke(Varargs args) {
|
||||
return varargsOf( next, args.checktable(1), NIL );
|
||||
}
|
||||
// pairsbase, // (t) -> iter-func, t, initial
|
||||
static final class pairsbase extends VarArgFunction {
|
||||
final LuaString method;
|
||||
final LuaValue initial;
|
||||
final VarArgFunction iter;
|
||||
|
||||
pairsbase(LuaString method, LuaValue initial, VarArgFunction iter) {
|
||||
this.method = method;
|
||||
this.initial = initial;
|
||||
this.iter = iter;
|
||||
}
|
||||
|
||||
// // "ipairs", // (t) -> iter-func, t, 0
|
||||
static final class ipairs extends VarArgFunction {
|
||||
inext inext = new inext();
|
||||
public Varargs invoke(Varargs args) {
|
||||
return varargsOf( inext, args.checktable(1), ZERO );
|
||||
LuaValue arg = args.arg1();
|
||||
LuaValue t = arg.metatag(method);
|
||||
if (!t.isnil())
|
||||
// TODO: This can return more than 3 results.
|
||||
return t.invoke(args.isvalue(1) ? arg : t);
|
||||
return varargsOf(iter, args.checktable(1), initial);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user