aboutsummaryrefslogtreecommitdiff
path: root/builtin_metatables.moon
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.moon
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.moon')
-rw-r--r--builtin_metatables.moon4
1 files changed, 3 insertions, 1 deletions
diff --git a/builtin_metatables.moon b/builtin_metatables.moon
index 7af5bf7..430a48a 100644
--- a/builtin_metatables.moon
+++ b/builtin_metatables.moon
@@ -80,8 +80,9 @@ co_mt =
as_text: => (tostring(@)\gsub("thread", "Coroutine")).." ("..coroutine.status(@)..")"
__len: => math.huge
__call: coroutine.resume
- __next: (k)=>
+ __inext: (k)=>
ok, val = coroutine.resume(@)
+ return if coroutine.status(@) == 'dead'
if ok then return (k or 0) + 1, val
__index: (k)=>
if k == (_last_co_i[@] or 0) + 1
@@ -92,6 +93,7 @@ co_mt =
else
return nil
return co_mt[k]
+co_mt.__next = co_mt.__inext
debug.setmetatable(coroutine.create(->), co_mt)
nil_mt =