Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #2113 > unrolled thread

Re: Method Call from inside a file.

Started byTridib Bandopadhyay <tridib04@gmail.com>
First post2011-04-01 10:44 -0500
Last post2011-04-01 17:00 -0500
Articles 4 — 2 participants

Back to article view | Back to comp.lang.ruby

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Method Call from inside a file. Tridib Bandopadhyay <tridib04@gmail.com> - 2011-04-01 10:44 -0500
    Re: Method Call from inside a file. Brian Candler <b.candler@pobox.com> - 2011-04-01 13:23 -0500
      Re: Method Call from inside a file. Tridib Bandopadhyay <tridib04@gmail.com> - 2011-04-01 13:33 -0500
        Re: Method Call from inside a file. Brian Candler <b.candler@pobox.com> - 2011-04-01 17:00 -0500

#2113 — Re: Method Call from inside a file.

FromTridib Bandopadhyay <tridib04@gmail.com>
Date2011-04-01 10:44 -0500
SubjectRe: Method Call from inside a file.
Message-ID<e0c5b4412cfe9be1068f352d3ba3824f@ruby-forum.com>
Hello

Thanks a lot it is working and giving me the desired output.

But I am little confused about two things.

1. Is the Init_Name I am declaring and calling from the ruby file, Is it 
acting like a Library function? If not, how to create a library 
function?

2. What does the require command do?


Regards

Tridib

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

[toc] | [next] | [standalone]


#2119

FromBrian Candler <b.candler@pobox.com>
Date2011-04-01 13:23 -0500
Message-ID<7823646f2514b0f079496a3719a70f72@ruby-forum.com>
In reply to#2113
Tridib Bandopadhyay wrote in post #990410:
> 1. Is the Init_Name I am declaring and calling from the ruby file, Is it
> acting like a Library function? If not, how to create a library
> function?

"Now look at the last function, Init_Test. Every class or module defines 
a C global function named Init_ Name. This function will be called when 
the interpreter first loads the extension Name (or on startup for 
statically linked extensions). It is used to initialize the extension 
and to insinuate it into the Ruby environment."

I don't know what you mean by "acting like a library function". Your 
code will be either compiled into a shared library (.so or .dll), or 
linked directly into the ruby binary, depending on how you build it. 
Init_<Name> is a publicly-accessible function, which is called by ruby 
when the module is loaded, or when the interpreter starts.

> 2. What does the require command do?

http://www.ruby-doc.org/core/classes/Kernel.html#M001418

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

[toc] | [prev] | [next] | [standalone]


#2120

FromTridib Bandopadhyay <tridib04@gmail.com>
Date2011-04-01 13:33 -0500
Message-ID<dfe49bf2701da93ea247d28df645138a@ruby-forum.com>
In reply to#2119
Brian Candler wrote in post #990438:

>
Your code will be either compiled into a shared library (.so or .dll),


Yes its getting compiled in *.so file.

> I don't know what you mean by "acting like a library function".

I mean to say that I am trying to write a function which will allow the 
users to free the allocated memory by themselves rather than doing it by 
Garbage Collection. So I need a syntax like that of C

free(variable);

So, to achieve it do I need to this above detailed thing or I have to do 
any other stuffs.

Regards

Tridib

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

[toc] | [prev] | [next] | [standalone]


#2135

FromBrian Candler <b.candler@pobox.com>
Date2011-04-01 17:00 -0500
Message-ID<b9bbd5905179d536fc41eb26e2d5eac8@ruby-forum.com>
In reply to#2120
Tridib Bandopadhyay wrote in post #990442:
>> I don't know what you mean by "acting like a library function".
>
> I mean to say that I am trying to write a function which will allow the
> users to free the allocated memory by themselves rather than doing it by
> Garbage Collection. So I need a syntax like that of C
>
> free(variable);

I believe you're writing C code for use by ruby. Ruby doesn't provide 
users with any free() method; users rely on garbage collection. So if 
you want to extend ruby in C, you need to make your code work with 
ruby's garbage collection.

A ruby user can *prevent* something from being garbage collected, if 
they want, just by holding a reference to it (e.g. in a global 
variable).

If you read 
http://www.ruby-doc.org/docs/ProgrammingRuby/html/ext_ruby.html then 
you'll find whole sections on memory allocation and garbage collection. 
Look at Data_Make_Struct and Data_Wrap_Struct in particular. If you 
won't read the documentation, then I'm afraid you're on your own.

Of course, if you're writing C to be called from C (rather than from 
ruby) then you can have people call your own allocate and free routines. 
But this is not a forum about writing C programs.

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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.ruby


csiph-web