Wednesday, July 18, 2007

lab 79 - acme javascript

NAME

NOTES

I'm excited about today's lab. I hope others pick up on this
and experiment with it
because I think some cool acme clients would come of it.

The idea behind this lab is to mix together acme, javascript and json web services.

I've been poking around at inferno's javascript, hoping to improve it.
The best way of doing that is to start using it more heavily. In earlier labs
I created a tool called js that ran javascript scripts outside of charon.
But without knowing what set of host objects to build it has languished.

Looking to use javascript more, I've been taking another
look at web services APIs, and noticing
that JSON is getting strong support, especially from Google and Yahoo.
I'm pleased about this, since the SOAP stuff looked so horrid.
So I really want to pull JSON web services into inferno using javascript.
But web services
don't work too well when text is just output to the command line, they need more
interaction.

So the natural thing to do is build an acme client. Acme clients can
be built using shell but I don't think that is ideal. Inferno shell
can really show its limits when used as a programming
language. And for new users javascript is probably an easier
and more familiar language to get to grips with.

I decided in this lab to create a javascript command that includes acmewin as
a host object. I also added a host readlUrl function meant for calling json
services. Together I hope this makes it really simple for anyone to
put together an acme client using data pulled from the internet.

The command is called Jwin and is envoked with the name of
a javascript file.

% Jwin -f file.js

It opens one window for the script to operate on.

I created an Acmewin host object, that is instantiated before the script
is run. It has methods that mirror the acmewin library, read, writebody,
tagwrite, name, clean, select, setaddr, replace, readall.

It also has two event properties, onlook and onexec, which should
be assigned functions if you want to react to mouse clicks
of the middle and right buttons.

I still need to write a postUrl method. I'd like a blogger interface myself.
Even though most google APIs allow read access using JSON they
only allow posts in Atom format. But given the Javascript object
it shouldn't be hard to build the xml string for the post.

The web access is through svc/webget/webget, so this
should be started before using Jwin.

Below is a longer example to give you more of a flavor
of an acmeclient written in javascript. Try this out and
see how fast you can come up with you own acme client.