Jump to content




Issues with coroutine.resume


  • You cannot reply to this topic
4 replies to this topic

#1 natedogith1

  • Members
  • 110 posts

Posted 12 August 2014 - 01:26 AM

Could someone explain to me why coroutine.resume(corotune.create(error)) returns true? Am I misunderstanding something in the specification?

Quote

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.


#2 0099

  • Members
  • 52 posts

Posted 12 August 2014 - 09: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.

#3 natedogith1

  • Members
  • 110 posts

Posted 13 August 2014 - 01:23 AM

View Post0099, on 12 August 2014 - 09:26 PM, said:

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)

#4 0099

  • Members
  • 52 posts

Posted 13 August 2014 - 03: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.

#5 natedogith1

  • Members
  • 110 posts

Posted 14 August 2014 - 04:45 AM

Well, that's annoying. I suppose I'll just need to wrap the function used in coroutine.create with a pcall...





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users