ajwang / groovypptest

Automatically exported from code.google.com/p/groovypptest
0 stars 0 forks source link

GroovyScriptEngine fails to compile sources referring binding-scoped variables #336

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Just try

GroovyScriptEngine gse = new GroovyScriptEngine( new URL[] { new File( 
"[directory containing greeting.cpp]"  ).toURI().toURL() } );
Binding binding = new Binding();
binding.setVariable( "greeting", "Hello world!" );
gse.run( "test.gpp", binding );

with greeting.cpp:

System.out.println( greeting );

It will fail like this:

Exception in thread "main" 
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
/C:/Users/Alfred/development/brt/standalone_scomp/src/main/resources/test.gpp: 
1: Cannot find property greeting of class test
 @ line 1, column 21.
   System.out.println( greeting );
                       ^

Original issue reported on code.google.com by varona.c...@gmail.com on 24 Jan 2011 at 5:11

GoogleCodeExporter commented 8 years ago
This is quite natural that static compiler can't find property it is not aware 
about.

Use something like 

System.out.println( getProperty("greeting") )

Original comment by alex.tka...@gmail.com on 24 Jan 2011 at 5:34

GoogleCodeExporter commented 8 years ago
Or, you may also mark your code with @Typed(TypePolicy.MIXED) and then you 
should be able to access the binding variables as you would in core groovy.

Original comment by roshanda...@gmail.com on 25 Jan 2011 at 2:38

GoogleCodeExporter commented 8 years ago
G++ behaves as designed here. Also, 2 work-arounds suggested. Ref: 
http://groups.google.com/group/groovyplusplus/browse_thread/thread/92ed13069d82f
bb1

Original comment by roshanda...@gmail.com on 6 Feb 2011 at 2:42