From 8d6aa06548929000d98004f5bcbb57bfd1afd4e9 Mon Sep 17 00:00:00 2001 From: Felix Jones Date: Sun, 6 Nov 2016 13:01:21 +0000 Subject: Added mrb_class_under_defined --- include/mruby.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'include/mruby.h') diff --git a/include/mruby.h b/include/mruby.h index 25514ee2c..a603a316d 100644 --- a/include/mruby.h +++ b/include/mruby.h @@ -566,6 +566,37 @@ MRB_API mrb_bool mrb_class_defined(mrb_state *mrb, const char *name); */ MRB_API struct RClass * mrb_class_get(mrb_state *mrb, const char *name); +/** + * Returns an mrb_bool. True if child class was defined, and false if the child class was not defined. + * + * Example: + * void + * mrb_example_gem_init(mrb_state* mrb) { + * struct RClass *example_parent, *example_child; + * mrb_bool cd; + * + * example_parent = mrb_define_module(mrb, "ExampleParent"); + * + * example_child = mrb_define_class(mrb, "ExampleChild", mrb->object_class); + * cd = mrb_class_under_defined(mrb, example_parent, "ExampleChild"); + * + * // If mrb_class_under_defined returns 1 then puts "True" + * // If mrb_class_under_defined returns 0 then puts "False" + * if (cd == 1){ + * puts("True"); + * } + * else { + * puts("False"); + * } + * } + * + * @param [mrb_state*] mrb The current mruby state. + * @param [struct RClass *] outer The name of the parent class. + * @param [const char *] name A string representing the name of the child class. + * @return [mrb_bool] A boolean value. + */ +MRB_API mrb_bool mrb_class_under_defined(mrb_state *mrb, struct RClass *outer, const char *name); + /** * Gets a child class. * @param [mrb_state*] mrb The current mruby state. -- cgit v1.2.3 From cc5f40b2dbcd8e0ea703e820dcf203619b5f1003 Mon Sep 17 00:00:00 2001 From: Felix Jones Date: Sun, 6 Nov 2016 13:19:14 +0000 Subject: mrb_class_under_defined docs renamed parent and child to outer and inner --- include/mruby.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'include/mruby.h') diff --git a/include/mruby.h b/include/mruby.h index a603a316d..886b15e50 100644 --- a/include/mruby.h +++ b/include/mruby.h @@ -567,18 +567,18 @@ MRB_API mrb_bool mrb_class_defined(mrb_state *mrb, const char *name); MRB_API struct RClass * mrb_class_get(mrb_state *mrb, const char *name); /** - * Returns an mrb_bool. True if child class was defined, and false if the child class was not defined. + * Returns an mrb_bool. True if inner class was defined, and false if the inner class was not defined. * * Example: * void * mrb_example_gem_init(mrb_state* mrb) { - * struct RClass *example_parent, *example_child; + * struct RClass *example_outer, *example_inner; * mrb_bool cd; * - * example_parent = mrb_define_module(mrb, "ExampleParent"); + * example_outer = mrb_define_module(mrb, "ExampleOuter"); * - * example_child = mrb_define_class(mrb, "ExampleChild", mrb->object_class); - * cd = mrb_class_under_defined(mrb, example_parent, "ExampleChild"); + * example_inner = mrb_define_class_under(mrb, example_outer, "ExampleInner", mrb->object_class); + * cd = mrb_class_under_defined(mrb, example_outer, "ExampleInner"); * * // If mrb_class_under_defined returns 1 then puts "True" * // If mrb_class_under_defined returns 0 then puts "False" @@ -591,8 +591,8 @@ MRB_API struct RClass * mrb_class_get(mrb_state *mrb, const char *name); * } * * @param [mrb_state*] mrb The current mruby state. - * @param [struct RClass *] outer The name of the parent class. - * @param [const char *] name A string representing the name of the child class. + * @param [struct RClass *] outer The name of the outer class. + * @param [const char *] name A string representing the name of the inner class. * @return [mrb_bool] A boolean value. */ MRB_API mrb_bool mrb_class_under_defined(mrb_state *mrb, struct RClass *outer, const char *name); -- cgit v1.2.3 From e3c8092ccdd3a9991ccd31634e28e9a5a0e29d91 Mon Sep 17 00:00:00 2001 From: Felix Jones Date: Thu, 10 Nov 2016 19:51:56 +0000 Subject: Renamed class_under_defined to class_defined_under --- include/mruby.h | 8 ++++---- src/class.c | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'include/mruby.h') diff --git a/include/mruby.h b/include/mruby.h index 886b15e50..1b227d41a 100644 --- a/include/mruby.h +++ b/include/mruby.h @@ -578,10 +578,10 @@ MRB_API struct RClass * mrb_class_get(mrb_state *mrb, const char *name); * example_outer = mrb_define_module(mrb, "ExampleOuter"); * * example_inner = mrb_define_class_under(mrb, example_outer, "ExampleInner", mrb->object_class); - * cd = mrb_class_under_defined(mrb, example_outer, "ExampleInner"); + * cd = mrb_class_defined_under(mrb, example_outer, "ExampleInner"); * - * // If mrb_class_under_defined returns 1 then puts "True" - * // If mrb_class_under_defined returns 0 then puts "False" + * // If mrb_class_defined_under returns 1 then puts "True" + * // If mrb_class_defined_under returns 0 then puts "False" * if (cd == 1){ * puts("True"); * } @@ -595,7 +595,7 @@ MRB_API struct RClass * mrb_class_get(mrb_state *mrb, const char *name); * @param [const char *] name A string representing the name of the inner class. * @return [mrb_bool] A boolean value. */ -MRB_API mrb_bool mrb_class_under_defined(mrb_state *mrb, struct RClass *outer, const char *name); +MRB_API mrb_bool mrb_class_defined_under(mrb_state *mrb, struct RClass *outer, const char *name); /** * Gets a child class. diff --git a/src/class.c b/src/class.c index ed2e5d5ba..b81859ab8 100644 --- a/src/class.c +++ b/src/class.c @@ -272,7 +272,7 @@ mrb_class_defined(mrb_state *mrb, const char *name) } MRB_API mrb_bool -mrb_class_under_defined(mrb_state *mrb, struct RClass *outer, const char *name) +mrb_class_defined_under(mrb_state *mrb, struct RClass *outer, const char *name) { mrb_value sym = mrb_check_intern_cstr(mrb, name); if (mrb_nil_p(sym)) { -- cgit v1.2.3