I'm trying to use Beanshell in a java application to execute "addon" files supplied by a user. Since the "main" code of the addon is called in a repeating loop, some addons need to use global variables initialized outside the scope of this code in order to keep track of things that require more than one loop cycle. I'm trying to do this by setting up a beanshell interpreter as
interpreter.eval("float xPositions;");
while(condition) {
interpreter.eval("xpositions++;");
}
The problem is, by the time beanshell 开发者_JS百科gets the second eval, it's forgotten that the variable exists. Is there a way to stop it doing this?
This is the way to go: interpreter.set("myVarName", myValue);
Btw: There is a bugfix version of beanshell, called beanshell2 at http://code.google.com/p/beanshell2 available.
精彩评论