JRuby (1.6.7.2)框架的JSR223 javax.script接口似乎忽略了ScriptContext绑定中的绑定Java值。我做错了吗?下面是一个不起作用的简单示例:
private void run() throws ScriptException {
ScriptEngine engine = new JRubyEngineFactory().getScriptEngine();
LittleClass l = new LittleClass();
engine.put("l", l);
engine.eval("l.x;");
}
public class LittleClass {
public int x;
public void add() {
x = x + 1;
}
}或者这是一个已知的问题?
发布于 2013-03-11 23:36:09
默认情况下,局部变量不会在多次求值中存活。请参阅:http://kenai.com/projects/jruby/pages/RedBridge
要更改此行为,请设置org.jruby.embed.localvariable.behavior属性:
System.setProperty("org.jruby.embed.localvariable.behavior", "persistent");
ScriptEngine engine = new JRubyEngineFactory().getScriptEngine();
LittleClass l = new LittleClass();
engine.put("l", l);
engine.eval("l.add");
System.out.println(engine.eval("l.x"));https://stackoverflow.com/questions/10786812
复制相似问题