Fixed issue: #51

This commit is contained in:
UnlegitDqrk
2026-03-02 15:28:31 +01:00
parent 7aea99d650
commit 63edacbb5f
11 changed files with 55 additions and 3 deletions

View File

@@ -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.libs.jse.JsePlatform
* @see org.luaj.vm2.libs.jme.JmePlatform
@@ -263,6 +263,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("");

View File

@@ -399,7 +399,9 @@ public class BaseLib extends TwoArgFunction implements ResourceFinder {
this.next = next;
}
public Varargs invoke(Varargs args) {
return varargsOf( next, args.checktable(1), NIL );
LuaValue table = args.arg1();
LuaValue h = table.metatag(PAIRS);
return h.isnil()? varargsOf(next, table.checktable(), NIL): h.invoke(table);
}
}
@@ -407,7 +409,9 @@ public class BaseLib extends TwoArgFunction implements ResourceFinder {
static final class ipairs extends VarArgFunction {
inext inext = new inext();
public Varargs invoke(Varargs args) {
return varargsOf( inext, args.checktable(1), ZERO );
LuaValue table = args.arg1();
LuaValue h = table.metatag(IPAIRS);
return h.isnil()? varargsOf(inext, table.checktable(), ZERO): h.invoke(table);
}
}