Finish basic ui binding to ruby
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user