Пример #1
0
static mrb_value
scroll(mrb_state *mrb, mrb_value self)
{
  mrb_value clip, amount;
  struct PP_Rect pp_rect;
  struct PP_Point pp_point;

  mrb_get_args(mrb, "oo", &clip, &amount);
  if (mrb_obj_is_instance_of(mrb, clip, mrb_pp_rect_class)) {
    int32_t x = mrb_fixnum(mrb_funcall(mrb, clip, "x", 0));
    int32_t y = mrb_fixnum(mrb_funcall(mrb, clip, "y", 0));
    int32_t w = mrb_fixnum(mrb_funcall(mrb, clip, "width", 0));
    int32_t h = mrb_fixnum(mrb_funcall(mrb, clip, "height", 0));
    pp_rect = PP_MakeRectFromXYWH(x, y, w, h);
  }
  else {
    mrb_raisef(mrb, E_TYPE_ERROR, "%S is not a PP::Rect object", clip);
  }
  if (mrb_obj_is_instance_of(mrb, amount, mrb_pp_point_class)) {
    int32_t x = mrb_fixnum(mrb_funcall(mrb, amount, "x", 0));
    int32_t y = mrb_fixnum(mrb_funcall(mrb, amount, "y", 0));
    pp_point = PP_MakePoint(x, y);
  }
  else {
    mrb_raisef(mrb, E_TYPE_ERROR, "%S is not a PP::Point object", amount);
  }

  PPB(Graphics2D)->Scroll(MRB_PP_RESOURCE(self), &pp_rect, &pp_point);

  return mrb_nil_value();
}
Пример #2
0
static mrb_value
initialize(mrb_state *mrb, mrb_value self)
{
  struct mrb_pp_resource *graphics_2d;
  mrb_value instance, size;
  mrb_bool is_always_opaque;
  PP_Instance pp_instance = 0;
  struct PP_Size pp_size = {0, 0};

  graphics_2d = mrb_pp_resource_alloc(mrb);
  DATA_TYPE(self) = &mrb_pp_graphics_2d_type;
  DATA_PTR(self) = graphics_2d;

  mrb_get_args(mrb, "oob", &instance, &size, &is_always_opaque);
  if (mrb_obj_is_kind_of(mrb, instance, mrb_pp_instance_class)) {
    pp_instance = MRB_PP_INSTANCE(instance);
  }
  else {
    mrb_raisef(mrb, E_TYPE_ERROR, "%S is not a kind of PP::Instance", instance);
  }
  if (mrb_obj_is_instance_of(mrb, size, mrb_pp_size_class)) {
    pp_size.width = mrb_fixnum(mrb_funcall(mrb, size, "width", 0));
    pp_size.height = mrb_fixnum(mrb_funcall(mrb, size, "height", 0));
  }
  else {
    mrb_raisef(mrb, E_TYPE_ERROR, "%S is not a PP::Size object", size);
  }

  MRB_PP_RESOURCE(self) = PPB(Graphics2D)->
    Create(pp_instance, &pp_size, is_always_opaque ? PP_TRUE : PP_FALSE);
  mrb_iv_set(mrb, self, mrb_intern_lit(mrb, "size"), size);
  return self;
}
Пример #3
0
static mrb_value
mrb_uefi_pointer_initialize_copy(mrb_state *mrb, mrb_value copy)
{
    mrb_value src;
    struct MRB_UEFI_POINTER_DATA *pd;

    mrb_get_args(mrb, "o", &src);

    if (mrb_obj_equal(mrb, copy, src)){
        return copy;
    }
    if (!mrb_obj_is_instance_of(mrb, src, mrb_obj_class(mrb, copy))){
        mrb_raise(mrb, E_TYPE_ERROR, "wrong argument class");
    }
    if (DATA_PTR(copy)){
        pd = (struct MRB_UEFI_POINTER_DATA *)mrb_get_datatype(mrb, copy, &mrb_uefi_pointer_type);
    }else{
        pd = mrb_uefi_pointer_alloc(mrb, NULL);
        DATA_PTR(copy) = pd;
        DATA_TYPE(copy) = &mrb_uefi_pointer_type;
    }
    if (!pd){
        mrb_raise(mrb, E_RUNTIME_ERROR, "allocation error");
    }
    pd->pointer = ((struct MRB_UEFI_POINTER_DATA *)DATA_TYPE(src))->pointer;
    return copy;
}
Пример #4
0
mrb_value
mrb_range_eq(mrb_state *mrb, mrb_value range)
{
  struct RRange *rr;
  struct RRange *ro;
  mrb_value obj;

  mrb_get_args(mrb, "o", &obj);

  if (mrb_obj_equal(mrb, range, obj)) return mrb_true_value();

  /* same class? */
  //  if (!rb_obj_is_instance_of(obj, rb_obj_class(range)))
  if (!mrb_obj_is_instance_of(mrb, obj, mrb_obj_class(mrb, range)))
    return mrb_false_value();

  rr = mrb_range_ptr(range);
  ro = mrb_range_ptr(obj);
  if (!mrb_obj_equal(mrb, rr->edges->beg, ro->edges->beg))
    return mrb_false_value();
  if (!mrb_obj_equal(mrb, rr->edges->end, ro->edges->end))
    return mrb_false_value();
  if (rr->excl != ro->excl)
    return mrb_false_value();

  return mrb_true_value();
}
Пример #5
0
static mrb_value
paint_image_data(mrb_state *mrb, mrb_value self)
{
  mrb_value image, top_left, src_rect = mrb_nil_value();
  PP_Resource image_data = 0;
  struct PP_Point pp_point;
  struct PP_Rect pp_rect;

  mrb_get_args(mrb, "oo|o", &image, &top_left, &src_rect);
  if (mrb_obj_is_instance_of(mrb, image, mrb_pp_image_data_class)) {
    image_data = MRB_PP_RESOURCE(image);
  }
  else {
    mrb_raisef(mrb, E_TYPE_ERROR, "%S is not a PP::Image object", image);
  }
  if (mrb_obj_is_instance_of(mrb, top_left, mrb_pp_point_class)) {
    int32_t x = mrb_fixnum(mrb_funcall(mrb, top_left, "x", 0));
    int32_t y = mrb_fixnum(mrb_funcall(mrb, top_left, "y", 0));
    pp_point = PP_MakePoint(x, y);
  }
  else {
    mrb_raisef(mrb, E_TYPE_ERROR, "%S is not a PP::Point object", top_left);
  }
  if (!mrb_nil_p(src_rect)) {
    if (mrb_obj_is_instance_of(mrb, src_rect, mrb_pp_rect_class)) {
      int32_t x = mrb_fixnum(mrb_funcall(mrb, src_rect, "x", 0));
      int32_t y = mrb_fixnum(mrb_funcall(mrb, src_rect, "y", 0));
      int32_t w = mrb_fixnum(mrb_funcall(mrb, src_rect, "width", 0));
      int32_t h = mrb_fixnum(mrb_funcall(mrb, src_rect, "height", 0));
      pp_rect = PP_MakeRectFromXYWH(x, y, w, h);
    }
    else {
      mrb_raisef(mrb, E_TYPE_ERROR, "%S is not a PP::Rect object", src_rect);
    }
  }

  if (mrb_nil_p(src_rect)) {
    PPB(Graphics2D)->
      PaintImageData(MRB_PP_RESOURCE(self), image_data, &pp_point, NULL);
  }
  else {
    PPB(Graphics2D)->
      PaintImageData(MRB_PP_RESOURCE(self), image_data, &pp_point, &pp_rect);
  }

  return mrb_nil_value();
}
Пример #6
0
//----------------------------------------------------------
ofImage* BindImage::ToPtr(mrb_state* mrb, mrb_value aValue)
{
    if (!mrb_obj_is_instance_of(mrb, aValue, mrb_class_get(mrb, "Image"))) {
        mrb_raise(mrb, E_TYPE_ERROR, "wrong argument class");
    }

    return static_cast<ofImage*>(DATA_PTR(aValue));
}
Пример #7
0
Файл: kernel.c Проект: kou/mruby
/*
 *  call-seq:
 *     obj.instance_of?(class)    -> true or false
 *
 *  Returns <code>true</code> if <i>obj</i> is an instance of the given
 *  class. See also <code>Object#kind_of?</code>.
 */
static mrb_value
obj_is_instance_of(mrb_state *mrb, mrb_value self)
{
  mrb_value arg;

  mrb_get_args(mrb, "C", &arg);

  return mrb_bool_value(mrb_obj_is_instance_of(mrb, self, mrb_class_ptr(arg)));
}
Пример #8
0
static mrb_value
method_eql(mrb_state *mrb, mrb_value self)
{
  mrb_value other, receiver, orig_proc, other_proc;
  struct RClass *owner, *klass;
  struct RProc *orig_rproc, *other_rproc;

  mrb_get_args(mrb, "o", &other);
  if (!mrb_obj_is_instance_of(mrb, other, mrb_class(mrb, self)))
    return mrb_false_value();

  if (mrb_class(mrb, self) != mrb_class(mrb, other))
    return mrb_false_value();

  klass = mrb_class_ptr(IV_GET(self, "@klass"));
  if (klass != mrb_class_ptr(IV_GET(other, "@klass")))
    return mrb_false_value();

  owner = mrb_class_ptr(IV_GET(self, "@owner"));
  if (owner != mrb_class_ptr(IV_GET(other, "@owner")))
    return mrb_false_value();

  receiver = IV_GET(self, "@recv");
  if (!mrb_obj_equal(mrb, receiver, IV_GET(other, "@recv")))
    return mrb_false_value();

  orig_proc = IV_GET(self, "proc");
  other_proc = IV_GET(other, "proc");
  if (mrb_nil_p(orig_proc) && mrb_nil_p(other_proc)) {
    if (mrb_symbol(IV_GET(self, "@name")) == mrb_symbol(IV_GET(other, "@name")))
      return mrb_true_value();
    else
      return mrb_false_value();
  }

  if (mrb_nil_p(orig_proc))
    return mrb_false_value();
  if (mrb_nil_p(other_proc))
    return mrb_false_value();

  orig_rproc = mrb_proc_ptr(orig_proc);
  other_rproc = mrb_proc_ptr(other_proc);
  if (MRB_PROC_CFUNC_P(orig_rproc)) {
    if (!MRB_PROC_CFUNC_P(other_rproc))
      return mrb_false_value();
    if (orig_rproc->body.func != other_rproc->body.func)
      return mrb_false_value();
  }
  else {
    if (MRB_PROC_CFUNC_P(other_rproc))
      return mrb_false_value();
    if (orig_rproc->body.irep != other_rproc->body.irep)
      return mrb_false_value();
  }

  return mrb_true_value();
}
Пример #9
0
/*
 * Class:     org_jamruby_mruby_RClass
 * Method:    n_objIsInstanceOf
 * Signature: (JLorg/jamruby/mruby/Value;J)Z
 */
JNIEXPORT jboolean JNICALL Java_org_jamruby_mruby_RClass_n_1objIsInstanceOf
  (JNIEnv *env, jclass, jlong mrb, jobject obj, jlong c)
{
	mrb_value obj_val;
	if (!create_mrb_value(getEnv(), obj, obj_val)) {
		return JNI_FALSE;
	}
	int const &ret = mrb_obj_is_instance_of(to_ptr<mrb_state>(mrb), obj_val, to_ptr<RClass>(c));
	return (0 != ret) ? JNI_TRUE : JNI_FALSE;
}
Пример #10
0
/*
 *  call-seq:
 *     obj.instance_of?(class)    -> true or false
 *
 *  Returns <code>true</code> if <i>obj</i> is an instance of the given
 *  class. See also <code>Object#kind_of?</code>.
 */
static mrb_value
obj_is_instance_of(mrb_state *mrb, mrb_value self)
{
  mrb_value arg;

  mrb_get_args(mrb, "o", &arg);
  if (mrb_obj_is_instance_of(mrb, self, mrb_class_ptr(arg))){
    return mrb_true_value();
  }
  else {
    return mrb_false_value();
  }
}
Пример #11
0
static mrb_value
replace_contents(mrb_state *mrb, mrb_value self)
{
  mrb_value image;

  mrb_get_args(mrb, "o", &image);
  if (!mrb_obj_is_instance_of(mrb, image, mrb_pp_image_data_class)) {
    mrb_raisef(mrb, E_TYPE_ERROR, "%S is not a PP::Image object", image);
  }

  PPB(Graphics2D)->ReplaceContents(MRB_PP_RESOURCE(self), MRB_PP_RESOURCE(image));

  return mrb_nil_value();
}
Пример #12
0
static mrb_value
flush(mrb_state *mrb, mrb_value self)
{
  mrb_value cc;
  int32_t ret;

  mrb_get_args(mrb, "o", &cc);
  if (!mrb_obj_is_instance_of(mrb, cc, mrb_pp_completion_callback_class)) {
    mrb_raisef(mrb, E_TYPE_ERROR, "%S is not a PP::CompletionCallback object", cc);
  }

  ret = PPB(Graphics2D)->Flush(MRB_PP_RESOURCE(self), MRB_PP_COMPLETION_CALLBACK(cc));
  return mrb_fixnum_value(ret);
}
Пример #13
0
Файл: range.c Проект: jjue/mruby
/* 15.2.14.4.15(x) */
mrb_value
range_initialize_copy(mrb_state *mrb, mrb_value copy)
{
  mrb_value src;

  mrb_get_args(mrb, "o", &src);

  if (mrb_obj_equal(mrb, copy, src)) return copy;
  if (!mrb_obj_is_instance_of(mrb, src, mrb_obj_class(mrb, copy))) {
    mrb_raise(mrb, E_TYPE_ERROR, "wrong argument class");
  }
  *mrb_range_ptr(copy) = *mrb_range_ptr(src);

  return copy;
}
Пример #14
0
/* 15.2.14.4.15(x) */
mrb_value
range_initialize_copy(mrb_state *mrb, mrb_value copy)
{
  mrb_value src;
  mrb_get_args(mrb, "o", &src);

    if (mrb_obj_equal(mrb, copy, src)) return copy;
    //mrb_check_frozen(copy);
    if (!mrb_obj_is_instance_of(mrb, src, mrb_obj_class(mrb, copy))) {
      mrb_raise(mrb, E_TYPE_ERROR, "wrong argument class");
    }
    memcpy(mrb_range_ptr(copy), mrb_range_ptr(src), sizeof(struct RRange));

    return copy;
}
Пример #15
0
/* Initializes a copy of this time object. */
static mrb_value
mrb_time_initialize_copy(mrb_state *mrb, mrb_value copy)
{
  mrb_value src;

  mrb_get_args(mrb, "o", &src);
  if (mrb_obj_equal(mrb, copy, src)) return copy;
  if (!mrb_obj_is_instance_of(mrb, src, mrb_obj_class(mrb, copy))) {
    mrb_raise(mrb, E_TYPE_ERROR, "wrong argument class");
  }
  if (!DATA_PTR(copy)) {
    mrb_data_init(copy, mrb_malloc(mrb, sizeof(struct mrb_time)), &mrb_time_type);
  }
  *(struct mrb_time *)DATA_PTR(copy) = *(struct mrb_time *)DATA_PTR(src);
  return copy;
}
Пример #16
0
static mrb_value
pcre_regexp_initialize_copy(mrb_state *mrb, mrb_value copy) {
  mrb_value regexp;
  struct mrb_pcre_regexp *reg;

  mrb_get_args(mrb, "o", &regexp);
  if (mrb_obj_equal(mrb, copy, regexp)){
    return copy;
  }
  if (!mrb_obj_is_instance_of(mrb, regexp, mrb_obj_class(mrb, copy))){
    mrb_raise(mrb, E_TYPE_ERROR, "wrong argument class");
  }

  Data_Get_Struct(mrb, regexp, &mrb_pcre_regexp_type, reg);
  pcre_regexp_init(mrb, copy, mrb_funcall_argv(mrb, regexp, mrb_intern_lit(mrb, "source"), 0, NULL), mrb_fixnum_value(reg->flag));
  return copy;
}
Пример #17
0
static mrb_value
mrb_ipvs_service_init_copy(mrb_state *mrb, mrb_value copy)
{
  mrb_value src;

  mrb_get_args(mrb, "o", &src);
  if (mrb_obj_equal(mrb, copy, src)) return copy;
  if (!mrb_obj_is_instance_of(mrb, src, mrb_obj_class(mrb, copy))) {
    mrb_raise(mrb, E_TYPE_ERROR, "wrong argument class");
  }
  if (!DATA_PTR(copy)) {
    DATA_PTR(copy) = (struct mrb_ipvs_entry*)mrb_malloc(mrb, sizeof(struct mrb_ipvs_entry));
    DATA_TYPE(copy) = &mrb_ipvs_service_type;
  }
  *(struct mrb_ipvs_entry*)DATA_PTR(copy) = *(struct mrb_ipvs_entry*)DATA_PTR(src);
  return copy;
}
Пример #18
0
/* :nodoc: */
static mrb_value
mrb_struct_init_copy(mrb_state *mrb, mrb_value copy)
{
  mrb_value s;

  mrb_get_args(mrb, "o", &s);

  if (mrb_obj_equal(mrb, copy, s)) return copy;
  if (!mrb_obj_is_instance_of(mrb, s, mrb_obj_class(mrb, copy))) {
    mrb_raise(mrb, E_TYPE_ERROR, "wrong argument class");
  }
  if (!mrb_array_p(s)) {
    mrb_raise(mrb, E_TYPE_ERROR, "corrupted struct");
  }
  mrb_ary_replace(mrb, copy, s);
  return copy;
}
Пример #19
0
/* :nodoc: */
mrb_value
mrb_struct_init_copy(mrb_state *mrb, mrb_value copy)
{
  mrb_value s;

  mrb_get_args(mrb, "o", &s);

  if (mrb_obj_equal(mrb, copy, s)) return copy;
  if (!mrb_obj_is_instance_of(mrb, s, mrb_obj_class(mrb, copy))) {
    mrb_raise(mrb, E_TYPE_ERROR, "wrong argument class");
  }
  if (RSTRUCT_LEN(copy) != RSTRUCT_LEN(s)) {
    mrb_raise(mrb, E_TYPE_ERROR, "struct size mismatch");
  }
  memcpy(RSTRUCT_PTR(copy), RSTRUCT_PTR(s), sizeof(mrb_value)*RSTRUCT_LEN(copy));

  return copy;
}
Пример #20
0
static mrb_value
hs_regexp_initialize_copy(mrb_state *mrb, mrb_value copy)
{
    mrb_value src;
    struct mrb_hs_regexp *reg;

    mrb_get_args(mrb, "o", &src);
    if (mrb_obj_equal(mrb, copy, src)){
        return copy;
    }
    if (!mrb_obj_is_instance_of(mrb, src, mrb_obj_class(mrb, copy))){
        mrb_raise(mrb, E_TYPE_ERROR, "wrong argument class");
    }

    Data_Get_Struct(mrb, src, &mrb_hs_regexp_type, reg);
    hs_regexp_init(mrb, copy, mrb_funcall_argv(mrb, src, INTERN("source"), 0, NULL), reg->flag);
    return copy;
}
Пример #21
0
/* 15.2.14.4.15(x) */
static mrb_value
range_initialize_copy(mrb_state *mrb, mrb_value copy)
{
  mrb_value src;
  struct RRange *r;

  mrb_get_args(mrb, "o", &src);

  if (mrb_obj_equal(mrb, copy, src)) return copy;
  if (!mrb_obj_is_instance_of(mrb, src, mrb_obj_class(mrb, copy))) {
    mrb_raise(mrb, E_TYPE_ERROR, "wrong argument class");
  }

  r = mrb_range_ptr(src);
  range_init(mrb, copy, r->edges->beg, r->edges->end, r->excl);

  return copy;
}
Пример #22
0
static mrb_value
mrb_digest_init_copy(mrb_state *mrb, mrb_value copy)
{
  struct mrb_md *m1, *m2;
  mrb_value src;

  mrb_get_args(mrb, "o", &src);
  if (mrb_obj_equal(mrb, copy, src)) return copy;
  if (!mrb_obj_is_instance_of(mrb, src, mrb_obj_class(mrb, copy))) {
    mrb_raise(mrb, E_TYPE_ERROR, "wrong argument class");
  }
  if (!DATA_PTR(copy)) {
    DATA_PTR(copy) = mrb_malloc(mrb, sizeof(struct mrb_md));
    DATA_TYPE(copy) = &mrb_md_type;
  }
  m1 = DATA_PTR(src);
  m2 = DATA_PTR(copy);
  lib_md_init_copy(mrb, m2, m1);
  return copy;
}
Пример #23
0
mrb_value
mrb_range_eq(mrb_state *mrb, mrb_value range)
{
  struct RRange *rr;
  struct RRange *ro;
  mrb_value obj;

  mrb_get_args(mrb, "o", &obj);

  if (mrb_obj_equal(mrb, range, obj)) return mrb_true_value();
  if (!mrb_obj_is_instance_of(mrb, obj, mrb_obj_class(mrb, range))) { /* same class? */
    return mrb_false_value();
  }

  rr = mrb_range_ptr(range);
  ro = mrb_range_ptr(obj);
  if (!mrb_bool(mrb_funcall(mrb, rr->edges->beg, "==", 1, ro->edges->beg)) ||
      !mrb_bool(mrb_funcall(mrb, rr->edges->end, "==", 1, ro->edges->end)) ||
      rr->excl != ro->excl) {
    return mrb_false_value();
  }
  return mrb_true_value();
}
Пример #24
0
mrb_value
mrb_matchdata_init_copy(mrb_state *mrb, mrb_value copy)
{
  mrb_value src;
  struct mrb_matchdata *mrb_md_copy, *mrb_md_src;
  int vecsize;

  mrb_get_args(mrb, "o", &src);

  if (mrb_obj_equal(mrb, copy, src)) return copy;
  if (!mrb_obj_is_instance_of(mrb, src, mrb_obj_class(mrb, copy))) {
    mrb_raise(mrb, E_TYPE_ERROR, "wrong argument class");
  }

  mrb_md_copy = (struct mrb_matchdata *)mrb_malloc(mrb, sizeof(*mrb_md_copy));
  mrb_md_src  = DATA_PTR(src);

  if (mrb_md_src->ovector == NULL) {
    mrb_md_copy->ovector = NULL;
    mrb_md_copy->length = -1;
  } else {
    vecsize = sizeof(int) * mrb_md_src->length * 3;
    mrb_md_copy->ovector = mrb_malloc(mrb, vecsize);
    memcpy(mrb_md_copy->ovector, mrb_md_src->ovector, vecsize);
    mrb_md_copy->length = mrb_md_src->length;
  }

  if (DATA_PTR(copy) != NULL) {
    mrb_matchdata_free(mrb, DATA_PTR(copy));
  }
  DATA_PTR(copy) = mrb_md_copy;

  mrb_iv_set(mrb, copy, mrb_intern_lit(mrb, "@regexp"), mrb_iv_get(mrb, src, mrb_intern_lit(mrb, "@regexp")));
  mrb_iv_set(mrb, copy, mrb_intern_lit(mrb, "@string"), mrb_iv_get(mrb, src, mrb_intern_lit(mrb, "@string")));

  return copy;
}
Пример #25
0
/* :nodoc: */
mrb_value
mrb_struct_init_copy(mrb_state *mrb, mrb_value copy)
{
  mrb_value s;
  mrb_int i, len;

  mrb_get_args(mrb, "o", &s);

  if (mrb_obj_equal(mrb, copy, s)) return copy;
  if (!mrb_obj_is_instance_of(mrb, s, mrb_obj_class(mrb, copy))) {
    mrb_raise(mrb, E_TYPE_ERROR, "wrong argument class");
  }
  if (!mrb_array_p(s)) {
    mrb_raise(mrb, E_TYPE_ERROR, "corrupted struct");
  }
  if (RSTRUCT_LEN(copy) != RSTRUCT_LEN(s)) {
    mrb_raise(mrb, E_TYPE_ERROR, "struct size mismatch");
  }
  len = RSTRUCT_LEN(copy);
  for (i = 0; i < len; i++) {
    mrb_ary_set(mrb, copy, i, RSTRUCT_PTR(s)[i]);
  }
  return copy;
}