groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "David Ekholm (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (GROOVY-8221) Not being able to refer to global variables via scripted methods
Date Fri, 09 Jun 2017 12:34:18 GMT

    [ https://issues.apache.org/jira/browse/GROOVY-8221?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16044373#comment-16044373
] 

David Ekholm commented on GROOVY-8221:
--------------------------------------

I appreciate if you can provide an example using traits (if that's more straight-forward than
subclassing), but most of all I'd like Groovy to support these kinds of global variables just
like BeanShell does. This is almost the last stumbling block when transitioning from BeanShell
to Groovy. The other somewhat nagging issue is that imports are forgotten between invocations
of the eval() method. That's not the case with either BeanShell or JavaScript and it's not
very groovy to have to evaluate the imports on each eval() when working interactively with
the language in a scripting console.

> Not being able to refer to global variables via scripted methods
> ----------------------------------------------------------------
>
>                 Key: GROOVY-8221
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8221
>             Project: Groovy
>          Issue Type: Bug
>          Components: GroovyScriptEngine
>    Affects Versions: 2.4.11
>         Environment: Probably not relevant, but problem at least confirmed on Mac OS
X
>            Reporter: David Ekholm
>
> We wish to switch from BeanShell to Groovy as script language (JSR-223) in our desktop
software jAlbum. jAlbum injects a set of global variables into the scriptlets via the Bindings
object of the JSR-223 API. These variables are directly accessible in simple scripts, but
contrary to scripting in BeanShell, these variables are not available to methods declared
within scripted classes.
> Here's what works (assuming that "foo" is passed to the GroovyScriptEngine via the Bindings
object):
> println(foo) // foo being made available to the magically created Script class' run method
> Here's what won't work (foo again being passed to the GroovyScriptEngine via the Bindings
object):
> class Test {
>   void bar() {
>     println(foo); // Reference to missing variable
>   }
> }
> Test t = new Test()
> t.bar() // Fails due to missing variable



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Mime
View raw message