Yoko,...

Thanks for your response, I've tried the code you sent, but it gave me an error adapter.parse NoSuchMethod. I'm using JRuby 1.2

What JRuby version are you using with this code?

Regards,..

Ahmed

Yoko Harada wrote:
Hi Ahmed,

Do you mean you got an error when you tried to run just
evalScriptlet("require 'rubygems'") ?
I didn't encounter this error on JRuby 1.3.0RC1. What's your JRuby version?
If you get the error even on JRuby 1.3.0RC1, try below. This newer way
of executing script sets null to DynamicScope when a parsing gets
started. I guess, a wrong DynamicScope was selected while parsing your
script, so you got the error while  evaluating.

import java.util.ArrayList;
import java.util.List;
import org.jruby.Ruby;
import org.jruby.RubyRuntimeAdapter;
import org.jruby.javasupport.JavaEmbedUtils;
import org.jruby.javasupport.JavaEmbedUtils.EvalUnit;

.....
.....
String jrubyhome = "<path_to_your_JRuby>";
List list = new ArrayList();
list.add(jrubyhome + "/lib/ruby/1.8");
list.add(jrubyhome + "/lib/ruby/site_ruby/1.8");
Ruby runtime = JavaEmbedUtils.initialize(list);

RubyRuntimeAdapter adapter = JavaEmbedUtils.newRuntimeAdapter();
EvalUnit unit = adapter.parse(runtime, "require 'rubygems'", "<script>", 0);
unit.run();
....

-Yoko

On Mon, May 25, 2009 at 12:47 PM, Ahmed Abdelsalam <[email protected]> wrote:
  
Hi all,...

We are developing an application that contains a JRuby interpreter running
in a thread and user interacts with the interpreter with a SWT console.
Commands are executed inside the JRuby thread using the following line:
result = runtime.evalScriptlet(scriptlet)

When I run a script starting with the following line:
require 'rubygems'

I've tried to run the same script using system console, and jirb utility
(using the same JRuby installation I used in my application), and it run
successfully with no errors !!!

However, running the same command (require 'rubygems') or even any other
require 'xxxxx' using evalScriptlet gives the below error:

 java.lang.RuntimeException: TwoVarDynamicScope only supports scopes with
two variables
java.lang.RuntimeException: TwoVarDynamicScope only supports scopes with two
variables
    at
org.jruby.runtime.scope.TwoVarDynamicScope.setValue(TwoVarDynamicScope.java:108)
    at org.jruby.ast.DAsgnNode.interpret(DAsgnNode.java:107)
    at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:101)
    at org.jruby.ast.BlockNode.interpret(BlockNode.java:67)
    at org.jruby.ast.IfNode.interpret(IfNode.java:108)
    at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:101)
    at org.jruby.ast.BlockNode.interpret(BlockNode.java:67)
    at
org.jruby.runtime.InterpretedBlock.evalBlockBody(InterpretedBlock.java:202)
    at org.jruby.runtime.InterpretedBlock.yield(InterpretedBlock.java:190)
    at org.jruby.runtime.Block.yield(Block.java:110)
    at org.jruby.ast.YieldNode.interpret(YieldNode.java:95)
    at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:101)
    at org.jruby.ast.EnsureNode.interpret(EnsureNode.java:93)
    at org.jruby.ast.BeginNode.interpret(BeginNode.java:80)
    at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:101)
    at org.jruby.ast.BlockNode.interpret(BlockNode.java:67)
    at
org.jruby.internal.runtime.methods.DefaultMethod.interpretedCall(DefaultMethod.java:163)
    at
org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:140)
    at
org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:274)
    at
org.jruby.runtime.CallSite$InlineCachingCallSite.cacheAndCall(CallSite.java:168)
    at
org.jruby.runtime.CallSite$InlineCachingCallSite.callIter(CallSite.java:425)
    at
org.jruby.ast.FCallOneArgBlockNode.interpret(FCallOneArgBlockNode.java:33)
    at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:101)
    at
org.jruby.runtime.InterpretedBlock.evalBlockBody(InterpretedBlock.java:202)
    at org.jruby.runtime.InterpretedBlock.yield(InterpretedBlock.java:190)
    at org.jruby.runtime.Block.yield(Block.java:110)
    at org.jruby.ast.YieldNode.interpret(YieldNode.java:95)
    at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:101)
    at org.jruby.ast.IfNode.interpret(IfNode.java:108)
    at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:101)
    at org.jruby.ast.BlockNode.interpret(BlockNode.java:67)
    at org.jruby.ast.RescueNode.executeBody(RescueNode.java:222)
    at
org.jruby.ast.RescueNode.interpretWithJavaExceptions(RescueNode.java:144)
    at org.jruby.ast.RescueNode.interpret(RescueNode.java:107)
    at org.jruby.ast.BeginNode.interpret(BeginNode.java:80)
    at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:101)
    at
org.jruby.runtime.InterpretedBlock.evalBlockBody(InterpretedBlock.java:202)
    at org.jruby.runtime.InterpretedBlock.yield(InterpretedBlock.java:153)
    at org.jruby.runtime.Block.yield(Block.java:105)
    at org.jruby.RubyKernel.loop(RubyKernel.java:1039)
    at
org.jruby.RubyKernel$s_method_0_0$RUBYFRAMEDINVOKER$loop.call(org/jruby/RubyKernel$s_method_0_0$RUBYFRAMEDINVOKER$loop.gen)
    at
org.jruby.runtime.CallSite$InlineCachingCallSite.cacheAndCall(CallSite.java:144)
    at
org.jruby.runtime.CallSite$InlineCachingCallSite.callIter(CallSite.java:374)
    at
org.jruby.ast.FCallNoArgBlockNode.interpret(FCallNoArgBlockNode.java:31)
    at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:101)
    at
org.jruby.runtime.InterpretedBlock.evalBlockBody(InterpretedBlock.java:202)
    at org.jruby.runtime.InterpretedBlock.yield(InterpretedBlock.java:153)
    at org.jruby.runtime.Block.yield(Block.java:105)
    at org.jruby.RubyKernel.rbCatch(RubyKernel.java:890)
    at
org.jruby.RubyKernel$s_method_1_0$RUBYFRAMEDINVOKER$rbCatch.call(org/jruby/RubyKernel$s_method_1_0$RUBYFRAMEDINVOKER$rbCatch.gen)
    at
org.jruby.runtime.CallSite$InlineCachingCallSite.cacheAndCall(CallSite.java:168)
    at
org.jruby.runtime.CallSite$InlineCachingCallSite.callIter(CallSite.java:425)
    at
org.jruby.ast.FCallOneArgBlockNode.interpret(FCallOneArgBlockNode.java:33)
    at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:101)
    at org.jruby.ast.BlockNode.interpret(BlockNode.java:67)
    at
org.jruby.internal.runtime.methods.DefaultMethod.interpretedCall(DefaultMethod.java:163)
    at
org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:140)
    at
org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:232)
    at
org.jruby.runtime.CallSite$InlineCachingCallSite.cacheAndCall(CallSite.java:144)
    at
org.jruby.runtime.CallSite$InlineCachingCallSite.call(CallSite.java:355)
    at
org.jruby.ast.CallNoArgBlockNode.interpret(CallNoArgBlockNode.java:63)
    at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:101)
    at org.jruby.ast.BlockNode.interpret(BlockNode.java:67)
    at
org.jruby.internal.runtime.methods.DefaultMethod.interpretedCall(DefaultMethod.java:163)
    at
org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:140)
    at
org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:211)
    at
org.jruby.runtime.CallSite$InlineCachingCallSite.cacheAndCall(CallSite.java:132)
    at
org.jruby.runtime.CallSite$InlineCachingCallSite.call(CallSite.java:343)
    at org.jruby.ast.CallNoArgNode.interpret(CallNoArgNode.java:61)
    at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:101)
    at
org.jruby.runtime.InterpretedBlock.evalBlockBody(InterpretedBlock.java:202)
    at org.jruby.runtime.InterpretedBlock.yield(InterpretedBlock.java:153)
    at org.jruby.runtime.Block.yield(Block.java:105)
    at org.jruby.RubyKernel.rbCatch(RubyKernel.java:890)
    at
org.jruby.RubyKernel$s_method_1_0$RUBYFRAMEDINVOKER$rbCatch.call(org/jruby/RubyKernel$s_method_1_0$RUBYFRAMEDINVOKER$rbCatch.gen)
    at
org.jruby.runtime.CallSite$InlineCachingCallSite.cacheAndCall(CallSite.java:168)
    at
org.jruby.runtime.CallSite$InlineCachingCallSite.callIter(CallSite.java:425)
    at
org.jruby.ast.FCallOneArgBlockNode.interpret(FCallOneArgBlockNode.java:33)
    at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:101)
    at org.jruby.ast.BlockNode.interpret(BlockNode.java:67)
    at
org.jruby.internal.runtime.methods.DefaultMethod.interpretedCall(DefaultMethod.java:163)
    at
org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:140)
    at
org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:211)
    at
org.jruby.runtime.CallSite$InlineCachingCallSite.cacheAndCall(CallSite.java:132)
    at
org.jruby.runtime.CallSite$InlineCachingCallSite.call(CallSite.java:343)
    at org.jruby.ast.CallNoArgNode.interpret(CallNoArgNode.java:61)
    at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:101)
    at org.jruby.ast.RootNode.interpret(RootNode.java:126)
    at org.jruby.Ruby.evalScriptlet(Ruby.java:229)



Any help?

Thanks

Ahmed
--------------------------------------------------------------------- To
unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
    

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



  

--

Regards,...

Ahmed Abdelsalam
--------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email

Reply via email to