Finish basic ui binding to ruby

This commit is contained in:
2026-05-05 11:53:27 +01:00
parent a51eb903c4
commit 1b15f51e1e
10 changed files with 536 additions and 23 deletions
+16
View File
@@ -12,10 +12,20 @@ struct Block {
Block() : proc(mrb_nil_value()) {}
void set_proc(mrb_value new_proc) {
if (!mrb_nil_p(proc))
mrb_gc_unregister(mrb, proc);
proc = new_proc;
if (!mrb_nil_p(proc))
mrb_gc_register(mrb, proc);
}
Block(const Block &) = delete;
Block &operator=(const Block &) = delete;
mrb_value call(int argc = 0, mrb_value *argv = nullptr) const {
if (mrb_nil_p(proc))
return mrb_nil_value();
return mrb_funcall(mrb, proc, "call", argc, argv);
}
@@ -23,4 +33,10 @@ struct Block {
mrb_gc_unregister(mrb, proc);
}
};
inline void run_string(const char *code, size_t length) {
int ai = mrb_gc_arena_save(mrb);
mrb_load_nstring(mrb, code, length);
mrb_gc_arena_restore(mrb, ai);
}
}; // namespace Ruby