You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@groovy.apache.org by Ralph Johnson <jo...@cs.uiuc.edu> on 2016/08/30 16:19:20 UTC

access to local variables in scripts

I have a system that executes scripts written by users.  I'd like to
provide more debugging tools.  In particular, I'd like to be able to
display the values of variables that the script uses.   Some of the
variables are defined outside the script, and I can access and display
them.   But the script might use  "def" to define some more variables, and
I don't know how to access them.   When a script runs, does it have some
kind of context object in which it stores temporary variables?  Is there a
way I could access it so I could read those variables?   If so, what is it
called and where could I learn more about it?

-Ralph Johnson

Re: access to local variables in scripts

Posted by Thibault Kruse <ti...@googlemail.com>.
Hi Ralph,

I think I maybe did something similar for groovysh, see here:
https://github.com/apache/groovy/blob/master/subprojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/Groovysh.groovy
In method evaluateWithStoredBoundVars()

I think this was based on some blog article by Guillaume about variable
bindings.

Hope that helps.

On Aug 31, 2016 01:19, "Ralph Johnson" <jo...@cs.uiuc.edu> wrote:

> I have a system that executes scripts written by users.  I'd like to
> provide more debugging tools.  In particular, I'd like to be able to
> display the values of variables that the script uses.   Some of the
> variables are defined outside the script, and I can access and display
> them.   But the script might use  "def" to define some more variables, and
> I don't know how to access them.   When a script runs, does it have some
> kind of context object in which it stores temporary variables?  Is there a
> way I could access it so I could read those variables?   If so, what is it
> called and where could I learn more about it?
>
> -Ralph Johnson
>