Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example #4 of ScriptingContainer documentation doesn't work #3043

Closed
abonas opened this issue Jun 13, 2015 · 8 comments
Closed

Example #4 of ScriptingContainer documentation doesn't work #3043

abonas opened this issue Jun 13, 2015 · 8 comments

Comments

@abonas
Copy link

abonas commented Jun 13, 2015

source:
http://jruby.org/apidocs/org/jruby/embed/ScriptingContainer.html

This example:

Example 4:
         ScriptingContainer container = new ScriptingContainer();
         script =
          "def message\n" +
              "\"message: #\"\n" +
          "end\n" +
          "message";
         container.put("@message", "What's up?");
         EvalUnit unit = container.parse(script);
         IRubyObject ret = unit.run();
         System.out.println(JavaEmbedUtils.rubyToJava(ret));
         container.put("@message", "Fabulous!");
         ret = unit.run();
         System.out.println(JavaEmbedUtils.rubyToJava(ret));
         container.put("@message", "That's the way you are.");
         ret = unit.run();
         System.out.println(JavaEmbedUtils.rubyToJava(ret));

first of all, the script variable needs a type (String)
But even after adding it, the script outputs the following:

message: #
message: #
message: #

same result also when initializing the scripting container with LocalVariableBehavior.PERSISTENT
tested with jruby 1.7.18

kares added a commit that referenced this issue Jun 14, 2015
also added a test to double-check its working as expected (due #3043)
@kares
Copy link
Member

kares commented Jun 14, 2015

improved ScriptingCotainer's javadoc based on your suggestion, but the code runs just fine.
please make sure you did not miss "message"; and also try against 1.7.20 ... should be all well

@kares kares closed this as completed Jun 14, 2015
@abonas
Copy link
Author

abonas commented Jun 14, 2015

@kares, thank you. RVM's latest jruby is 1.7.19, not 1.7.20
The rvm I have is 1.26.11, it claims to be the latest (no update available) - on rhel.

@kares
Copy link
Member

kares commented Jun 14, 2015

@abonas simply do not assume RVM to know better than us :) rvm install jruby-1.7.20 (or 1.7.20.1)

@abonas
Copy link
Author

abonas commented Jun 15, 2015

improved ScriptingCotainer's javadoc based on your suggestion, but the code runs just fine.
please make sure you did not miss "message"; and also try against 1.7.20 ... should be all well

I'm not sure what you meant by "did not miss 'message'" - but it still doesn't work with 1.7.20.
I run the example as is from the docs - copy paste it (with the fix for adding String for script var) - it prints:
message: #
message: #
message: #

@kares
Copy link
Member

kares commented Jun 15, 2015

... I meant (last line) but you mentioned you double checked your ✂️ :

          "def message\n" +
              "\"message: #\"\n" +
          "end\n" +
          "message";

hmm, that makes no sense ... works just fine as the suite runs, you mentioned RVM - could we know details about your environment and how you run these - any system properties set ?

@kares kares reopened this Jun 15, 2015
@abonas
Copy link
Author

abonas commented Jun 15, 2015

sure. OS is rhel 6.5. jruby 1.7.20, jruby installed with rvm.
I run the examples in IntelliJ, just a Java simple class with a main method, and I specifically added the jruby.jar from the 1.7.20 installation location to the project libraries in IntelliJ to make sure it takes the right one.
All needed classes get imported properly, and I see they are from the 1.7.20 jruby.jar.

@bbrowning
Copy link
Contributor

@abonas What's happening here is the rendered JavaDocs are missing some of the necessary Ruby code, which is hopefully fixed by @kares change. In the meantime, use https://github.com/jruby/jruby/blob/jruby-1_7/core/src/main/java/org/jruby/embed/ScriptingContainer.java#L156-L171 as your source for copy & pasting the code.

@abonas
Copy link
Author

abonas commented Jun 15, 2015

@bbrowning you are 100% right! copy pasting from that source did the work. thanks a lot!

@kares kares closed this as completed Jun 16, 2015
@enebo enebo added this to the Non-Release milestone Jul 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants