aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Janda <siffiejoe@gmx.net>2015-08-18 03:39:46 +0200
committerPhilipp Janda <siffiejoe@gmx.net>2015-08-18 03:39:46 +0200
commitb1d549ae3ffcd5352cc5e7c05f2b434b4739160e (patch)
tree6b08410e4f3ee1ab4874cfda439c491ced054326
parentdb7cb39cdd973deca26ad96d5a478a4ba1d98f30 (diff)
downloadlua-compat-5.3-b1d549ae3ffcd5352cc5e7c05f2b434b4739160e.tar.gz
lua-compat-5.3-b1d549ae3ffcd5352cc5e7c05f2b434b4739160e.tar.bz2
lua-compat-5.3-b1d549ae3ffcd5352cc5e7c05f2b434b4739160e.zip
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!
-rw-r--r--compat53/init.lua28
1 files 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
206 end -- debug table available 206 end -- debug table available
207 207
208 208
209 local main_coroutine = coroutine_create(function() end)
210
211 if not is_luajit52 then 209 if not is_luajit52 then
210 local coroutine_running52 = M.coroutine.running
212 function M.coroutine.running() 211 function M.coroutine.running()
213 local co = coroutine_running() 212 local co, ismain = coroutine_running52()
214 if co then 213 if ismain then
215 return pcall_mainOf[co] or co, false 214 return co, true
216 else 215 else
217 return main_coroutine, true 216 return pcall_mainOf[co] or co, false
218 end 217 end
219 end 218 end
220 end 219 end
221 220
222 if not is_luajit then 221 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
240 local function pcall_results(current, call, success, ...) 222 local function pcall_results(current, call, success, ...)
241 if coroutine_status(call) == "suspended" then 223 if coroutine_status(call) == "suspended" then
242 return pcall_results(current, call, coroutine_resume(call, coroutine_yield(...))) 224 return pcall_results(current, call, coroutine_resume(call, coroutine_yield(...)))