From 27eef7094c51d77878e5054244bc0877230950a0 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Wed, 17 Oct 2018 15:19:54 -0400 Subject: [PATCH] Add JS interop to web build. --- src/webclient/main.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/webclient/main.c b/src/webclient/main.c index a30ccb2b..c705ceb7 100644 --- a/src/webclient/main.c +++ b/src/webclient/main.c @@ -51,6 +51,17 @@ static int enter_loop(void) { return 0; } +/* Allow JS interop from within janet */ +static int cfun_js(JanetArgs args) { + const uint8_t *bytes; + int32_t len; + JANET_FIXARITY(args, 1); + JANET_ARG_BYTES(bytes, len, args, 0); + (void) len; + emscripten_run_script((const char *)bytes); + JANET_RETURN_NIL(args); +} + /* Intialize the repl */ EMSCRIPTEN_KEEPALIVE void repl_init(void) { @@ -65,6 +76,10 @@ void repl_init(void) { janet_def(env, "repl-yield", janet_wrap_cfunction(repl_yield)); janet_register("repl-yield", janet_wrap_cfunction(repl_yield)); + /* Janet line getter */ + janet_def(env, "js", janet_wrap_cfunction(cfun_js)); + janet_register("js", janet_wrap_cfunction(cfun_js)); + /* Run startup script */ Janet ret; status = janet_dobytes(env, janet_gen_webinit, sizeof(janet_gen_webinit), "webinit.janet", &ret);