How create a object inside a C

I create a simple C extension with data (allocate function, free function etc.)

How I can create a function for return new object type object in C extension.

simple I create class Foo
I need function to return Foo object from C.

Thanks
Fabian Wawrzyniec

Quoting fab1an (fab1an@onet.pl):

   I create a simple C extension with data (allocate function, free function
   etc.)
   
   How I can create a function for return new object type object in C
   extension.
   
   simple I create class Foo
   I need function to return Foo object from C.

From all Ruby-callable methods written in C, you return a variable of
type VALUE. That can include any ruby object. For example, to return
an integer, return

INT2FIX(int_vrb);

For a float use rb_float_new. For a string, use rb_str_new.

In order to create an object from C, you first get the class instance
with rb_define_class, then call the 'new' function on it with
rb_funcall.

If you study the source code of Ruby itself, it contains tons of
examples. In file

doc/extension.rdoc

there is some useful info.

Your question is not clear. Try to better describe what you are trying
to do. Best thing would be for you to include some sample code in your
question.

Carlo

···

Subject: How create a object inside a C
  Date: gio 18 gen 18 07:51:04 +0100

--
  * Se la Strada e la sua Virtu' non fossero state messe da parte,
* K * Carlo E. Prelz - fluido@fluido.as che bisogno ci sarebbe
  * di parlare tanto di amore e di rettitudine? (Chuang-Tzu)

You probably want rb_class_new_instance().

Marvin

···

Am 18. Januar 2018 um 19:51 Uhr +0100 schrieb fab1an:

simple I create class Foo
I need function to return Foo object from C.

--
Blog: https://mg.guelker.eu
PGP/GPG ID: F1D8799FBCC8BC4F