is there any possibility to build an unix library not from C/C++/…
code, but from ruby code? IOW, I need to have some functionality
“packaged” as an unix library, but I’d like to write it in Ruby and
then, somehow, compile it. Is it possible?
I need to have some functionality “packaged” as an unix library
Just write the ruby code or use what is already available.
Ruby can do the same what the unix tools can. Its just a question of
how much work to invest
but I’d like to write it in Ruby and then, somehow, compile it.
Compile ruby code? That is not really possible. It’s just .rb files.
I need to have some functionality “packaged” as an unix library
Just write the ruby code or use what is already available.
Ruby can do the same what the unix tools can. Its just a question of
how much work to invest
Unfortunately, I definitely need a library which could be easily used in
C programs (or elsewhere). A ruby script does not fit my needs.
perlembed is about embedding Perl into your programs, not libraries
and even then it’s about building a C / C++ program that can call out
perl functions, like for using Perl as a scripting language. If you
want a library that’s linked to by other programs, it has to be
written in a language that can be compiled into a static library.
Thus, you’re stuck with C / C++.
What you want, you can’t do, whether in Ruby, Perl, Lua, etc.
You can fake it by:
Creating a C library with a single function that starts up the Ruby vm
and executes installed Ruby scripts or Ruby code compiled into the
library as a giant string.
Link to that library, link to Ruby, and then call the function to
start the whole process.
Please don’t do this. If it needs to be a Unix library, just write it
in C / C++.
Not having done this, this is a shot in the dark, but…
First thing to do, is to see if you can use compiled ruby extensions
from a plain old c program.
Pick a common compiled ruby lib, and try and link to it. Maybe
digest.so? I’m pretty sure you can get this to work, but I’ve never
tried.
Now…
There are several systems out there to make it easier for you to
develop ruby code, and turn it into a c extension for ruby: rubyinline
and ruby2c come to mind (ruby2c may be slightly abandoned, but it
could still help).
This is the only way that comes to my mind to do what you want to do…
Write your library in pure ruby
Write a really good set of unit tests!
Use those tools to piecewise convert the library to a purely C ruby
extension
Make sure those unit tests still pass…
Link to that extension (probably libruby too) from your C program.
–Kyle
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.