Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
With this PR, GopherLua respects the
__index
metamethod inipairs
. This change was introduced in Lua 5.3. (Lua 5.2 had an__ipairs
metamethod, which was deprecated in 5.3.)This would be particularly useful in the context of gopher-luar (CC @layeh). To iterate over a Go array or slice
t
from Lua, one currently has to access the iterator viat()
(__call
metamethod). This means that one has to write separate code for iterating over Lua lists on the one hand and Go arrays/slices on the other. With this PR, the same code would work for both cases.Performance: On my machine, summing up the values of an honest Lua list with one million integer entries becomes about 15% slower with this PR. For non-trivial loop bodies the slow-down would obviously be smaller.
EDIT: Iterating over a Go array/slice doesn't work yet because gopher-luar doesn't return
nil
if one tries to access a non-existing entry, but instead errors. Iterating over a Go map with indices1
,2
, ... does work.