Calling blocks and Proc objects from C: let me guess?

A

Asfand Yar Qazi

Hi,

I plan on letting the user give me Proc objects that I will execute in
response to certain events (ala Socket-Slot thingy.)

I plan on calling the Proc objects from C code. But I'm not sure how.

Here's what I've guessed at so far:
An object of type T_OBJECT will be of class rb_cProc. (lets call it 'pr')
To call it with 2 arguments, ("Hello", 8007), we do this:

if(!rb_obj_is_instance_of(pr, rb_cProc))
/* raise, etc. */
rb_funcall(pr, rb_intern("call"), 2, rb_str_new2("Hello"), INT2NUM(8007))

Is there a more efficient way?

Thanks,
Asfand Yar
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top