JSR-223 - returning value from NetRexx

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

JSR-223 - returning value from NetRexx

Dave Woodman

Hi,

 

I have an application that allows JSR-223 scripting, so, of course I promptly dropped NetRexx in and Lo! The Scripts Runneth!

 

Now all I need to do is to get a return value at the end of the script

 

At least in this environment, JavaScript does an implicit return of the last item evaluated and Groovy and Beanshell both use a return statement

 

Neither of the above seem to work for NetRexx. The eternal question is therefore about to be asked…

 

“What am I missing?”

 

Cheers,

 

                Dave.




This email has been checked for viruses by Avast antivirus software.
www.avast.com



_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: JSR-223 - returning value from NetRexx

rvjansen
I always thought that exit(x) returned a value to the caller. Will have a look.

René.


On 15 apr. 2015, at 10:54, Dave Woodman <[hidden email]> wrote:

Hi,
 
I have an application that allows JSR-223 scripting, so, of course I promptly dropped NetRexx in and Lo! The Scripts Runneth!
 
Now all I need to do is to get a return value at the end of the script
 
At least in this environment, JavaScript does an implicit return of the last item evaluated and Groovy and Beanshell both use a return statement
 
Neither of the above seem to work for NetRexx. The eternal question is therefore about to be asked…
 
“What am I missing?”
 
Cheers,
 
                Dave.



This email has been checked for viruses by Avast antivirus software. 
www.avast.com


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: JSR-223 - returning value from NetRexx

Dave Woodman

I am afraid that it does not, at least in the environment that I am using L

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of René Jansen
Sent: 15 April 2015 11:54
To: IBM Netrexx
Subject: Re: [Ibm-netrexx] JSR-223 - returning value from NetRexx

 

I always thought that exit(x) returned a value to the caller. Will have a look.

 

René.

 

 

On 15 apr. 2015, at 10:54, Dave Woodman <[hidden email]> wrote:

 

Hi,

 

I have an application that allows JSR-223 scripting, so, of course I promptly dropped NetRexx in and Lo! The Scripts Runneth!

 

Now all I need to do is to get a return value at the end of the script

 

At least in this environment, JavaScript does an implicit return of the last item evaluated and Groovy and Beanshell both use a return statement

 

Neither of the above seem to work for NetRexx. The eternal question is therefore about to be asked…

 

“What am I missing?”

 

Cheers,

 

                Dave.



This email has been checked for viruses by Avast antivirus software. 
www.avast.com


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : 
http://ibm-netrexx.215625.n3.nabble.com/

 




This email has been checked for viruses by Avast antivirus software.
www.avast.com



_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: JSR-223 - returning value from NetRexx

rvjansen
Dave, 

I can reproduce it. 

import javax.script.

nrEngine = ScriptEngineManager().getEngineByName("NetRexx")

/* check returncode */
say nrEngine.eval('exit 99')




yields a blank.

Thanks for mentioning this before 3.04 comes out - and not just after the release. Would you be so kind as to enter it as a problem in https://kenai.com/jira/browse/NETREXX ?

Will try to solve it quickly so it can go into the release.

best regards,

René.




On 15 apr. 2015, at 13:47, Dave Woodman <[hidden email]> wrote:

I am afraid that it does not, at least in the environment that I am using L
 
From: [hidden email] [[hidden email]] On Behalf Of René Jansen
Sent: 15 April 2015 11:54
To: IBM Netrexx
Subject: Re: [Ibm-netrexx] JSR-223 - returning value from NetRexx
 
I always thought that exit(x) returned a value to the caller. Will have a look.
 
René.
 
 
On 15 apr. 2015, at 10:54, Dave Woodman <[hidden email]> wrote:
 
Hi,
 
I have an application that allows JSR-223 scripting, so, of course I promptly dropped NetRexx in and Lo! The Scripts Runneth!
 
Now all I need to do is to get a return value at the end of the script
 
At least in this environment, JavaScript does an implicit return of the last item evaluated and Groovy and Beanshell both use a return statement
 
Neither of the above seem to work for NetRexx. The eternal question is therefore about to be asked…
 
“What am I missing?”
 
Cheers,
 
                Dave.



This email has been checked for viruses by Avast antivirus software. 
www.avast.com

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : 
http://ibm-netrexx.215625.n3.nabble.com/
 



This email has been checked for viruses by Avast antivirus software. 
www.avast.com


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: JSR-223 - returning value from NetRexx

Dave Woodman

NETREXX-116 has been created.

 

Cheers,

               Dave.

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of René Jansen
Sent: 15 April 2015 13:02
To: IBM Netrexx
Subject: Re: [Ibm-netrexx] JSR-223 - returning value from NetRexx

 

Dave, 

 

I can reproduce it. 

 

import javax.script.

 

nrEngine = ScriptEngineManager().getEngineByName("NetRexx")

 

/* check returncode */

say nrEngine.eval('exit 99')

 

 

 

 

yields a blank.

 

Thanks for mentioning this before 3.04 comes out - and not just after the release. Would you be so kind as to enter it as a problem in https://kenai.com/jira/browse/NETREXX ?

 

Will try to solve it quickly so it can go into the release.

 

best regards,

 

René.

 

 

 

 

On 15 apr. 2015, at 13:47, Dave Woodman <[hidden email]> wrote:

 

I am afraid that it does not, at least in the environment that I am using L

 

From: [hidden email] [[hidden email]] On Behalf Of René Jansen
Sent: 15 April 2015 11:54
To: IBM Netrexx
Subject: Re: [Ibm-netrexx] JSR-223 - returning value from NetRexx

 

I always thought that exit(x) returned a value to the caller. Will have a look.

 

René.

 

 

On 15 apr. 2015, at 10:54, Dave Woodman <[hidden email]> wrote:

 

Hi,

 

I have an application that allows JSR-223 scripting, so, of course I promptly dropped NetRexx in and Lo! The Scripts Runneth!

 

Now all I need to do is to get a return value at the end of the script

 

At least in this environment, JavaScript does an implicit return of the last item evaluated and Groovy and Beanshell both use a return statement

 

Neither of the above seem to work for NetRexx. The eternal question is therefore about to be asked…

 

“What am I missing?”

 

Cheers,

 

                Dave.




This email has been checked for viruses by Avast antivirus software. 
www.avast.com


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : 
http://ibm-netrexx.215625.n3.nabble.com/

 



This email has been checked for viruses by Avast antivirus software. 
www.avast.com


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : 
http://ibm-netrexx.215625.n3.nabble.com/

 




This email has been checked for viruses by Avast antivirus software.
www.avast.com



_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: JSR-223 - returning value from NetRexx

Kermit Kiser
In reply to this post by rvjansen
Try the following:

------------------------------------------------------------------------------------------------------
import javax.script.

nrEngine = ScriptEngineManager().getEngineByName("NetRexx")

say nrEngine.eval('NetRexxScriptEngine.instance.put("returnobject", "99")')
------------------------------------------------------------------------------------------------------

This is an area where JSR223 does not define a standard procedure so each scripting language has to implement it's own approach and my approach for NetRexx was to pass the returned object from a script in the engine bindings under the name "returnobject". (Explanation below.)

As you know, I an not very happy with the JSR223 specification because it does not include rules for passing script names or return values, etc. but in this case the lack of rules sort of makes sense because the designers did not know what an arbitrary script language could handle.

A NetRexx script (in this context different from a NetRexx program because it has no defined class or main method) cannot use the "return" statement to return an object (JSR223 implementations return Java objects.) because the class and main method are generated and hence there is no "returns type" and thus using such a statement in a script is considered a syntax error by NetRexx. That is why I implemented the "returnobject" workaround. Other scripting languages have similar problems. I have now reexamined the current NetRexxA APIs and the JSR223 source. I don't think we can improve the default behavior other than perhaps changing the return object name to "result" because NetRexx requires consistent return statements (all void or all with an expression). But I think it might be possible to allow a "main" method for a JSR223 script to be explicitly coded this way to allow the script to directly return an object via NetRexxA eval:

method main(argwords=String[]) static returns Object

If that works then the NetRexx JSR223 engine could accept any Object returned by a script and pass it to the "eval" caller directly. Some testing will be needed of course. What do you think? (I don't know any way to obtain the "exit" code btw and I suspect it terminates the JVM anyway.)

-- Kermit

PS: What is 3.04?


On 4/15/2015 5:02 AM, René Jansen wrote:
Dave, 

I can reproduce it. 

import javax.script.

nrEngine = ScriptEngineManager().getEngineByName("NetRexx")

/* check returncode */
say nrEngine.eval('exit 99')




yields a blank.

Thanks for mentioning this before 3.04 comes out - and not just after the release. Would you be so kind as to enter it as a problem in https://kenai.com/jira/browse/NETREXX ?

Will try to solve it quickly so it can go into the release.

best regards,

René.




On 15 apr. 2015, at 13:47, Dave Woodman <[hidden email]> wrote:

I am afraid that it does not, at least in the environment that I am using L
 
From: [hidden email] [[hidden email]] On Behalf Of René Jansen
Sent: 15 April 2015 11:54
To: IBM Netrexx
Subject: Re: [Ibm-netrexx] JSR-223 - returning value from NetRexx
 
I always thought that exit(x) returned a value to the caller. Will have a look.
 
René.
 
 
On 15 apr. 2015, at 10:54, Dave Woodman <[hidden email]> wrote:
 
Hi,
 
I have an application that allows JSR-223 scripting, so, of course I promptly dropped NetRexx in and Lo! The Scripts Runneth!
 
Now all I need to do is to get a return value at the end of the script
 
At least in this environment, JavaScript does an implicit return of the last item evaluated and Groovy and Beanshell both use a return statement
 
Neither of the above seem to work for NetRexx. The eternal question is therefore about to be asked…
 
“What am I missing?”
 
Cheers,
 
                Dave.



This email has been checked for viruses by Avast antivirus software. 
www.avast.com

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : 
http://ibm-netrexx.215625.n3.nabble.com/
 



This email has been checked for viruses by Avast antivirus software. 
www.avast.com


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/



_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/



_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: JSR-223 - returning value from NetRexx

rvjansen
Hi Kermit,

thanks - 3.04 as in the release we need to put out.

Yes, I think “result” would be an improvement, and main(agrs=String[]) static returns Object would not hurt and bring it in line with other scripting languages.


best regards,

René.

On 16 apr. 2015, at 11:43, Kermit Kiser <[hidden email]> wrote:

Try the following:

------------------------------------------------------------------------------------------------------
import javax.script.

nrEngine = ScriptEngineManager().getEngineByName("NetRexx")

say nrEngine.eval('NetRexxScriptEngine.instance.put("returnobject", "99")')
------------------------------------------------------------------------------------------------------

This is an area where JSR223 does not define a standard procedure so each scripting language has to implement it's own approach and my approach for NetRexx was to pass the returned object from a script in the engine bindings under the name "returnobject". (Explanation below.)

As you know, I an not very happy with the JSR223 specification because it does not include rules for passing script names or return values, etc. but in this case the lack of rules sort of makes sense because the designers did not know what an arbitrary script language could handle.

A NetRexx script (in this context different from a NetRexx program because it has no defined class or main method) cannot use the "return" statement to return an object (JSR223 implementations return Java objects.) because the class and main method are generated and hence there is no "returns type" and thus using such a statement in a script is considered a syntax error by NetRexx. That is why I implemented the "returnobject" workaround. Other scripting languages have similar problems. I have now reexamined the current NetRexxA APIs and the JSR223 source. I don't think we can improve the default behavior other than perhaps changing the return object name to "result" because NetRexx requires consistent return statements (all void or all with an expression). But I think it might be possible to allow a "main" method for a JSR223 script to be explicitly coded this way to allow the script to directly return an object via NetRexxA eval:

method main(argwords=String[]) static returns Object

If that works then the NetRexx JSR223 engine could accept any Object returned by a script and pass it to the "eval" caller directly. Some testing will be needed of course. What do you think? (I don't know any way to obtain the "exit" code btw and I suspect it terminates the JVM anyway.)

-- Kermit

PS: What is 3.04?


On 4/15/2015 5:02 AM, René Jansen wrote:
Dave, 

I can reproduce it. 

import javax.script.

nrEngine = ScriptEngineManager().getEngineByName("NetRexx")

/* check returncode */
say nrEngine.eval('exit 99')




yields a blank.

Thanks for mentioning this before 3.04 comes out - and not just after the release. Would you be so kind as to enter it as a problem in https://kenai.com/jira/browse/NETREXX ?

Will try to solve it quickly so it can go into the release.

best regards,

René.




On 15 apr. 2015, at 13:47, Dave Woodman <[hidden email]> wrote:

I am afraid that it does not, at least in the environment that I am using L
 
From: [hidden email] [[hidden email]] On Behalf Of René Jansen
Sent: 15 April 2015 11:54
To: IBM Netrexx
Subject: Re: [Ibm-netrexx] JSR-223 - returning value from NetRexx
 
I always thought that exit(x) returned a value to the caller. Will have a look.
 
René.
 
 
On 15 apr. 2015, at 10:54, Dave Woodman <[hidden email]> wrote:
 
Hi,
 
I have an application that allows JSR-223 scripting, so, of course I promptly dropped NetRexx in and Lo! The Scripts Runneth!
 
Now all I need to do is to get a return value at the end of the script
 
At least in this environment, JavaScript does an implicit return of the last item evaluated and Groovy and Beanshell both use a return statement
 
Neither of the above seem to work for NetRexx. The eternal question is therefore about to be asked…
 
“What am I missing?”
 
Cheers,
 
                Dave.



This email has been checked for viruses by Avast antivirus software. 
www.avast.com

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : 
http://ibm-netrexx.215625.n3.nabble.com/
 



This email has been checked for viruses by Avast antivirus software. 
www.avast.com


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/



_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/



_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: JSR-223 - returning value from NetRexx

Kermit Kiser
I think the changes for the jsr223 modules are ready. Do I understand correctly that the SVN trunk is now being updated for 3.04? Should I commit the new modules there for testing? What other enhancements can be included in 3.04?

-- Kermit

On 4/16/2015 3:59 AM, René Jansen wrote:
Hi Kermit,

thanks - 3.04 as in the release we need to put out.

Yes, I think “result” would be an improvement, and main(agrs=String[]) static returns Object would not hurt and bring it in line with other scripting languages.


best regards,

René.



_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: JSR-223 - returning value from NetRexx

rvjansen
Hi Kermit,

great! Yes, to trunk. Also, the list processing and threading enhancements can go there, so I can go about making testcases and such. All the pipes support classes are in there already and I am debugging the TCP stages, and then it must be ready.

best regards,

René.

> On 17 apr. 2015, at 11:07, Kermit Kiser <[hidden email]> wrote:
>
> I think the changes for the jsr223 modules are ready. Do I understand correctly that the SVN trunk is now being updated for 3.04? Should I commit the new modules there for testing? What other enhancements can be included in 3.04?
>
> -- Kermit
>
> On 4/16/2015 3:59 AM, René Jansen wrote:
>> Hi Kermit,
>>
>> thanks - 3.04 as in the release we need to put out.
>>
>> Yes, I think “result” would be an improvement, and main(agrs=String[]) static returns Object would not hurt and bring it in line with other scripting languages.
>>
>>
>> best regards,
>>
>> René.
>>
>
> _______________________________________________
> Ibm-netrexx mailing list
> [hidden email]
> Online Archive : http://ibm-netrexx.215625.n3.nabble.com/
>

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: JSR-223 - returning value from NetRexx

Kermit Kiser
The JSR223 mods have been committed to trunk. The changes are as follows:

1) Add scriptengine instance to bindings (script namespace). This allows a script to use the local handle named "scriptengine" to pass Java objects between the script and the caller like this:

scriptengine.put("result", "77")

2) Allow standard return object via name "result" as well as "returnobject". A script can return an object to the jsr223 eval caller as in the above put statement. The older method { NetRexxScriptEngine.instance.put("returnobject", "9999") } still works.

3) Optional script call via NetRexxA "eval" API to allow direct object return when script starts with a method statement (method name does not need to be "main") that returns a value:

method main(args=String[]) static returns Object
 
This allows a script to return an object to the jsr223 eval caller with a return statement:

return "88"

General NetRexx JSR223 Notes:
  • All engine scope bindings are passed to the script as variables - note that binding names containing periods have the periods changed to underscores to be legal variable names.
  • ***** Emphasize ***** The NetRexx script engine is reused unless the script returned via an "exit" statement and the bindings are persistent which means that scripts will see the bindings (Objects) created by previous scripts! *****
  • Arguments are passed both as the normal "arg" string and as the array binding "javax.script.argv" ie script variable "javax_script_argv".
  • Scripts are executed via the NetRexxA API for interpreting a program from a string so they are not written to files. Other than that -
  • The current version of the engine has no other optimization and only support for bare minimum JSR223 features (No compilable, invokeable, preparse or caching or user profiles or console, etc.).
  • When running as an Ant Script task, properties whose names contain periods are not passed to the bindings and must be accessed via project.getProperty('some.name')
  • The genius who designed Ant local properties did not allow bulk access, so they are not passed in the bindings which means the above line is true for them also unless ==>
  • Workaround - Simply define a local Ant property as a global first and the scriptengine will overlay the global value with the local value in the bindings map
  • When running as an Ant Script task, properties can be set via project.setProperty('some.name','some value')
  • There are no standards for jsr223 interactions that are helpful for NetRexx so I created my own:
  • Script parms can be passed in an "arg" binding. Parse flags can be passed with a "netrexxflags" binding or in Ant with the usual "ant.netrexx.verbose", etc properties.
  • Ant scripts can use the nested classpath facility - It is automatically added to the classpath that NetRexx scans. Likewise any path segments from a thread context URLclassloader are added.
  • The engine will run programs (ie that have a main class) as well as scripts but bindings cannot then be auto added to the program namespace so-
  • Programs have to load bindings like this: NetRexxScriptEngine.getObject("objectname")
Source code used to test the changes:
---------------------------------------------------------------------------------
import javax.script.
import org.netrexx.

nrEngine = ScriptEngineManager().getEngineByName("NetRexx")
nrEngine.put("returnobject",null)
nrEngine.put("result",null)

say nrEngine.eval('scriptengine.put("returnobject", "999")')

say nrEngine.eval('NetRexxScriptEngine.instance.put("returnobject", "9999")')

say nrEngine.eval('scriptengine.put("result", "99")')

say "jsr223 test running"
nrEngine.put("netrexxflags","verbose0")

say nrEngine.eval('method notmain(args=String[]) static returns Object;  scriptengine.put("result", "77"); NetRexxScriptEngine.instance.put("returnobject", "66"); return "88" ')

say nrEngine.eval('method main(args=String[]) static returns Object; say '1111';  return "88" ')
---------------------------------------------------------------------------------

-- Kermit

On 4/17/2015 2:15 AM, René Jansen wrote:
Hi Kermit,

great! Yes, to trunk. Also, the list processing and threading enhancements can go there, so I can go about making testcases and such. All the pipes support classes are in there already and I am debugging the TCP stages, and then it must be ready.

best regards,

René.

On 17 apr. 2015, at 11:07, Kermit Kiser [hidden email] wrote:

I think the changes for the jsr223 modules are ready. Do I understand correctly that the SVN trunk is now being updated for 3.04? Should I commit the new modules there for testing? What other enhancements can be included in 3.04?

-- Kermit

On 4/16/2015 3:59 AM, René Jansen wrote:
Hi Kermit,

thanks - 3.04 as in the release we need to put out.

Yes, I think “result” would be an improvement, and main(agrs=String[]) static returns Object would not hurt and bring it in line with other scripting languages.


best regards,

René.

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/





_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/