Exemplo n.º 1
0
static VALUE
make_curry_proc(VALUE proc, VALUE passed, VALUE arity)
{
    VALUE args = rb_ary_new3(3, proc, passed, arity);
    rb_ary_freeze(passed);
    rb_ary_freeze(args);
    return rb_proc_new(curry, args);
}
Exemplo n.º 2
0
static VALUE ludicrous_splat_iterate_proc_(VALUE val)
{
  struct Ludicrous_Splat_Iterate_Proc_Data * data =
    (struct Ludicrous_Splat_Iterate_Proc_Data *)val;

  ID varname = rb_intern("ludicrous_splat_iterate_var");

  /* Create a new scope */
  NEWOBJ(scope, struct SCOPE);
  OBJSETUP(scope, 0, T_SCOPE);
  scope->super = ruby_scope->super;
  scope->local_tbl = ALLOC_N(ID, 4);
  scope->local_vars = ALLOC_N(VALUE, 4);
  scope->flags = SCOPE_MALLOC;

  /* Set the names of the scope's local variables */
  scope->local_tbl[0] = 3;
  scope->local_tbl[1] = '_';
  scope->local_tbl[2] = '~';
  scope->local_tbl[3] = varname;

  /* And and their values */
  scope->local_vars[0] = 3;
  scope->local_vars[1] = Qnil;
  scope->local_vars[2] = Qnil;
  scope->local_vars[3] = Qnil;
  ++scope->local_vars;

  scope->local_vars[0] = ruby_scope->local_vars[0]; /* $_ */
  scope->local_vars[1] = ruby_scope->local_vars[1]; /* $~ */

  /* Temporarily set ruby_scope to the new scope, so the proc being
   * created below will pick it up (it will be set back when this
   * function returns) */
  ruby_scope = scope;

  /* Create a new proc */
  VALUE proc = rb_proc_new(
      data->body,
      data->val);

  NODE * * var;
  Data_Get_Struct(proc, NODE *, var);

  /* Set the iterator's assignment node to set a local variable that the
   * iterator's body can retrieve */
  *var = NEW_MASGN(
      0,
      NEW_NODE(
          NODE_LASGN,
          varname,
          0,
          2));

  /* And return the proc */
  return proc;
}
Exemplo n.º 3
0
WeakValueReference::WeakValueReference(RubyValue value) :
    d(std::make_shared<Data>())
{
    d->mHasValue = true;
    d->mValue = value;
    static auto objspace = RubyModule::fromPath("ObjectSpace");
    protect([&] {
        auto proc = rb_proc_new((VALUE (*)(...))&Data::finalize, Ext_AnyWrapper::create(QVariant::fromValue(d)));
        VALUE args[] = { value };
        rb_funcall_with_block(objspace, RUBYQML_INTERN("define_finalizer"), 1, args, proc);
    });
}
Exemplo n.º 4
0
static VALUE
make_curry_proc(VALUE proc, VALUE passed, VALUE arity)
{
#if WITH_OBJC
    VALUE args = rb_ary_new3(3, proc, passed, arity);
#else
    VALUE args = rb_ary_new2(3);
    RARRAY_PTR(args)[0] = proc;
    RARRAY_PTR(args)[1] = passed;
    RARRAY_PTR(args)[2] = arity;
    RARRAY_LEN(args) = 3;
#endif
    rb_ary_freeze(passed);
    rb_ary_freeze(args);
    return rb_proc_new(curry, args);
}
Exemplo n.º 5
0
// ----------------------------------------------------------------------------
VALUE RubyClassHandler::Initialize(VALUE self)
// ----------------------------------------------------------------------------
{//static called from Ruby

    // Ruby class instantiation
    // This function is called when the user issues "TuioClient.new"

    #if defined(LOGGING)
    LOGIT( "RubyClassHandler::Class Initialize self VALUE[%lu]", self);
    #endif

    // Add a finalizer to users TuioClient class that will delete the class object
    // from our array when Ruby garbage collection deletes this class object.
    VALUE mObjectSpace = rb_const_get(rb_cObject, rb_intern(_T("ObjectSpace")));
    VALUE proc = rb_proc_new((ruby_method*)&Finalizer, self);
    rb_funcall(mObjectSpace, rb_intern("define_finalizer"), 2, self, proc);

    // Add this class object to our array of Ruby objects to post events to.
    This->AddRubyObj(self);

    return self;
}
Exemplo n.º 6
0
static VALUE
yielder_new(void)
{
    return yielder_init(yielder_allocate(rb_cYielder), rb_proc_new(yielder_yield_i, 0));
}
Exemplo n.º 7
0
VALUE
rb_fiber_new(VALUE (*func)(ANYARGS), VALUE obj)
{
    return fiber_init(fiber_alloc(rb_cFiber), rb_proc_new(func, obj));
}
Exemplo n.º 8
0
VALUE sp_underline_concat_proc(VALUE self) {
    return rb_proc_new(concat_func, Qnil);
}
Exemplo n.º 9
0
static VALUE
bug_proc_make_call_super(VALUE self, VALUE procarg)
{
    return rb_proc_new(bug_proc_call_super, procarg);
}
Exemplo n.º 10
0
VALUE proc_spec_rb_proc_new(VALUE self) {
  return rb_proc_new(proc_spec_rb_proc_new_function, Qnil);
}
Exemplo n.º 11
0
Arquivo: cont.c Projeto: genki/ruby
VALUE
rb_fiber_new(VALUE (*func)(ANYARGS), VALUE obj)
{
    return fiber_new(rb_cFiber, rb_proc_new(func, obj));
}
Exemplo n.º 12
0
void
Init_cairo_font (void)
{
#if CAIRO_CHECK_VERSION(1, 7, 6)
  cr_id_call = rb_intern ("call");
  cr_id_new = rb_intern ("new");

  cr_id_init = rb_intern ("init");
  cr_id_render_glyph = rb_intern ("render_glyph");
  cr_id_text_to_glyphs = rb_intern ("text_to_glyphs");
  cr_id_unicode_to_glyph = rb_intern ("unicode_to_glyph");

  cr_id_at_glyphs = rb_intern ("@glyphs");
  cr_id_at_clusters = rb_intern ("@clusters");
  cr_id_at_cluster_flags = rb_intern ("@cluster_flags");
  cr_id_at_need_glyphs = rb_intern ("@need_glyphs");
  cr_id_at_need_clusters = rb_intern ("@need_clusters");
  cr_id_at_need_cluster_flags = rb_intern ("@need_cluster_flags");
#endif

  rb_cCairo_FontFace =
    rb_define_class_under (rb_mCairo, "FontFace", rb_cObject);
  rb_define_alloc_func (rb_cCairo_FontFace, cr_font_face_allocate);

  rb_define_singleton_method (rb_cCairo_FontFace, "quartz_supported?",
                              cr_font_face_quartz_supported_p, 0);
  rb_define_singleton_method (rb_cCairo_FontFace, "freetype_supported?",
                              cr_font_face_freetype_supported_p, 0);

#ifdef CAIRO_HAS_FT_FONT
  rb_cCairo_FreeTypeFontFace =
    rb_define_class_under (rb_mCairo, "FreeTypeFontFace", rb_cCairo_FontFace);

  {
    FT_Error error;

    error = FT_Init_FreeType (&cr_freetype_library);
    cr_freetype_error_check (error, "failed to initialize FreeType", Qnil);

    rb_define_finalizer (rb_cCairo_FreeTypeFontFace,
                         rb_proc_new (cr_freetype_done_library, Qnil));
  }

  rb_define_method (rb_cCairo_FreeTypeFontFace, "initialize",
                    cr_freetype_font_face_initialize, 1);
#endif

#if CAIRO_CHECK_VERSION(1, 7, 6)
  rb_cCairo_ToyFontFace =
    rb_define_class_under (rb_mCairo, "ToyFontFace", rb_cCairo_FontFace);

  rb_define_method (rb_cCairo_ToyFontFace, "initialize",
                    cr_toy_font_face_initialize, -1);

  rb_define_method (rb_cCairo_ToyFontFace, "family",
                    cr_toy_font_face_get_family, 0);
  rb_define_method (rb_cCairo_ToyFontFace, "slant",
                    cr_toy_font_face_get_slant, 0);
  rb_define_method (rb_cCairo_ToyFontFace, "weight",
                    cr_toy_font_face_get_weight, 0);


  rb_cCairo_UserFontFace =
    rb_define_class_under (rb_mCairo, "UserFontFace", rb_cCairo_FontFace);

  rb_define_method (rb_cCairo_UserFontFace, "initialize",
                    cr_user_font_face_initialize, 0);

  rb_define_method (rb_cCairo_UserFontFace, "on_init",
                    cr_user_font_face_on_init, 0);
  rb_define_method (rb_cCairo_UserFontFace, "on_render_glyph",
                    cr_user_font_face_on_render_glyph, 0);
  rb_define_method (rb_cCairo_UserFontFace, "on_text_to_glyphs",
                    cr_user_font_face_on_text_to_glyphs, 0);
  rb_define_method (rb_cCairo_UserFontFace, "on_unicode_to_glyph",
                    cr_user_font_face_on_unicode_to_glyph, 0);


  rb_cCairo_UserFontFace_TextToGlyphsData =
    rb_define_class_under (rb_cCairo_UserFontFace,
                           "TextToGlyphsData", rb_cObject);
  rb_attr (rb_cCairo_UserFontFace_TextToGlyphsData, rb_intern ("glyphs"),
           CR_TRUE, CR_TRUE, CR_TRUE);
  rb_attr (rb_cCairo_UserFontFace_TextToGlyphsData, rb_intern ("clusters"),
           CR_TRUE, CR_TRUE, CR_TRUE);

  rb_define_method (rb_cCairo_UserFontFace_TextToGlyphsData,
                    "initialize", cr_text_to_glyphs_data_initialize, 3);

  rb_define_method (rb_cCairo_UserFontFace_TextToGlyphsData,
                    "cluster_flags",
                    cr_text_to_glyphs_data_get_cluster_flags, 0);
  rb_define_method (rb_cCairo_UserFontFace_TextToGlyphsData,
                    "cluster_flags=",
                    cr_text_to_glyphs_data_set_cluster_flags, 1);
  rb_define_method (rb_cCairo_UserFontFace_TextToGlyphsData,
                    "need_glyphs?", cr_text_to_glyphs_data_need_glyphs, 0);
  rb_define_method (rb_cCairo_UserFontFace_TextToGlyphsData,
                    "need_clusters?", cr_text_to_glyphs_data_need_clusters, 0);
  rb_define_method (rb_cCairo_UserFontFace_TextToGlyphsData,
                    "need_cluster_flags?",
                    cr_text_to_glyphs_data_need_cluster_flags, 0);

  RB_CAIRO_DEF_SETTERS (rb_cCairo_UserFontFace_TextToGlyphsData);
#endif
}