[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

c api, getting class

Patrick Gundlach

2/8/2006 11:43:00 AM

Hi,

q: How do I throw a custom exception in the c-part of a ruby program?


I have a mixed ruby/c class and I'd like to throw an exception that is
defined in the ruby side from the c side:


myklass.rb

class Myclass
class UnknownFormat < Exception
end
end


myklass_c.c

....
VALUE eUnknownFormatError;
eUnknownFormatError=rb_gv_get("Myclass::UnknownFormat");
rb_raise(eUnknownFormatError,"fatal: format not found");


This does not work. I have no idea how to proceed. Some small hints
would probably enough to point me in the right direction. I have seen
(pickaxe) that I can define the class in the c part with
rb_define_class(), but I want to reuse the class that is already
defined on the ruby side.

Patrick
2 Answers

Florian Frank

2/8/2006 12:14:00 PM

0

On 2006-02-08 20:43:21 +0900, Patrick Gundlach wrote:
> This does not work. I have no idea how to proceed. Some small hints
> would probably enough to point me in the right direction. I have seen
> (pickaxe) that I can define the class in the c part with
> rb_define_class(), but I want to reuse the class that is already
> defined on the ruby side.

Use rb_path2class("Myclass::UnknownFormat").

--
Florian Frank


Patrick Gundlach

2/8/2006 12:31:00 PM

0

Hello Florian,

> On 2006-02-08 20:43:21 +0900, Patrick Gundlach wrote:
>> This does not work. I have no idea how to proceed. Some small hints
>> would probably enough to point me in the right direction. I have seen
>> (pickaxe) that I can define the class in the c part with
>> rb_define_class(), but I want to reuse the class that is already
>> defined on the ruby side.
>
> Use rb_path2class("Myclass::UnknownFormat").

This is exactly what I was looking for; seems somewhat undocumented.

Thank you,

Patrick