diff --git a/src/coroutine/make.lua b/src/coroutine/make.lua index 66d7adb..f176ecc 100644 --- a/src/coroutine/make.lua +++ b/src/coroutine/make.lua @@ -1,20 +1,37 @@ -local select = select -local create = coroutine.create -local isyieldable = coroutine.isyieldable -- luacheck: ignore -local resume = coroutine.resume -local running = coroutine.running -local status = coroutine.status -local wrap = coroutine.wrap -local yield = coroutine.yield +local select = select +local setmetatable = setmetatable +local create = coroutine.create +local isyieldable = coroutine.isyieldable -- luacheck: ignore +local resume = coroutine.resume +local running = coroutine.running +local status = coroutine.status +local wrap = coroutine.wrap +local yield = coroutine.yield + +local _tagged = setmetatable({}, {__mode = 'kv'}) + +local _str_tags = setmetatable({}, {__mode = 'v'}) return function (tag) + if type(tag) == 'string' then + local _tag = _str_tags[tag] or {} + _str_tags[tag] = _tag + tag = _tag + end + + tag = tag or {} + + if _tagged[tag] then + return _tagged[tag] + end + local coroutine = { isyieldable = isyieldable, running = running, status = status, } - tag = tag or {} + _tagged[tag] = coroutine local function for_wrap (co, ...) if tag == ... then return select (2, ...)