Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
70 user(s) are online (57 user(s) are browsing Forums)

Members: 1
Guests: 69

TheMagicSN, more...

Support us!

Headlines

 
  Register To Post  

ARexxability - but how?
Just popping in
Just popping in


See User information
I've always had the aim to add ARexx support for JAmiga. I however haven't decided on how it should look. How would one want to call Java code from an ARexx script?

I've been looking at the twitter4j API, and how that could be utilised from ARexx.
For instance how should this Java code be written in ARexx?

01    import twitter4j.TwitterFactory;
02    import twitter4j.Twitter;
03    import twitter4j.Status;
04    import java.util.List;
    ...
10    Twitter twitter TwitterFactory.getSingleton();
11    List<Statusstatuses twitter.getHomeTimeline();
12    System.out.println("Showing home timeline.");
13    for (Status status statuses) {
14        System.out.println(status.getUser().getName() + ":" +
15                           status.getText());
16    }


My initial aim was to not require any Java code to be written to utilise any arbitrary Java JAR. But this might prove too difficult. The main aim should be an easy to use approach.

One option is to expose the JNI layer using ADDLIB("jni"), creating something like:

01  CALL ADDLIB("jamiga", -20)    /* expose JNI layer*/
02  factory GetStaticFieldID("twitter4j.TwitterFactory")
03  twitter CallObjectMethod(factory"getSingleton")
04  say "Showing home timeline."
05  statuses CallObjectMethod(twitter"getHomeTimeline")
06  DO i=0 TO CallIntMethod(statuses"size")
07      user CallObjectMethod(statuses"getUser")
08      
name CallObjectMethod(user"getName")
09      
text CallObjectMethod(user"getStatus")
10      say name ":" text
11  END


As you see, this gets very chatty and clunky. It is however extremely powerful, as it allows you do much anything. However, you need to know your JNI, and if you do, you're probably better off just writing it in Java. There are also lots of stuff not covered, for isntance exceptions. This can probably be a real nightmare to use.

So, what I would like to achieve is something more in the lines of:

01  ADDRESS JAMIGA
02  CALL ADDLIB
("jamiga", -20/* add JAmiga functions, like JCALL */
03  
04  twitter 
JCALL("twitter4j.TwitterFactory""getSingleton")
05  statuses twitter.homeTimeline    /* translates to twitter.getHomeTimeline() */
06  DO i=0 TO statuses.size
07      say statuses
.i.user.name ":" status.i.text
08  END


This is much more convenient to write, and even makes sense if you just know ARexx. It is however very likely a can of worms for me, implementation wise. For instance, in order to get the homeTimeline stem variable on row 05, the underlying code on row 04, woudl have to fully traverse the Twitter object structure, which does hold a lot of other methods, where some most likely would throw exceptions.

I guess I could add a few more helper functions, to export Java bean objects to stem variables, forming something like:

01  ADDRESS JAMIGA
02  CALL ADDLIB
("jamiga", -20
03  
04  twitter 
JCALL("twitter4j.TwitterFactory""getSingleton")
05  statuses JBEAN(twitter"getHomeTimeline")  /* makes the list of statuses as a stem var */
06  DO i=0 TO statuses.size
07      status 
JBEAN(statuses"get"i)      /* gets the i:th item */
08      say status.user.name ":" status.text
09  END


Now, I haven't done much ARexx host programming so I don't know all ways how callbacks from ARexx to C is actually made, but I don't think that accessing stem variables creates a callback, right? AFAIU, a stem variable is just a variable with dots in the name...?

Does anyone have any input to give, on how you would like to call Java from ARexx?


Edited by jaokim on 2014/8/16 17:29:02
Maintainer and developer for Jamiga2 - Java for Amiga
Go to top
Re: ARexxability - but how?
Just can't stay away
Just can't stay away


See User information
@jaokim

Maybe have a look at the Gui4Cli interpreter's source, how it is done there?
For links look at my blog on OS4coding
.net



Go to top
Re: ARexxability - but how?
Just popping in
Just popping in


See User information
@JosDuchIt

Do you have a more direct link? I downloaded the sources and browsed around, but couldn't find any examples, not any interpreter source of interest (I have to admit, I was very lazy).

Currently I'm just looking for input on how one would want to call Java from ARexx, not so much how to solve it technically (although suggestions based on what is possible would be welcome).

Perhaps my aim is a bit high. I should perhaps just settle with a simple sort of Java-bean based approach, to enable simple ARexx communication, possibly requiring some Java code to be written, rather than fully utilise Java from ARexx.

Maintainer and developer for Jamiga2 - Java for Amiga
Go to top
Re: ARexxability - but how?
Home away from home
Home away from home


See User information
@jaokim

You have the question the wrong way round.

It's not how would you call Java from ARexx but how would you call ARexx from java.

Java should have an ARexx class similar in nature to pythons arexx module, so that you can send ARexx commands to applications and / or create an ARexx port to allow sending commands to java apps.


That's not to say executeing a few lines of Java from ARexx might not be useful too, but when people were asking for ARexx support I believe they asking for what I described rather that what you have.

As to stem vars, I don't have any experience of setting them from an ARexx function *library* bit from an ARexx function *host* they are simple got/set with Get/SetRexxVarFromMsg() and are indeed variable with dots in from that point of view.



Edited by broadblues on 2014/8/17 18:36:11
Go to top
Re: ARexxability - but how?
Just can't stay away
Just can't stay away


See User information
@jaokim
@jaokim

http://users.online.be/AD/ my site about Gui4Cli
http://gui4cli.com/ami/gcmain.htm the author's site
http://gui4cli.com/ami/progs/gui4cli.lha 3.8 full archive with examples and user manual (also of arexx possibilities)
http://gui4cli.com/ami/progs/G4C385.LHA 3.8.5 executable
http://gui4cli.com/ami/src/g4c-gcview.lha source (OS3.x of 3.8.5)
http://users.online.be/AD/G4Guide/main.html online manual
http://users.online.be/AD/G4Guide/arexx.html arexx part of the manual

Under Gui4Cli you address an other arexx capable program with
sendrexx Portname CommandLine and get the eventual result as
$RexxRet.

This has always solved all problems that Gui4Cli was not capable of handling

The other way round, sending arexx commands to a Gui4Cli interpreted script is important too.
It allows the interaction of any application with Gui4Cli scripts (Gui4Cli is powerfull enough to call some scripts applications btw)

You do this addressing the 'Gui4CLI' port of the interpreter.
You can load and then address directly any loaded script/gui with the arexx capable commands including opening,closing quitting the scripts window and Gosub (go to subroutine)

12.Amiga OS 4:> RX 'ADDRESS "Gui4Cli" "GuiLoad guic:TestGui.gc"'
12.Amiga OS 4:> RX 'ADDRESS "Gui4Cli" GuiClose TestGui.gc'
12.Amiga OS 4:> RX 'ADDRESS "Gui4Cli" GuiOpen TestGui.gc'
12.Amiga OS 4:> RX 'ADDRESS "Gui4Cli" GuiQuit TestGui.gc'
12.Amiga OS 4:> RX 'ADDRESS "Gui4Cli" GuiOpen TestGui.gc'
12.Amiga OS 4:> RX 'ADDRESS "Gui4Cli" GuiOpen TestGui.gc
12.Amiga OS 4:> RX 'ADDRESS "Gui4Cli" Gosub TestGui.gc TitleRoutine "this is the New window title" '

The list of arexx capable commands is given here http://users.online.be/AD/G4Guide/main.html

Of course the manipulation of one gui/script by a " master" script/gui is possible too using the (arexx capable) Gui4Cli commands directly.


Go to top

  Register To Post

 




Currently Active Users Viewing This Thread: 1 ( 0 members and 1 Anonymous Users )




Powered by XOOPS 2.0 © 2001-2024 The XOOPS Project