diff --git a/include/mruby.h b/include/mruby.h index 7a533cfa7..3ed86f8c7 100644 --- a/include/mruby.h +++ b/include/mruby.h @@ -1458,8 +1458,6 @@ MRB_API mrb_value mrb_fiber_new(mrb_state *mrb, const struct RProc *proc); * Implemented in mruby-fiber * * Switches to the specified fiber and executes. Like the `Fiber#resume` method. - * - * @note It can only be called before entering the mruby VM (e.g. in the `main()` function). */ MRB_API mrb_value mrb_fiber_resume(mrb_state *mrb, mrb_value fib, mrb_int argc, const mrb_value *argv); diff --git a/mrbgems/mruby-fiber/src/fiber.c b/mrbgems/mruby-fiber/src/fiber.c index 62bcbc301..d9718121d 100644 --- a/mrbgems/mruby-fiber/src/fiber.c +++ b/mrbgems/mruby-fiber/src/fiber.c @@ -301,19 +301,19 @@ fiber_switch(mrb_state *mrb, mrb_value self, mrb_int len, const mrb_value *a, mr * to the next Fiber.yield statement inside the fiber's block * or to the block value if it runs to completion without any * Fiber.yield - * - * This method cannot be called from C using mrb_funcall(). - * Use mrb_fiber_resume() function instead. */ static mrb_value fiber_resume(mrb_state *mrb, mrb_value self) { const mrb_value *a; mrb_int len; + mrb_bool vmexec = FALSE; - fiber_check_cfunc(mrb, mrb->c); mrb_get_args(mrb, "*!", &a, &len); - return fiber_switch(mrb, self, len, a, TRUE, FALSE); + if (mrb->c->ci->cci > 0) { + vmexec = TRUE; + } + return fiber_switch(mrb, self, len, a, TRUE, vmexec); } MRB_API mrb_value