summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-binding-core/src
diff options
context:
space:
mode:
authordearblue <[email protected]>2021-02-22 22:15:46 +0900
committerdearblue <[email protected]>2021-02-22 22:15:46 +0900
commit935ffa46a3a89a5f1662e5a4111ca0ed19566698 (patch)
tree4f6a25c2031db99f71ea9dc98fb71cc145503b8c /mrbgems/mruby-binding-core/src
parent297c5ac5983ee0c90b85a189ab1effc630bad617 (diff)
downloadmruby-935ffa46a3a89a5f1662e5a4111ca0ed19566698.tar.gz
mruby-935ffa46a3a89a5f1662e5a4111ca0ed19566698.zip
Change `mruby-binding` to `mruby-binding-core`
Diffstat (limited to 'mrbgems/mruby-binding-core/src')
-rw-r--r--mrbgems/mruby-binding-core/src/binding-core.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/mrbgems/mruby-binding-core/src/binding-core.c b/mrbgems/mruby-binding-core/src/binding-core.c
new file mode 100644
index 000000000..4899dcc20
--- /dev/null
+++ b/mrbgems/mruby-binding-core/src/binding-core.c
@@ -0,0 +1,46 @@
+#include "mruby.h"
+#include "mruby/array.h"
+#include "mruby/hash.h"
+#include "mruby/proc.h"
+#include "mruby/variable.h"
+
+mrb_value proc_local_variables(mrb_state *mrb, struct RProc *proc);
+
+static mrb_value
+binding_local_variables(mrb_state *mrb, mrb_value self)
+{
+ struct RProc *proc = mrb_proc_ptr(mrb_iv_get(mrb, self, mrb_intern_lit(mrb, "proc")));
+ return proc_local_variables(mrb, proc);
+}
+
+static mrb_value
+mrb_f_binding(mrb_state *mrb, mrb_value self)
+{
+ struct RObject *obj;
+ mrb_value binding;
+ struct RProc *proc;
+ mrb_int i;
+
+ obj = (struct RObject*)mrb_obj_alloc(mrb, MRB_TT_OBJECT, mrb_class_get(mrb, "Binding"));
+ binding = mrb_obj_value(obj);
+ proc = mrb->c->ci[-1].proc;
+ mrb_iv_set(mrb, binding, mrb_intern_lit(mrb, "proc"), mrb_obj_value(proc));
+ mrb_iv_set(mrb, binding, mrb_intern_lit(mrb, "recv"), self);
+ return binding;
+}
+
+void
+mrb_mruby_binding_gem_init(mrb_state *mrb)
+{
+ struct RClass *binding = mrb_define_class(mrb, "Binding", mrb->object_class);
+ mrb_undef_class_method(mrb, binding, "new");
+
+ mrb_define_method(mrb, mrb->kernel_module, "binding", mrb_f_binding, MRB_ARGS_NONE());
+
+ mrb_define_method(mrb, binding, "local_variables", binding_local_variables, MRB_ARGS_NONE());
+}
+
+void
+mrb_mruby_binding_gem_final(mrb_state *mrb)
+{
+}