diff --git a/source/engine/mrbffi.c b/source/engine/mrbffi.c index 1e27a7a..baf6fff 100644 --- a/source/engine/mrbffi.c +++ b/source/engine/mrbffi.c @@ -292,6 +292,8 @@ s7_pointer s7_register(s7_scheme *sc, s7_pointer args) { int hook = s7_integer(s7_car(args)); s7_pointer sym = s7_cadr(args); + s7_gc_protect(sc, sym); + /* 0 : update */ /* 1 : gui */ /* 2 : physics */ @@ -318,11 +320,15 @@ s7_pointer s7_obregister(s7_scheme *sc, s7_pointer args) { s7_pointer sym = s7_cadr(args); s7_pointer env = s7_caddr(args); + s7_gc_protect(sc, sym); + s7_gc_protect(sc, env); + register_obupdate(env, sym); } s7_pointer s7_set_pawn(s7_scheme *sc, s7_pointer args) { s7_pointer pawn = s7_car(args); + s7_gc_protect(sc, pawn); set_pawn(pawn); return args; } diff --git a/source/engine/script.c b/source/engine/script.c index b25db81..fbd36e7 100644 --- a/source/engine/script.c +++ b/source/engine/script.c @@ -109,7 +109,13 @@ void script_eval_w_env(const char *s, s7_pointer env) { snprintf(buffer, 512-1, "(%s)", s); s7_set_current_error_port(s7, s7_open_output_function(s7, null_port)); - s7_eval_c_string_with_environment(s7, buffer, env); + + s7_pointer oldenv = s7_curlet(s7); + s7_set_curlet(s7, env); + s7_eval_c_string(s7, buffer); + s7_set_curlet(s7, oldenv); + + s7_set_current_error_port(s7, s7_open_output_function(s7, my_err)); } @@ -153,8 +159,10 @@ void call_updates(double dt) { s7_call(s7, updates[i], s7_cons(s7, s7_make_real(s7, dt), s7_nil(s7))); for (int i = 0; i < arrlen(obupdates); i++) { + s7_pointer curlet = s7_curlet(s7); s7_set_curlet(s7, obupdates[i].obj); s7_call(s7, obupdates[i].sym, s7_cons(s7, s7_make_real(s7, dt), s7_nil(s7))); + s7_set_curlet(s7, curlet); } }