Feature #3731

Easier Embedding API for Ruby

Added by Beoran Aegul over 3 years ago. Updated over 1 year ago.

[ruby-core:31815]
Status:Assigned
Priority:High
Assignee:Koichi Sasada
Category:core
Target version:next minor

Description

=begin
With Ruby 1.9, it has become more difficult to embed Ruby in a C application correctly.
It would be nice if there was a clearly documented and simple C API to embed ruby in C programs.
I know Ruby was not designed from the start to be embedded, but Ruby was used before in several
products as an embedded scripting langauge. It should therefore be possible to do so in a
more straightforward way.

Kind Regards,

B.
=end


Related issues

Related to ruby-trunk - Feature #7424: an embedded Ruby interpreter doesn't get the full Ruby en... Assigned 11/23/2012

History

#1 Updated by Asher Haig over 3 years ago

=begin
What is difficult about this?

Example:

#include

int main( int argc attribute((unused)), char *argv[] attribute((unused)) ) {

ruby_init();

//  Ruby Options are just like /usr/bin/ruby
//  interpreter name, script name, argv ...
char*   options[]   =   { "", "rpdom_test.rb",  };
void*   node        =   ruby_options( 2, options );

return ruby_run_node( node );

}

Struck me as potentially a documentation issue, but the actual functionality I think is pretty straightforward?

Asher

On Aug 21, 2010, at 6:18 PM, Beoran Aegul wrote:

Feature #3731: Easier Embedding API for Ruby
http://redmine.ruby-lang.org/issues/show/3731

Author: Beoran Aegul
Status: Open, Priority: Normal

With Ruby 1.9, it has become more difficult to embed Ruby in a C application correctly.
It would be nice if there was a clearly documented and simple C API to embed ruby in C programs.
I know Ruby was not designed from the start to be embedded, but Ruby was used before in several
products as an embedded scripting langauge. It should therefore be possible to do so in a
more straightforward way.

Kind Regards,

B.


http://redmine.ruby-lang.org

=end

#2 Updated by Beoran Aegul over 3 years ago

=begin
Dear Asher,

Well, I certainly agree documentation should be improved for this use case! :)

However, the problem with what you suggest is that it doesn't work more than once.

For example; I get a segmentation violation (crash) with a "You may encounter a bug of Ruby interpreter."
on the second call to rubyrunnode();
if I try this on a ruby1.9.1 p0:

#include

RUBYGLOBALSETUP
int main( int argc attribute((unused)), char argv[] attribute((unused)) ) {
RUBYINITSTACK
ruby_init();

{
char
options[] = { "", "-e", "puts 'hello'" };
void* node = rubyoptions( 2, options );
char* options2[] = { "", "-e", "puts 'world'" };
void* node2 = ruby
options( 2, options2 );

rubyrunnode( node );
rubyrunnode( node2 );
}
}

It may be that this bug is fixed in later versions, but I still have to install them to try.

Another problem is that it's a rather unwieldy API. It's nicer if you can run multiple scripts, or call rbevalstring multiple times.
It's also nice if you can catch syntax errors in the ruby files loaded and handle them on the C side.

Kind Regards,

B.

=end

#3 Updated by Shyouhei Urabe over 3 years ago

  • Status changed from Open to Feedback

=begin

=end

#4 Updated by Hiroshi Nakamura about 2 years ago

  • Description updated (diff)
  • Category set to core
  • Status changed from Feedback to Open
  • Assignee set to Koichi Sasada
  • Target version set to 2.0.0

#5 Updated by Shyouhei Urabe about 2 years ago

  • Status changed from Open to Assigned

#6 Updated by Koichi Sasada almost 2 years ago

I'll write document for embedding Ruby on your application.
At first, in Japanese,
Second, translate in English.
Please revise it after I finished.

#7 Updated by Koichi Sasada over 1 year ago

  • Priority changed from Normal to High

Ah, sorry for pending.
I need one more body (brain?) of myself.

#8 Updated by Yusuke Endoh over 1 year ago

  • Target version changed from 2.0.0 to next minor

ko1, I think you are not divided yet.

This looks a big feature. I'm setting this to next minor.
Please try it if you have time after you finished other tasks.

Yusuke Endoh mame@tsg.ne.jp

Also available in: Atom PDF