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

wiki/RedBridgeExamples needs to stress that container.parse() does not support local variables #513

Closed
AshwinJay opened this issue Jan 25, 2013 · 3 comments

Comments

@AshwinJay
Copy link

Local variables do not work here:

    System.out.println("[" + Test1.class.getName() + "]");

    ScriptingContainer container = new ScriptingContainer();

    EmbedEvalUnit unit = container.parse("puts \"#{a} < #{@a} ? #{a < @a}\"");

    for (int i = 0; i < 10; i++) {
        container.put("a", i * 10);
        container.put("@a", i);
        unit.run();
    }

Error:

org.jruby.exceptions.RaiseException: (NameError) undefined local variable or method `a' for #<Object:0x71b58ad1 @a=0>
    at RUBY.(root)(<script>:1)

Local variables work alright here (of course):

    System.out.println("[" + Test1.class.getName() + "]");

    ScriptingContainer container = new ScriptingContainer();

    for (int i = 0; i < 10; i++) {
        container.put("a", i * 10);
        container.put("@a", i);
        container.runScriptlet("puts \"#{a} < #{@a} ? #{a < @a}\"");
    }
@enebo
Copy link
Member

enebo commented Jan 25, 2013

We do mention this behavior on the embedding page, but it is quite a ways down. Also you can persist locals if you want to (new ScriptingContainer(LocalVariableBehavior.PERSISTENT)):

https://github.com/jruby/jruby/wiki/RedBridge#wiki-Local_Variable_Behavior_Options

Whenever someone mentions updating documentation I am at a loss in how to address this issue. It clearly tripped you up, but I am unsure what we should update to make this less confusing to others. Tell me if you think we need to change this document or do something else or I will end up closing this issue.

@AshwinJay
Copy link
Author

Thanks for the clarification. I guess a line to clarify that might help others - esp the part where vanilla.ScriptingEvalSample prints local, instance, global and constants using runScriptlet instead of eval.

Thanks. It's not really an issue, just a little confusing in the docs/wiki.

@enebo
Copy link
Member

enebo commented Jan 25, 2013

If you can review that document and perhaps figure out a better way of phrasing this we can change the document. I will close this as an issue and let you ponder an edit (I am not sure how to make this more clear).

@enebo enebo closed this as completed Jan 25, 2013
eregon added a commit that referenced this issue Dec 1, 2017
bacedc5 Exclude a couple specs not supported on Windows
7a2c8be Disable Lint/AmbiguousBlockAssociation
677c103 Fix indentation
8eb3a31 Fix trailing whitespace
b8d6e05 Suppress warnings around intended constant re-definition
0e31c13 Add RUBYOPT with extra whitespace command line spec
84e28fc Restrict the File.utime spec with large times to Linux 64-bit
47b9727 Add spec for File.utime with Time instances far in the future
421b858 Make sure to read the output of date in Kernel#open specs
baf5d11 Add spec for IO#sysread
1884b1d Add specs that IO#{read,write}_nonblock sets the IO to nonblock mode
4d60f75 Improve Time#round spec
77ba816 Improve thread local specs
240afea Add FL_ABLE and FL_TEST specs
c5bf527 Organize the Process.groups= spec
ba8700e Move the Process.groups= example under the Process.groups= spec
fb9c3a2 Fix DateTime.now spec
05b3ca1 Fix expectation in Dir#chroot spec
2ff8dc3 Add `rb_scan_args' specs for optional kwargs.
610a22f Give more margin for Mutex#sleep sleep time
3a7d4e1 Use a monotonic time to measure real-time intervals in Mutex#sleep spec
b6e9294 Specs for string issues found. Yaml test currently tagged.
de9ecda Implement rb_absint_singlebit_p and add spec
250e29a Only require fixtures needing refinements in the examples that need it
6b05eed Avoid loading a fixture using #refine while loading
c7c888a Fix IO#each spec
4cda555 Add spec for Time.{utc,gm} with small fractional usec.
12ab462 Add spec for tiny Mutex#sleep times.
6b14dca Spec for __FILE__ in BEGIN. See #4677.
3a9d651 Add spec for looped delegation of a block containing a break.
d04818f Added specs for IO#each(sep,limit) (#4833)
df0a78f Add spec for Time#to_datetime
2e1c77c Add a spec for DateTime#to_time
7e69e0a Basic constant assign specs for &&=
9089561 Make BigDecimal::limit work for subtraction and division. Fix #1615.
3041df8 Adapt sprintf/format specs to handle the 2.5 behavior for sprintf("%")
4c29047 Restore the return in class spec and specify the old and new behaviors
1da2fca Put a problematic refine spec in quarantine
7db8544 spec/ruby/optional/capi/constants_spec.rb: Data is deprecated now
85f85b4 * append newline at EOF.
ec75aa8 Add specs for concurrent Module#autoload
0fcde61 Reorganize Module#autoload to have similar specs next to each other
eef31f7 parse.y: no return in class
7f8a8b7 load from relative path to __FILE__
85562a8 Clarify what is written and read in IO#popen spec
cc7bfbd Fix spec which can fail if the pipe is closed before flushing in the subprocess
9f8d3d0 Some methods of Module are now public
f2f23ad Fix File#printf specs running on Windows
bcc750f Suppress Rubocop warnings
bc797f8 Code review. Share test cases for b and B, g and G, e and E, d, i and u formats
91ab65a Code review. Minor issues
e1d646d Remove excessive specs
b8bbe86 Adopt already existed test cases
5a30b08 Include shared example for StringIO#printf
8de650e Include shared example for String#%
19ce86a Include shared example for File#printf
b77658e Include shared example for Kernel#sprintf
1ddb415 Include shared example for Kernel#printf
764b78b Shared example: Add reference by name
acc3bdf Shared example: Add precision
b001a62 Shared example: Add width
1800767 Shared example: Add flags
f148cc7 Shared example: Add types
760a41e Add specs for Array#append [Feature #12746]
8bde28c Move Array#push specs to shared/
bc769a8 Remove superfluous spec
e32f79f Add specs for Array#prepend [Feature #12746]
ff2eb10 Move Array#unshift specs to shared/
e7ac1ca Test that the rescue in method arguments fails when not between parens
a7770da Update line number
43fe574 Remove old guard
e7598e6 Remove guards for old versions
f3599a7 Clarify which part should be undefined in defined? specs
76df3f7 Avoid defining top-level constants in TracePoint specs
e84c928 #513 Add TracePoint specs (#518)
7d76b72 Workaround Travis CI issue by hardcoding localhost
2025413 fix trailing space
f179d05 Avoid plain "should raise_error" by specifying an expected error class
6a2034c Require spec_helper should be first
2ab4d54 Pick up sibling mspec when running a spec with 'ruby' directly
214791f Fix File::Stat#blocks spec to allow zero
11a0cf2 Fix platform dependent specs for File.empty?
663d8eb Ignore the libruby check if it cannot be found
7069967 Make sure to compile each extension only once in ruby/spec
c051e55 Use ENV['RUBY_EXE'] as RbConfig.ruby might be incorrect
6b65a12 * append newline at EOF.

git-subtree-dir: spec/ruby
git-subtree-split: bacedc542c85b825f01d2698d037fad8e1c012a4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants