groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Assia Alexandrova <kob...@gmail.com>
Subject JSR 223 support behavior
Date Mon, 22 May 2017 04:53:20 GMT
Hi all,

My first time here. I wasn't sure weather to post this to dev list, so
please let me know if I should!

I'm trying to hook the latest Groovy interpreter to a JVM scripting
notebook environment (https://github.com/bolerio/seco). At a minimum I need
good JSR 223 support so that symbols/variables can be shared between
scripting languages. With Groovy and its built-in JSR 223 support, it seems
like an assignment:

something = 10

is placed into the common scripting context, but not a definition like this:

def something = 10

Here is a sample program reproducing the issue:

import javax.script.*;
import org.codehaus.groovy.jsr223.*;

public class TestMe
{

  public static void main(String[] args)
  {
    ScriptEngine engine = (ScriptEngine) new
GroovyScriptEngineFactory().getScriptEngine();

    try
    {
      String decl = "def something = 10";
      String stmt = "println something";
      engine.eval(decl);
      engine.eval(stmt);
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
  }
}

This yields an error: Caused by: groovy.lang.MissingPropertyException: No
such property: something for class: Script2

I played with GroovyShell a bit, passing in my own groovy.lang.Binding
implementation and indeed whenever there is a "def name = value", the
binding setVariable or setProperty are not called.

Is this a bug? If not, is there a way to get access to those symbols
introduced via 'def'. Disclaimer: I'm not a Groovy programmer, just trying
to learn enough to make this work.

Regards

Mime
View raw message