Re: Running Scripted Command in separate namespaces?
Paul Landes <[email protected]> Sat, 2 Jan 2010 23:19:53 -0600
| Newsgroups | gmane.comp.java.beanshell.devel |
|---|---|
| Message-ID | <[email protected]> |
Beanshell isn't supported by the original author any longer and there
isn't any "official" maintainer any more. I do believe there is a
repository that has various patches people have applied over time
though.
That said, I think the latest (2.04b) does what you need. When
scripted methods are defined in the global namespace, yes, you're
correct. However, you can also define nested scripted methods:
bsh.XThis foo() {
print(this.namespace);
bsh.XThis bar()
print(this.namespace);
}
return this;
}
foo().bar();
Or you can run the scripted method in the namespace of your choosing,
in this case the caller's namespace:
Object eval( String expression ) {
return this.interpreter.eval( expression, this.caller.namespace );
}
This example is actually the implementation of the "eval()" command.
On Dec 30, 2009, at 2:36 PM, keith preston wrote:
> I've noticed that all scriptedCommands are executed in the Global
> Namespace. I see two problems with this:
>
> 1. Misbehaving scripts can pollute the global namespace if they have
> subfunctions or global variable in the scriptedCommand. This give
> rise to the possibility of name collisions.
> 2. In long running scripts that use lots of scriptedCommands, all of
> the compiled form of the scripted commands is kept in memory. This
> can cause a lot of extra memory to be used (possibly running out).
>
> I've actually run into both of these in my use of the Beanshell
> engine. I propose the following patch to beanshell that modifies
> scriptedCommands to run in a seperate namespace, which solves both of
> these problems.
>
>
> Keith Preston
> <
> namespacedScriptedCommands
> .patch
> >
> ------------------------------------------------------------------------------
> This SF.Net email is sponsored by the Verizon Developer Community
> Take advantage of Verizon's best-in-class app development support
> A streamlined, 14 day to market process makes app distribution fast
> and easy
> Join now and get one step closer to millions of Verizon customers
> http://p.sf.net/sfu/verizon-dev2dev
> _______________________________________________
> Beanshell-developers mailing list
> Beanshell-developers-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
> https://lists.sourceforge.net/lists/listinfo/beanshell-developers
------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev