44 lines
966 B
C++
44 lines
966 B
C++
#pragma once
|
|
|
|
#include "definitions.h"
|
|
#include "pch.h"
|
|
|
|
namespace bed::internal::scripting {
|
|
struct Block {
|
|
mrb_value proc;
|
|
mrb_state *mrb;
|
|
|
|
Block(mrb_state *mrb, mrb_value proc)
|
|
: proc(proc), mrb(mrb) {
|
|
mrb_gc_register(mrb, proc);
|
|
}
|
|
|
|
Block() : proc(mrb_nil_value()) {}
|
|
|
|
~Block() {
|
|
if (!mrb_nil_p(proc))
|
|
mrb_gc_unregister(mrb, proc);
|
|
}
|
|
|
|
void set_proc(mrb_value new_proc) {
|
|
if (!mrb_nil_p(proc))
|
|
mrb_gc_unregister(mrb, proc);
|
|
proc = new_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();
|
|
mrb_value result = mrb_funcall_argv(mrb, proc, mrb_intern_cstr(mrb, "call"), argc, argv);
|
|
return result;
|
|
}
|
|
};
|
|
|
|
void register_basic(BEd &ctx);
|
|
void run(BEd &ctx, const std::string &str);
|
|
}; // namespace bed::internal::scripting
|