From b1d549ae3ffcd5352cc5e7c05f2b434b4739160e Mon Sep 17 00:00:00 2001 From: Philipp Janda Date: Tue, 18 Aug 2015 03:39:46 +0200 Subject: Remove superfluous redefinitions. By calling the `compat53.module` version of `coroutine.running` from the `compat53` redefinition, the `main_coroutine` value can be reused and the need for the `coroutine.status` and `coroutine.resume` redefinitions vanishes. Thanks @daurnimator! --- compat53/init.lua | 28 +++++----------------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/compat53/init.lua b/compat53/init.lua index b952003..96b6c67 100644 --- a/compat53/init.lua +++ b/compat53/init.lua @@ -206,37 +206,19 @@ if lua_version == "5.1" then end -- debug table available - local main_coroutine = coroutine_create(function() end) - if not is_luajit52 then + local coroutine_running52 = M.coroutine.running function M.coroutine.running() - local co = coroutine_running() - if co then - return pcall_mainOf[co] or co, false + local co, ismain = coroutine_running52() + if ismain then + return co, true else - return main_coroutine, true + return pcall_mainOf[co] or co, false end end end if not is_luajit then - function M.coroutine.resume(co, ...) - if co == main_coroutine then - return false, "cannot resume non-suspended coroutine" - else - return coroutine_resume(co, ...) - end - end - - function M.coroutine.status(co) - local notmain = coroutine_running() - if co == main_coroutine then - return notmain and "normal" or "running" - else - return coroutine_status(co) - end - end - local function pcall_results(current, call, success, ...) if coroutine_status(call) == "suspended" then return pcall_results(current, call, coroutine_resume(call, coroutine_yield(...))) -- cgit v1.2.3-55-g6feb