防止 Beanshell 中的变量消失
我试图在 java 应用程序中使用 Beanshell 来执行用户提供的“addon”文件。由于插件的“主”代码是在重复循环中调用的,因此某些插件需要使用在此代码范围之外初始化的全局变量,以便跟踪需要多个循环周期的事物。我试图通过设置一个 beanshell 解释器来做到这一点,因为
interpreter.eval("float xPositions;");
while(condition) {
interpreter.eval("xpositions++;");
}
问题是,当 beanshell 获得第二个 eval 时,它忘记了该变量存在。有没有办法阻止它这样做?
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 gets the second eval, it's forgotten that the variable exists. Is there a way to stop it doing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是要走的路:interpreter.set("myVarName", myValue);
顺便说一句:beanshell 有一个错误修复版本,称为 beanshell2,位于 http://code.google.com/p/ beanshell2 可用。
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.