Scoping in embedded groovy scripts
Posted
by
Aaron Digulla
on Stack Overflow
See other posts from Stack Overflow
or by Aaron Digulla
Published on 2010-11-22T12:49:07Z
Indexed on
2011/01/04
15:53 UTC
Read the original article
Hit count: 240
In my app, I use Groovy as a scripting language. To make things easier for my customers, I have a global scope where I define helper classes and constants.
Currently, I need to run the script (which builds the global scope) every time a user script is executed:
context = setupGroovy();
runScript( context, "global.groovy" ); // Can I avoid doing this step every time?
runScript( context, "user.groovy" );
Is there a way to setup this global scope once and just tell the embedded script interpreter: "Look here if you can't find a variable"? That way, I could run the global script once.
Note: Security is not an issue here but if you know a way to make sure the user can't modify the global scope, that's an additional plus.
© Stack Overflow or respective owner