Skip to content

Commit b1d549a

Browse files
committed
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!
1 parent db7cb39 commit b1d549a

1 file changed

Lines changed: 5 additions & 23 deletions

File tree

compat53/init.lua

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -206,37 +206,19 @@ if lua_version == "5.1" then
206206
end -- debug table available
207207

208208

209-
local main_coroutine = coroutine_create(function() end)
210-
211209
if not is_luajit52 then
210+
local coroutine_running52 = M.coroutine.running
212211
function M.coroutine.running()
213-
local co = coroutine_running()
214-
if co then
215-
return pcall_mainOf[co] or co, false
212+
local co, ismain = coroutine_running52()
213+
if ismain then
214+
return co, true
216215
else
217-
return main_coroutine, true
216+
return pcall_mainOf[co] or co, false
218217
end
219218
end
220219
end
221220

222221
if not is_luajit then
223-
function M.coroutine.resume(co, ...)
224-
if co == main_coroutine then
225-
return false, "cannot resume non-suspended coroutine"
226-
else
227-
return coroutine_resume(co, ...)
228-
end
229-
end
230-
231-
function M.coroutine.status(co)
232-
local notmain = coroutine_running()
233-
if co == main_coroutine then
234-
return notmain and "normal" or "running"
235-
else
236-
return coroutine_status(co)
237-
end
238-
end
239-
240222
local function pcall_results(current, call, success, ...)
241223
if coroutine_status(call) == "suspended" then
242224
return pcall_results(current, call, coroutine_resume(call, coroutine_yield(...)))

0 commit comments

Comments
 (0)