-
Notifications
You must be signed in to change notification settings - Fork 15
Open
Labels
Description
It seems there is small difference how pairs vs ipairs handle it when you explicitly put incorrect argument type.
While pairs provides bad argument error, ipairs instead attempts to index that wrong type value, leading to different error that is less readable to end user.
Cobalt/src/main/java/org/squiddev/cobalt/lib/BaseLib.java
Lines 221 to 235 in 6a4e506
private Varargs pairs(LuaState state, Varargs args) throws LuaError, UnwindThrowable { | |
// pairs(t) -> iter-func, t, nil | |
LuaValue value = args.checkValue(1); | |
LuaValue pairs = value.metatag(state, Constants.PAIRS); | |
if (pairs.isNil()) { | |
return varargsOf(next, value, Constants.NIL); | |
} else { | |
return Dispatch.invoke(state, pairs, value); | |
} | |
} | |
private Varargs ipairs(LuaState state, Varargs args) throws LuaError { | |
// ipairst) -> iter-func, t, 0 | |
return varargsOf(inext, args.checkValue(1), Constants.ZERO); | |
} |
I understand from #87 that iterator returned by ipairs is supposed to be what is handling the erroring, but would it be possible to change the error handling of the iterator to be one for incorrect argument instead attempt to index? It would improve clarity and to simplify debugging for end users.