VALUE rb_struct_iv_get(VALUE c, const char *name) { ID id; id = rb_intern(name); for (;;) { if (rb_ivar_defined(c, id)) return rb_ivar_get(c, id); c = RCLASS_SUPER(c); if (c == 0 || c == rb_cStruct) return Qnil; } }
static VALUE struct_class_layout(VALUE klass) { VALUE layout; if (!rb_ivar_defined(klass, id_layout_ivar)) { rb_raise(rb_eRuntimeError, "no Struct layout configured for %s", rb_class2name(klass)); } layout = rb_ivar_get(klass, id_layout_ivar); if (!rb_obj_is_kind_of(layout, rbffi_StructLayoutClass)) { rb_raise(rb_eRuntimeError, "invalid Struct layout for %s", rb_class2name(klass)); } return layout; }
static VALUE rg_add_toggle_actions(VALUE self, VALUE rbentries) { GtkActionGroup *group = _SELF(self); VALUE toggle_action_procs = rb_ivar_defined(self, id_toggle_action_procs) == Qtrue ? rb_ivar_get(self, id_toggle_action_procs) : rb_hash_new(); long n; GtkToggleActionEntry *entries = RVAL2GTKTOGGLEACTIONENTRIES(rbentries, n, toggle_action_procs); rb_ivar_set(self, id_toggle_action_procs, toggle_action_procs); gtk_action_group_add_toggle_actions(group, entries, n, (gpointer)self); g_free(entries); return self; }
void rbgtk_initialize_gtkobject(VALUE obj, GtkObject *gtkobj) { gtkobj = g_object_ref(gtkobj); gtk_object_sink(gtkobj); G_INITIALIZE(obj, gtkobj); if (GTK_IS_WINDOW(gtkobj) || GTK_IS_MENU_SHELL(gtkobj)) { VALUE klass; klass = rb_obj_class(obj); if (rb_ivar_defined(klass, id__windows__) == Qfalse) { rb_ivar_set(klass, id__windows__, rb_hash_new()); } rb_hash_aset(rb_ivar_get(klass, id__windows__), obj, Qnil); g_signal_connect_after(gtkobj, "destroy", G_CALLBACK(remove_from_windows), (gpointer)obj); } }
SharedValue KRubyObject::Get(const char *name) { std::string iv_name = std::string("@") + name; ID iv_ID = rb_intern(iv_name.c_str()); ID get_ID = rb_intern(name); ID mm_ID = rb_intern("method_missing"); VALUE ruby_value = Qnil; if (rb_obj_respond_to(object, get_ID, Qtrue) == Qtrue) { ruby_value = rb_funcall(object, rb_intern("method"), 1, ID2SYM(get_ID)); } else if (rb_ivar_defined(object, iv_ID)) { ruby_value = rb_ivar_get(object, iv_ID); } else if (rb_obj_respond_to(object, mm_ID, Qtrue) == Qtrue) { // If this object has a method_missing, call that and return the result, int error; VALUE rargs = rb_ary_new(); rb_ary_push(rargs, object); rb_ary_push(rargs, ID2SYM(get_ID)); ruby_value = rb_protect(kobj_do_method_missing_call, rargs, &error); // protect against NoMethodErrors which we don't want to propogate // back through Kroll, but other exceptions should be thrown. VALUE exception = rb_gv_get("$!"); if (rb_obj_is_kind_of(exception, rb_eNoMethodError) == Qtrue || rb_obj_is_kind_of(exception,rb_eNameError) == Qtrue) { return Value::Undefined; } else { SharedValue exceptionValue = RubyUtils::ToKrollValue(exception); ValueException e = ValueException(exceptionValue); throw e; } } return RubyUtils::ToKrollValue(ruby_value); }
static VALUE cr_get_target (VALUE self) { cairo_surface_t *surface; VALUE rb_surface = Qnil; surface = cairo_get_target (_SELF); rb_cairo_check_status (cairo_surface_status (surface)); if (RTEST (rb_ivar_defined (self, cr_id_surface))) rb_surface = rb_ivar_get (self, cr_id_surface); if (NIL_P (rb_surface) || RVAL2CRSURFACE (rb_surface) != surface) { rb_surface = CRSURFACE2RVAL (surface); rb_ivar_set (self, cr_id_surface, rb_surface); } return rb_surface; }
static VALUE cr_initialize (VALUE self, VALUE target) { cairo_t *cr; VALUE result = Qnil; cr = cairo_create (RVAL2CRSURFACE (target)); cr_check_status (cr); rb_ivar_set (self, cr_id_surface, target); if (rb_ivar_defined (target, rb_cairo__io_id_output)) cr_set_user_data (cr, &cr_object_holder_key, cr_object_holder_new (self), cr_object_holder_free); DATA_PTR (self) = cr; if (rb_block_given_p ()) result = rb_ensure (rb_yield, self, cr_destroy_with_destroy_check, self); return result; }
VALUE rbffi_Function_ForProc(VALUE rbFunctionInfo, VALUE proc) { VALUE callback; VALUE cbTable = RTEST(rb_ivar_defined(proc, id_cbtable)) ? rb_ivar_get(proc, id_cbtable) : Qnil; if (cbTable == Qnil) { cbTable = rb_hash_new(); rb_ivar_set(proc, id_cbtable, cbTable); } callback = rb_hash_aref(cbTable, rbFunctionInfo); if (callback != Qnil) { return callback; } callback = rbffi_Function_NewInstance(rbFunctionInfo, proc); rb_hash_aset(cbTable, rbFunctionInfo, callback); return callback; }
static VALUE conv_native_type(int argc, VALUE* argv, VALUE self) { if (argc == 0) { if (!rb_ivar_defined(self, id_native_type_ivar)) { rb_raise(rb_eNotImpError, "native_type method not overridden and no native_type set"); } return rb_ivar_get(self, id_native_type_ivar); } else if (argc == 1) { VALUE type = rbffi_Type_Find(argv[0]); rb_ivar_set(self, id_native_type_ivar, type); return type; } else { rb_raise(rb_eArgError, "incorrect arguments"); } }
void rbgobj_add_relative(VALUE obj, VALUE relative) { static VALUE mGLibObject = Qnil; if (NIL_P(mGLibObject)) { mGLibObject = rb_const_get(mGLib, rb_intern("Object")); } if (rb_obj_is_kind_of(obj, mGLibObject)) { rbgobj_object_add_relative(obj, relative); } else { VALUE rb_gc_marker = Qnil; if (RVAL2CBOOL(rb_ivar_defined(obj, id_relatives))) rb_gc_marker = rb_ivar_get(obj, id_relatives); if (NIL_P(rb_gc_marker)) { rb_gc_marker = rbg_gc_marker_new(); rb_ivar_set(obj, id_relatives, rb_gc_marker); } rbg_gc_marker_guard(rb_gc_marker, relative); } }
void rbgobj_add_relative_removable(VALUE obj, VALUE relative, ID obj_ivar_id, VALUE hash_key) { static VALUE cGLibObject = Qnil; if (NIL_P(cGLibObject)) { cGLibObject = rb_const_get(mGLib, rb_intern("Object")); } if (obj_ivar_id == rbgobj_id_children && rb_obj_is_kind_of(obj, cGLibObject)) { rbgobj_object_add_relative(obj, hash_key); } else { VALUE hash = Qnil; if (RVAL2CBOOL(rb_ivar_defined(obj, obj_ivar_id))) hash = rb_ivar_get(obj, obj_ivar_id); if (NIL_P(hash) || TYPE(hash) != RUBY_T_HASH) { hash = rb_hash_new(); rb_ivar_set(obj, obj_ivar_id, hash); } rb_hash_aset(hash, hash_key, relative); } }
static VALUE object_spec_rb_ivar_defined(VALUE self, VALUE obj, VALUE sym_name) { return rb_ivar_defined(obj, SYM2ID(sym_name)); }