Closed dionys closed 6 years ago
The extension syntax
package Java::Object { import => 'java.lang.Object' };
is currently only supported in pre-compilation mode (that is, using -Cjava
).
This is in the documentation (although it could be more clear):
Java extensions are disabled inside eval-string (only plain-perl)
The direction of development for Java extensions is not clear yet.
The current plan is to do something closer to the Nashorn API, https://docs.oracle.com/javase/8/docs/technotes/guides/scripting/prog_guide/javascript.html#A1147187 but something like JRuby is also possible, https://github.com/jruby/jruby/wiki/CallingJavaFromJRuby or Jython, http://www.jython.org/jythonbook/en/1.0/JythonAndJavaIntegration.html
Alternately, it would also be possible to make the current extension syntax "official" and go ahead with the integration in eval-string
The JRuby/Jython way looks good:
use java::lang::Object;
but there are many pitfalls in the implementation (namespace conflicts, etc.).
You also may using Perl-ish way, like use if
pragma, e.g.:
use java 'java::lang::Object', as => 'Object';
I've added some more support for Java objects in the eval-string
runtime,
https://github.com/fglock/Perlito/blob/master/README-perlito5-Java.md#java-fields-methods-and-constructors
It is work-in-progress, there is no "new syntax" yet (the examples are using Java::inline
).
I think since the runtime supports the basic operations, we can experiment with several variants of the syntax.
There are some new features available: https://github.com/fglock/Perlito/blob/master/README-perlito5-Java.md#java-perl-module
Java
is a Perl module: src5/lib/Perlito5X/Java/Java.pm
Typed variables now work in eval-string:
$ jrunscript -cp . -l Perl5
perl> package Java::Object { import => 'java.lang.Object' };
import
perl> my Java::Object $obj = Java::Object->new();
Object(0x4b44655e)
Note that some restrictions apply - https://github.com/fglock/Perlito/blob/master/README-perlito5-Java.md#using-typed-variables
I have test script which imported java class:
So I try to run and got error:
But this works ok:
Configuration:
and last master.