1
0
mirror of https://github.com/janet-lang/janet synced 2025-11-20 17:24:48 +00:00

Add janet_loop_fiber C function to run a fiber to completion from C.

This is mainly meant for use as the entry point to a C wrapper for a
janet program. This maeans the programmer doesn't need to use an ifdef
to handle if the event loop is enabled.
This commit is contained in:
Calvin Rose
2021-07-18 09:39:37 -05:00
parent aea1f59f6e
commit 55b8563c08
3 changed files with 22 additions and 13 deletions

View File

@@ -108,3 +108,19 @@ int janet_dostring(JanetTable *env, const char *str, const char *sourcePath, Jan
return janet_dobytes(env, (const uint8_t *)str, len, sourcePath, out);
}
/* Run a fiber to completion (use event loop if enabled). Return the status. */
int janet_loop_fiber(JanetFiber *fiber) {
int status;
#ifdef JANET_EV
janet_schedule(fiber, janet_wrap_nil());
janet_loop();
status = janet_fiber_status(fiber);
#else
Janet out;
status = janet_continue(fiber, janet_wrap_nil(), &out);
if (status != JANET_SIGNAL_OK && status != JANET_SIGNAL_EVENT) {
janet_stacktrace(fiber, out);
}
#endif
return status;
}