/* * call-seq: * DescriptorPool.build(&block) * * Invokes the block with a Builder instance as self. All message and enum types * added within the block are committed to the pool atomically, and may refer * (co)recursively to each other. The user should call Builder#add_message and * Builder#add_enum within the block as appropriate. This is the recommended, * idiomatic way to define new message and enum types. */ VALUE DescriptorPool_build(VALUE _self) { VALUE ctx = rb_class_new_instance(0, NULL, cBuilder); VALUE block = rb_block_proc(); rb_funcall_with_block(ctx, rb_intern("instance_eval"), 0, NULL, block); rb_funcall(ctx, rb_intern("finalize_to_pool"), 1, _self); return Qnil; }
/* * call-seq: * Builder.add_enum(name, &block) * * Creates a new, empty enum descriptor with the given name, and invokes the block in * the context of an EnumBuilderContext on that descriptor. The block can then * call EnumBuilderContext#add_value to define the enum values. * * This is the recommended, idiomatic way to build enum definitions. */ VALUE Builder_add_enum(VALUE _self, VALUE name) { DEFINE_SELF(Builder, self, _self); VALUE enumdef = rb_class_new_instance(0, NULL, cEnumDescriptor); VALUE ctx = rb_class_new_instance(1, &enumdef, cEnumBuilderContext); VALUE block = rb_block_proc(); rb_funcall(enumdef, rb_intern("name="), 1, name); rb_funcall_with_block(ctx, rb_intern("instance_eval"), 0, NULL, block); rb_ary_push(self->pending_list, enumdef); return Qnil; }
/* * call-seq: * Builder.add_message(name, &block) * * Creates a new, empty descriptor with the given name, and invokes the block in * the context of a MessageBuilderContext on that descriptor. The block can then * call, e.g., MessageBuilderContext#optional and MessageBuilderContext#repeated * methods to define the message fields. * * This is the recommended, idiomatic way to build message definitions. */ VALUE Builder_add_message(VALUE _self, VALUE name) { DEFINE_SELF(Builder, self, _self); VALUE msgdef = rb_class_new_instance(0, NULL, cDescriptor); VALUE args[2] = { msgdef, _self }; VALUE ctx = rb_class_new_instance(2, args, cMessageBuilderContext); VALUE block = rb_block_proc(); rb_funcall(msgdef, rb_intern("name="), 1, name); rb_funcall_with_block(ctx, rb_intern("instance_eval"), 0, NULL, block); rb_ary_push(self->pending_list, msgdef); return Qnil; }
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); }); }
static VALUE kernel_spec_rb_funcall_with_block(VALUE self, VALUE obj, VALUE method, VALUE block) { return rb_funcall_with_block(obj, SYM2ID(method), 0, NULL, block); }