jastrachan | 22 Apr 20:14 2004
Picon

Re: Calling scripts within scripts

Currently today you need to do

GroovyShell shell = new GroovyShell()
shell.evaluate()

When we get around to adding 'modules' or 'optional class 
augmentations' (or whatever we call them) we could well have a syntax 
to 'use' helper methods like this.

http://docs.codehaus.org/display/GroovyJSR/Extending+classes

(see the comments for some interesting discussion)

On 22 Apr 2004, at 19:03, John Stump wrote:
> Hi James,
>
> I have verified that the evaluate helper you added is for the
> global context only; it does not work inside a function or
> method.
>
> Is there currently any way to evaluate a string and/or file
> within the current context, be it a method, ctor, or function?
>
> What I would like is something like this:
>
> class A {
>   x = 0
>   A() {
>     evaluate new File("my_persisted_data.gv")
>     assert x == 23
>   }
> }
>
> where my_persisted_data.gv contains:
>
> x = 23
>
>
> Thanks
>
> john
>
> --- jastrachan@... wrote:
>>
>> On 16 Apr 2004, at 15:19, Kevin Jones wrote:
>>
>>> the easiest way of doing this is via a GroovyShell.
>>>
>>> shell = new GroovyShell()
>>> shell.evaluate(new File("foo.groovy"))
>>> shell.evaluate("for (x in 1..10) { println "hello ${x}" }')
>>>
>>> Thanks James, this is just what I needed,
>>
>> Incidentally there's now a groovier way :)
>>
>> I just fixed this issue...
>>
>> http://jira.codehaus.org/secure/ViewIssue.jspa?key=GROOVY-360
>>
>> which means there's an easier way to evaluate other scripts
>> inside a
>> script
>>
>> evaluate(new File("foo.groovy"))
>>
>>
>> e.g.
>>
>> http://tinyurl.com/26ppf
>>
>> James
>> -------
>> http://radio.weblogs.com/0112098/
>>
>> _______________________________________________
>> groovy-user mailing list
>> groovy-user@...
>> http://lists.codehaus.org/mailman/listinfo/groovy-user
>
>
>
> 	
> 		
> __________________________________
> Do you Yahoo!?
> Yahoo! Photos: High-quality 4x6 digital prints for 25ยข
> http://photos.yahoo.com/ph/print_splash
> _______________________________________________
> groovy-user mailing list
> groovy-user@...
> http://lists.codehaus.org/mailman/listinfo/groovy-user
>
>

James
-------
http://radio.weblogs.com/0112098/

Gmane