Do I Have to Use a Seperate PID

Sage
Posts: 1,403
Joined: 2005.07
Post: #1
Im trying to embed the Ruby language in a program, its not thread safe and there's no useful state variable like in lua, which is what's giving me this problem.

I made a simple turtle graphics/logo type program to test it, except using ruby instead of logo of course.
My test was to have two turtles with a separate ruby interpreter, running two different scripts, also with threading so they run at the same time.

First of all I tried loading a language bundle which I created that statically linked to libruby-static.a, my code looked something like this:

Code:
bundle1 = [[NSBundle alloc] initWithPath:@"RubyLogoBinding.bundle"];
language_binding1 = [[((GenericLanguageBinding*)[bundle1 principalClass]) alloc] initWithScriptFile:@"thread1script.rb" :turtle1];

bundle2 = [[NSBundle alloc] initWithPath:@"RubyLogoBinding copy.bundle"];
language_binding2 = [[((GenericLanguageBinding*)[bundle2 principalClass]) alloc] initWithScriptFile:@"thread2script.rb" : turtle2];

then I have two buttons that call execute on language_binding1 or language_binding2.

I expected that button one would call script 1 and move turtle 1 and the second button run script 2 on turtle 2, but they both call turtle2.

I tried recompiling the RubyLogoBinding.bundle by using the actual ruby source code instead of linking to the static lib but no luck there just got the same problem.

Is there anything I can do to sort this out, I hopefully wont have to spawn a separate PID and do interprocess communication and all that because it doesn't appeal to me to say the least..
Any ideas or suggestions or anything please Smile

thanks a lot, even if you just read this far.

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
You have two choices with Ruby -- separate processes, or Ruby's own threads within a single VM.
Quote this message in a reply
Post Reply