Forum: Ruby Using rb_str_insert from c

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F4ae9e7822cb761275aff25a0341f443?d=identicon&s=25 Phil Jackson (Guest)
on 2006-05-24 00:29
(Received via mailing list)
Hi all,

The function:

static VALUE rb_str_insert(VALUE, VALUE, VALUE)

is defined in string.c but is static and so is not avalible to me to
call
directly on my string. I have a feeling rb_funcall is my answer but I
can't
find any decent documentation on getting the functions ID.

Can anyone help?

Cheers,
Phil
47b1910084592eb77a032bc7d8d1a84e?d=identicon&s=25 Joel VanderWerf (Guest)
on 2006-05-24 00:39
(Received via mailing list)
Phil Jackson wrote:
> Can anyone help?
>
> Cheers,
> Phil

Offhand I think this will work:

id_insert = rb_intern("insert"); // you can do this once

rb_funcall(str, id_insert, 2, idx, str2);
F4ae9e7822cb761275aff25a0341f443?d=identicon&s=25 Phil Jackson (Guest)
on 2006-05-24 01:13
(Received via mailing list)
On Wed, May 24, 2006 at 07:37:21 +0900, Joel VanderWerf wrote:
>
> id_insert = rb_intern("insert"); // you can do this once
>
> rb_funcall(str, id_insert, 2, idx, str2);

You were spot-on, the mistake I was making was:

ID id = rb_intern("insert");
rb_funcall(cur_str, id, 3, cur_str, idx, str2);

Which I guess would be the Ruby equivilent of:

str.insert(str, 1, "hello world")

Thanks,
Phil
F1d6cc2b735bfd82c8773172da2aeab9?d=identicon&s=25 unknown (Guest)
on 2006-05-24 01:23
(Received via mailing list)
Hi,

At Wed, 24 May 2006 07:27:21 +0900,
Phil Jackson wrote in [ruby-talk:194275]:
> The function:
>
> static VALUE rb_str_insert(VALUE, VALUE, VALUE)
>
> is defined in string.c but is static and so is not avalible to me to call
> directly on my string. I have a feeling rb_funcall is my answer but I can't
> find any decent documentation on getting the functions ID.

If you are responsible to the arguments, rb_str_update() might
be an answer.
This topic is locked and can not be replied to.