aboutsummaryrefslogtreecommitdiff
path: root/builtin_metatables.lua
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2019-03-13 20:55:24 -0700
committerBruce Hill <bruce@bruce-hill.com>2019-03-13 20:55:59 -0700
commit783eec9b4592ff3fa54ffa1a855dda2a71f2db64 (patch)
tree3c03408a582b26e6d7fa37f661b695bb6c39ece3 /builtin_metatables.lua
parent1e99bbbe0a12b85800d316fcccd993591dde2431 (diff)
Made iteration easier to work with by using .__inext and .__next for
custom iteration, and a custom ipairs() and pairs() to use that.
Diffstat (limited to 'builtin_metatables.lua')
-rw-r--r--builtin_metatables.lua6
1 files changed, 5 insertions, 1 deletions
diff --git a/builtin_metatables.lua b/builtin_metatables.lua
index 63d865c..3b29e39 100644
--- a/builtin_metatables.lua
+++ b/builtin_metatables.lua
@@ -186,8 +186,11 @@ co_mt = {
return math.huge
end,
__call = coroutine.resume,
- __next = function(self, k)
+ __inext = function(self, k)
local ok, val = coroutine.resume(self)
+ if coroutine.status(self) == 'dead' then
+ return
+ end
if ok then
return (k or 0) + 1, val
end
@@ -207,6 +210,7 @@ co_mt = {
return co_mt[k]
end
}
+co_mt.__next = co_mt.__inext
debug.setmetatable(coroutine.create(function() end), co_mt)
local nil_mt = {
__type = "Nil",