Multiple instances of Ruby interpreter in my C++ code?

I wanted to use it in a module for an application to run (currently) very
simple scripts. The thing is that the app is multithreaded and several
instances of this module could run concurrently executing different scripts.
The scripts right now just look like this:

doSomething(x)
doSomethingElse(A_CONSTANT)

They are automatically generated but eventually I will write new ones by
hand and that’s where the flexibility of Ruby would come in handy. the calls
that are made in the scripts end up calling wrapped C/C++ functions.
If I have something like
script1: x = foo()
script2: x = bar()
I don’t want the scripts to actually share the variable x. They should be
visible only in the scope of the particular script. Maybe there’s a way of
wrapping these scripts inside a Ruby module through a preprocessor so that
they are isolated from each other?

-Thorsten

···

-----Original Message-----
From: Sean Middleditch [mailto:elanthis@awesomeplay.com]
Sent: Monday, June 10, 2002 9:49 AM
To: ruby-talk@ruby-lang.org
Subject: Re: multiple instances of Ruby interpreter in my C++ code?

Ruby makes use of a lot of global values - there is no way of doing this
in Ruby currently.

What reason do you have for wanting multiple instances? There may be
another way of accomplishing your goal(s).

On Mon, 2002-06-10 at 09:42, Thorsten Scheuermann wrote:

Hi,

I’m new to Ruby and am currently trying to embed Ruby in a C++ program. It
is pretty straightforward and I’ve already had some success with that.
However, what I really want is to have several independent instances of
the
interpreter running. Lua for example makes this easy by encapsulating the
interpreter state in a C struct, but I didn’t see that facility in Ruby.
Is
there any way to accomplish this?

-Thorsten Scheuermann

Ew, the threading will be a problem. As mad as some people on the list
may get at me for saying so, in the interest of “the best tool for the
job,” Ruby may not be your best bet if your app requires the
multi-threading.

On the other hand, Ruby itself has great threading support - you may
wish to have your app run in a single OS thread, and let the Ruby
scripts be multi-threaded?

Otherwise, of the languages I know, Lua would probably work best for
you.

···

On Mon, 2002-06-10 at 10:05, Thorsten Scheuermann wrote:

I wanted to use it in a module for an application to run (currently) very
simple scripts. The thing is that the app is multithreaded and several
instances of this module could run concurrently executing different scripts.
The scripts right now just look like this:

doSomething(x)
doSomethingElse(A_CONSTANT)

They are automatically generated but eventually I will write new ones by
hand and that’s where the flexibility of Ruby would come in handy. the calls
that are made in the scripts end up calling wrapped C/C++ functions.
If I have something like
script1: x = foo()
script2: x = bar()
I don’t want the scripts to actually share the variable x. They should be
visible only in the scope of the particular script. Maybe there’s a way of
wrapping these scripts inside a Ruby module through a preprocessor so that
they are isolated from each other?

-Thorsten

-----Original Message-----
From: Sean Middleditch [mailto:elanthis@awesomeplay.com]
Sent: Monday, June 10, 2002 9:49 AM
To: ruby-talk@ruby-lang.org
Subject: Re: multiple instances of Ruby interpreter in my C++ code?

Ruby makes use of a lot of global values - there is no way of doing this
in Ruby currently.

What reason do you have for wanting multiple instances? There may be
another way of accomplishing your goal(s).

On Mon, 2002-06-10 at 09:42, Thorsten Scheuermann wrote:

Hi,

I’m new to Ruby and am currently trying to embed Ruby in a C++ program. It
is pretty straightforward and I’ve already had some success with that.
However, what I really want is to have several independent instances of
the
interpreter running. Lua for example makes this easy by encapsulating the
interpreter state in a C struct, but I didn’t see that facility in Ruby.
Is
there any way to accomplish this?

-Thorsten Scheuermann

As Sean mentioned, right now Ruby won’t do what you want. He
recommended Lua; don’t forget about Tcl. It was meant for just
what you’re talking about.

– Dossy

···

On 2002.06.10, Thorsten Scheuermann TScheuermann@nvidia.com wrote:

I wanted to use it in a module for an application to run (currently) very
simple scripts. The thing is that the app is multithreaded and several
instances of this module could run concurrently executing different scripts.


Dossy Shiobara mail: dossy@panoptic.com
Panoptic Computer Network web: http://www.panoptic.com/
“He realized the fastest way to change is to laugh at your own
folly – then you can let go and quickly move on.” (p. 70)

I don't want the scripts to actually share the variable x. They should be
visible only in the scope of the particular script. Maybe there's a way of
wrapping these scripts inside a Ruby module through a preprocessor so that
they are isolated from each other?

If you can solve the thread problem, then load your script with

  rb_load_protect(rb_str_new2("script"), Qtrue, &state)

the script will be run in an anonymous module

Guy Decoux