From 783eec9b4592ff3fa54ffa1a855dda2a71f2db64 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Wed, 13 Mar 2019 20:55:24 -0700 Subject: Made iteration easier to work with by using .__inext and .__next for custom iteration, and a custom ipairs() and pairs() to use that. --- builtin_metatables.moon | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'builtin_metatables.moon') 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 = -- cgit v1.2.3