cbuschka / beanshell2

Automatically exported from code.google.com/p/beanshell2
0 stars 0 forks source link

Scope support #71

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Sorry for posting this as a defect. It's actually a feature request:
I'd like the interpreter to have support for variable scopes. I'd like to be 
able set the interpreter to a new scope and to add a number of variables to 
that scope. Now the newly added variables should naturally hide any variables 
with the same name that are in "outer" scopes. when I finally drop the scope I 
added last, I want all variables bound to that scope to be dropped and any 
previously set variables with the same name to be visible again.

Is this doable?

Original issue reported on code.google.com by david@jalbum.net on 1 Jun 2012 at 11:24

GoogleCodeExporter commented 8 years ago
Create a new Interpreter with the "nested" scope (creating interpreter 
instances is cheap).

Original comment by pejob...@gmail.com on 4 Jun 2012 at 9:25

GoogleCodeExporter commented 8 years ago
Sounds great. I didn't know there was a solution. Are you able to pass me a 
small example? (not full runnable code, just the key method calls)

Original comment by david@jalbum.net on 5 Jun 2012 at 9:19

GoogleCodeExporter commented 8 years ago
I'm sorry I have to bring this issue alive again. It turns out that BeanShell2 
doesn't allow me to create arbitrary namespace chains. I'm now using multiple 
Interpreter instances, but I can't for instance construct namespace chain with 
3 nodes. It seems I'm only able to create a local/function and a global 
namespace and link them together, but I need to create three chained 
namespaces: A global namespace, a "per image" namespace and the "function" 
namespace. The API seems to allow arbitrarily chained namespaces (I can write 
the code I need) but when investigating the resulting namespace chain, it has 
been rechained to two levels only. Are you able to fix this? It would open up 
the ability to significantly accelerate album builds in jAlbum as I will then 
be able to execute multiple scripts simultaneously.

Original comment by david@jalbum.net on 3 Aug 2012 at 10:05