Skip to content

Instantly share code, notes, and snippets.

@jarcode-foss
Created July 10, 2022 14:03
Show Gist options
  • Save jarcode-foss/b0e4f50afdde79feb8c799cf68128a82 to your computer and use it in GitHub Desktop.
Save jarcode-foss/b0e4f50afdde79feb8c799cf68128a82 to your computer and use it in GitHub Desktop.
exception.c
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <assert.h>
#include <luabase.h>
#include <ct.h>
static ct_scheduler frame_scheduler;
static ct_task* main_task;
static char* lua_source = "assert(pcall(function() io.open(\"doesntexist.txt\", \"r\") end) == false)";
static bool completed = false;
static void main_task_f(ct_arg task) {
CT_BEGIN(task) {
luaL_loadstring(ct_lua_state, lua_source);
if (!luaA_calltop(ct_lua_state))
abort();
completed = true;
}
}
int main(int argc, char** argv) {
luaA_entry();
ct_init(&frame_scheduler);
main_task = schedule(&frame_scheduler, main_task_f, CT_LUA, 0);
while (!completed) {
ct_enter(&frame_scheduler);
async_queue_wait_for_signal(50);
}
printf("returned from scheduler\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment