Commit d000c72b authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto

Merge pull request #2072 from take-cheeze/mrb_regexp_p

Add mrb_regexp_p.
parents 1d51d1a0 699964a8
......@@ -339,6 +339,7 @@ mrb_float_value(struct mrb_state *mrb, mrb_float f)
#define mrb_hash_p(o) (mrb_type(o) == MRB_TT_HASH)
#define mrb_cptr_p(o) (mrb_type(o) == MRB_TT_CPTR)
#define mrb_test(o) mrb_bool(o)
mrb_bool mrb_regexp_p(struct mrb_state*, mrb_value);
#define MRB_OBJECT_HEADER \
enum mrb_vtype tt:8;\
......
......@@ -65,7 +65,7 @@ noregexp(mrb_state *mrb, mrb_value self)
static void
regexp_check(mrb_state *mrb, mrb_value obj)
{
if (!memcmp(mrb_obj_classname(mrb, obj), REGEXP_CLASS, sizeof(REGEXP_CLASS) - 1)) {
if (mrb_regexp_p(mrb, obj)) {
noregexp(mrb, obj);
}
}
......
......@@ -8,6 +8,7 @@
#include "mruby/string.h"
#include "mruby/data.h"
#include "mruby/class.h"
#include "mruby/re.h"
struct RData*
mrb_data_object_alloc(mrb_state *mrb, struct RClass *klass, void *ptr, const mrb_data_type *type)
......@@ -176,3 +177,8 @@ mrb_cptr_value(mrb_state *mrb, void *p)
}
#endif /* MRB_WORD_BOXING */
mrb_bool
mrb_regexp_p(mrb_state *mrb, mrb_value v)
{
return mrb_class_defined(mrb, REGEXP_CLASS) && mrb_obj_is_kind_of(mrb, v, mrb_class_get(mrb, REGEXP_CLASS));
}
......@@ -717,7 +717,7 @@ noregexp(mrb_state *mrb, mrb_value self)
static void
regexp_check(mrb_state *mrb, mrb_value obj)
{
if (!memcmp(mrb_obj_classname(mrb, obj), REGEXP_CLASS, sizeof(REGEXP_CLASS) - 1)) {
if (mrb_regexp_p(mrb, obj)) {
noregexp(mrb, obj);
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment