mirror of
https://github.com/janet-lang/janet
synced 2025-06-07 00:54:12 +00:00
Add JS interop to web build.
This commit is contained in:
parent
c1923c5ada
commit
27eef7094c
@ -51,6 +51,17 @@ static int enter_loop(void) {
|
|||||||
return 0;
|
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 */
|
/* Intialize the repl */
|
||||||
EMSCRIPTEN_KEEPALIVE
|
EMSCRIPTEN_KEEPALIVE
|
||||||
void repl_init(void) {
|
void repl_init(void) {
|
||||||
@ -65,6 +76,10 @@ void repl_init(void) {
|
|||||||
janet_def(env, "repl-yield", janet_wrap_cfunction(repl_yield));
|
janet_def(env, "repl-yield", janet_wrap_cfunction(repl_yield));
|
||||||
janet_register("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 */
|
/* Run startup script */
|
||||||
Janet ret;
|
Janet ret;
|
||||||
status = janet_dobytes(env, janet_gen_webinit, sizeof(janet_gen_webinit), "webinit.janet", &ret);
|
status = janet_dobytes(env, janet_gen_webinit, sizeof(janet_gen_webinit), "webinit.janet", &ret);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user