[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

global rb_funcall

Simon Kröger

12/26/2005 10:30:00 PM

Hi,

i'm embedding ruby into a C++, how do i call _global_ functions from C?

like

rb_funcall2(??, rb_intern("test"), 0, NULL);

thanks

Simon



3 Answers

Eero Saynatkari

12/26/2005 10:56:00 PM

0

=?ISO-8859-1?Q?Simon_Kr=F6ger?= wrote:
> Hi,
>
> i'm embedding ruby into a C++, how do i call _global_ functions from C?
>
> like
>
> rb_funcall2(??, rb_intern("test"), 0, NULL);
>
> thanks

All of the global methods become singleton methods of
the top-level Object object, so you should be able to
refer to rb_cObject (I am unable to test). If that
does not work, see if README.EXT provides any clues.

> Simon


E

--
Posted via http://www.ruby-....


Simon Kröger

12/26/2005 11:35:00 PM

0

Eero Saynatkari wrote:
> =?ISO-8859-1?Q?Simon_Kr=F6ger?= wrote:
>
>>Hi,
>>
>>i'm embedding ruby into a C++, how do i call _global_ functions from C?
>>
>>like
>>
>> rb_funcall2(??, rb_intern("test"), 0, NULL);
>>
>>thanks
>
>
> All of the global methods become singleton methods of
> the top-level Object object, so you should be able to
> refer to rb_cObject (I am unable to test). If that
> does not work, see if README.EXT provides any clues.
>
>
>>Simon
>
>
>
> E
>

I was thinking of that possibility and dismissed the thought because
"thats the class, not the object..". Well, from time to time my past
trips me up.

Thanks !

Simon


Nakada, Nobuyoshi

12/27/2005 3:51:00 AM

0

Hi,

At Tue, 27 Dec 2005 07:55:32 +0900,
Eero Saynatkari wrote in [ruby-talk:172589]:
> > i'm embedding ruby into a C++, how do i call _global_ functions from C?
> >
> > like
> >
> > rb_funcall2(??, rb_intern("test"), 0, NULL);
> >
> > thanks
>
> All of the global methods become singleton methods of
> the top-level Object object, so you should be able to
> refer to rb_cObject (I am unable to test). If that
> does not work, see if README.EXT provides any clues.

They are private instance methods of Object.

$ ruby -e 'def foo;end; p Object.private_instance_methods.grep(/foo/)'
["foo"]

So the receiver is not a matter,

rb_funcall2(Qnil, rb_intern("test"), 0, NULL);
rb_funcall2(INT2FIX(999), rb_intern("test"), 0, NULL);
rb_funcall2(rb_cArray, rb_intern("test"), 0, NULL);
rb_funcall2(rb_str_new(0, 0), rb_intern("test"), 0, NULL);
rb_funcall2(rb_ary_new(), rb_intern("test"), 0, NULL);
rb_funcall2(rb_hash_new(), rb_intern("test"), 0, NULL);
rb_funcall2(rb_module_new(), rb_intern("test"), 0, NULL);

all work.

--
Nobu Nakada