7 Apr 2005 22:00
Re: how to access 'Variables' variable
On 7 Apr 2005, at 15:31, Gayathri Karthik wrote: > Hello All, > > Everytime i execute something ( i mean add a variable declaration and > initialize it for example) on the groovy console, i see 'Variables' > getting updated to reflect the current global variables. That looks > cool. Is there anyways i can access it in my code? It looks like a > Map.Can I directly bind functions to global scope by adding the entry > to the 'Variables' map? If you're embedding Groovy in your code you can access this from the GroovyShell. See the getContext() method http://groovy.codehaus.org/apidocs/groovy/lang/GroovyShell.html which returns a Binding http://groovy.codehaus.org/apidocs/groovy/lang/Binding.html Inside a shell script you can access the variable 'shell'. e.g. to display the variables for (e in shell.context.variables) { println "variable $e.key has value $e.value" } James ------- http://radio.weblogs.com/0112098/
RSS Feed