This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
natedogith1's profile picture

Issues with coroutine.resume

Started by natedogith1, 12 August 2014 - 12:26 AM
natedogith1 #1
Posted 12 August 2014 - 02:26 AM
Could someone explain to me why coroutine.resume(corotune.create(error)) returns true? Am I misunderstanding something in the specification?

If the coroutine runs without any errors, resume returns true plus any values passed to yield (if the coroutine yields) or any values returned by the body function (if the coroutine terminates). If there is any error, resume returns false plus the error message.
0099 #2
Posted 12 August 2014 - 10:26 PM
I checked it right now, it doesn't even want to create this coroutine: bad argument #1 to 'create' (Lua function expected)
If I write a custom function

function error2(...) error(...) end
then coroutine.resume(coroutine.create(error2)) returns false.
natedogith1 #3
Posted 13 August 2014 - 02:23 AM
I checked it right now, it doesn't even want to create this coroutine: bad argument #1 to 'create' (Lua function expected)
If I write a custom function

function error2(...) error(...) end
then coroutine.resume(coroutine.create(error2)) returns false.

What lua are you doing this with? When I tried this in c-base lua 5.1 those are the results I got as well, but I got different results when running it in computercraft(which uses luaj instead of a compilation of the original source code) (both with 'error' and an actual lua function)
0099 #4
Posted 13 August 2014 - 04:50 PM
You're right. It's a bug of LuaJ, I tested it in original JuaJ 3.0 (http://sourceforge.net/projects/luaj/) and it returned true. I suppose, it's just a bug with error layers. But with a lua function I get false, then "null" and error traceback.
natedogith1 #5
Posted 14 August 2014 - 05:45 AM
Well, that's annoying. I suppose I'll just need to wrap the function used in coroutine.create with a pcall…