Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ipairs iterator nil argument handling difference vs pairs iterator #91

Open
Wojbie opened this issue Nov 25, 2024 · 0 comments
Open

ipairs iterator nil argument handling difference vs pairs iterator #91

Wojbie opened this issue Nov 25, 2024 · 0 comments
Labels

Comments

@Wojbie
Copy link

Wojbie commented Nov 25, 2024

It seems there is small difference how pairs vs ipairs handle it when you explicitly put incorrect argument type.
obraz

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.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants