summaryrefslogtreecommitdiffhomepage
path: root/include/mruby.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/mruby.h')
-rw-r--r--include/mruby.h162
1 files changed, 152 insertions, 10 deletions
diff --git a/include/mruby.h b/include/mruby.h
index 0db9002b6..56d27a09a 100644
--- a/include/mruby.h
+++ b/include/mruby.h
@@ -243,8 +243,8 @@ MRB_API mrb_value mrb_singleton_class(mrb_state*, mrb_value);
* Include a module in another class or module.
* Equivalent to:
*
- * module B *
- * include A *
+ * module B
+ * include A
* end
* @param mrb_state* The current mruby state.
* @param RClass* A reference to module or a class.
@@ -292,17 +292,25 @@ MRB_API void mrb_define_method(mrb_state *mrb, struct RClass *cla, const char *n
* Defines a class method.
* # Ruby style
* class Foo
+ *
* def Foo.bar
* end
+ *
* end
* // C style
* mrb_value bar_method(mrb_state* mrb, mrb_value self){
+ *
* return mrb_nil_value();
+ *
* }
* void mrb_example_gem_init(mrb_state* mrb){
+ *
* struct RClass *foo;
+ *
* foo = mrb_define_class(mrb, "Foo", mrb->object_class);
- * mrb_define_class_method(mrb, foo, "bar", bar_method, MRB_ARGS_NONE());
+ *
+ * mrb_define_class_method(mrb, foo, "bar", bar_method, MRB_ARGS_NONE());
+ *
* }
* @param mrb_state* The MRuby state reference.
* @param RClass* The class where the class method will be defined.
@@ -316,17 +324,24 @@ MRB_API void mrb_define_singleton_method(mrb_state*, struct RObject*, const char
/**
* Defines a module fuction.
* # Ruby style
- * module Foo
+ * module Foo
+ *
* def Foo.bar * end
+ *
* end
* // C style
- * mrb_value bar_method(mrb_state* mrb, mrb_value self){
- * return mrb_nil_value();
+ * mrb_value bar_method(mrb_state* mrb, mrb_value self){
+ *
+ * return mrb_nil_value(); *
* }
- * void mrb_example_gem_init(mrb_state* mrb){
- * struct RClass *foo;
- * foo = mrb_define_module(mrb, "Foo");
+ * void mrb_example_gem_init(mrb_state* mrb){
+ *
+ * struct RClass *foo;
+ *
+ * foo = mrb_define_module(mrb, "Foo");
+ *
* mrb_define_module_function(mrb, foo, "bar", bar_method, MRB_ARGS_NONE());
+ *
* }
* @param mrb_state* The MRuby state reference.
* @param RClass* The module where the module function will be defined.
@@ -339,16 +354,143 @@ MRB_API void mrb_define_module_function(mrb_state*, struct RClass*, const char*,
/**
* Defines a constant.
* # Ruby style
+ *
+ * class ExampleClass
+ *
* AGE = 22
+ *
+ * end
+ *
* // C style
- * mrb_define_const(mrb, mrb->kernel_module, "AGE", mrb_fixnum_value(22));
+ * #include <stdio.h>
+ * #include <mruby.h>
+ *
+ * void
+ * mrb_example_gem_init(mrb_state* mrb){
+ *
+ * mrb_define_const(mrb, mrb->kernel_module, "AGE", mrb_fixnum_value(22));
+ *
+ * }
+ *
+ * mrb_value
+ * mrb_example_gem_final(mrb_state* mrb){
+ *
+ * }
* @param mrb_state* The MRuby state reference.
* @param RClass* A class or module the constant is defined in.
* @param name The name of the constant.
* @param mrb_value The value for the constant.
*/
MRB_API void mrb_define_const(mrb_state*, struct RClass*, const char *name, mrb_value);
+
+/**
+ * Undefines a method.
+ *
+ * # Ruby style
+ *
+ * class ExampleClassA
+ *
+ * def example_method
+ * "example"
+ * end
+ *
+ * end
+ *
+ * ExampleClassA.new.example_method # => example
+ *
+ * class ExampleClassB < ExampleClassA
+ *
+ * undef_method :example_method
+ *
+ * end
+ *
+ * ExampleClassB.new.example_method # => undefined method 'example_method' for ExampleClassB (NoMethodError)
+ *
+ * // C style
+ * #include <stdio.h>
+ * #include <mruby.h>
+ *
+ * mrb_value
+ * mrb_example_method(mrb_state *mrb){
+ *
+ * return mrb_str_new_cstr(mrb, "example");
+ *
+ * }
+ *
+ * void
+ * mrb_example_gem_init(mrb_state* mrb){
+ * struct RClass *example_class_a;
+ * struct RClass *example_class_b;
+ * struct RClass *example_class_c;
+ *
+ * example_class_a = mrb_define_class(mrb, "ExampleClassA", mrb->object_class);
+ *
+ * mrb_define_method(mrb, example_class_a, "example_method", mrb_example_method, MRB_ARGS_NONE());
+ *
+ * example_class_b = mrb_define_class(mrb, "ExampleClassB", example_class_a);
+ *
+ * example_class_c = mrb_define_class(mrb, "ExampleClassC", example_class_b);
+ *
+ * mrb_undef_method(mrb, example_class_c, "example_method");
+ *
+ * }
+ *
+ * mrb_example_gem_final(mrb_state* mrb){
+ *
+ * }
+ *
+ * @param mrb_state* The mruby state reference.
+ * @param RClass* A class the method will be undefined from.
+ * @param constchar* The name of the method to be undefined.
+ */
MRB_API void mrb_undef_method(mrb_state*, struct RClass*, const char*);
+
+/**
+ * Undefine a class method.
+ * # Ruby style
+ *
+ * class ExampleClass
+ *
+ * def self.example_method
+ * "example"
+ * end
+ *
+ * end
+ *
+ * ExampleClass.example_method
+ *
+ * // C style
+ * #include <stdio.h>
+ * #include <mruby.h>
+ *
+ * mrb_value
+ * mrb_example_method(mrb_state *mrb){
+ *
+ * return mrb_str_new_cstr(mrb, "example");
+ *
+ * }
+ *
+ * void
+ * mrb_example_gem_init(mrb_state* mrb){
+ *
+ * struct RClass *example_class;
+ *
+ * example_class = mrb_define_class(mrb, "ExampleClass", mrb->object_class);
+ *
+ * mrb_define_class_method(mrb, example_class, "example_method", mrb_example_method, MRB_ARGS_NONE());
+ *
+ * mrb_undef_class_method(mrb, example_class, "example_method");
+ *
+ * }
+ *
+ * void
+ * mrb_example_gem_final(mrb_state* mrb){
+ *
+ * }
+ * @param mrb_state* The mruby state reference.
+ * @param RClass* A class the class method will be undefined from.
+ * @param constchar* The name of the class method to be undefined.
+ */
MRB_API void mrb_undef_class_method(mrb_state*, struct RClass*, const char*);
/**