Arc Forumnew | comments | leaders | submitlogin
1 point by rocketnia 4926 days ago | link | parent

Here's how to run a REPL:

  node rainbow-node.js
One of the things that hasn't been ported yet is 'quit, so you'll need to use ctrl-C.

And like the web interface at http://rocketnia.github.com/rainbow-js/test/, this still doesn't load arc.arc, so it's very bare-bones. However, this particular bare-bones REPL probably has filesystem access. ^_^

(What? You expect me to test whether the filesystem access works? Ehhh. I'll get around to it someday.)

When loaded as a module, rainbow-node.js provides a tentative API composed of a few simple utilities:

  var rainbow = require( "./path/to/rainbow-node.js" );
  
  // Constructs a new Rainbow runtime by providing the basic external IO
  // operations Rainbow depends on.
  rainbow.makeRainbow( System_in, System_out, System_err, System_fs )
  
  // Constructs a Rainbow runtime that uses the actual filesystem and
  // the given Node writable/readable streams. The stdout and stderr
  // streams are provided as thunks so it's possible to swap out one
  // stream for another behind our backs.
  //
  // This sets the stdin parameter's encoding to "utf8" and calls
  // resume() on it to begin event dispatch. Because of that, stdin is
  // not given as a thunk; we expect it to be the same object every time
  // we use it.
  //
  rainbow.makeNodeRainbow( stdin, getStdout, getStderr )
  
  // Constructs a singleton Rainbow runtime that uses the actual
  // filesystem and IO streams. The first time this is called, it sets
  // system.stdin's encoding to "utf8" and calls resume() on it to begin
  // event dispatch.
  rainbow.getSharedRainbow()
All of these utilities provide a single kind of value, namely Rainbow.js's analogue to Java Rainbow's Console class. It provides Console.mainAsync(), an entrypoint corresponding somewhat to running Java Rainbow as a console program. Notably, that method takes its "command-line options" as a JavaScript object, and it's asynchronous.

Naturally, the REPL functionality of the "node rainbow-node.js" command is implemented in terms of getSharedRainbow(), which is implemented in terms of makeNodeRainbow(), which is implemented in terms of makeRainbow(), so they're all at least good enough for that one purpose. :-p

(Before you ask, "node rainbow-node.js" doesn't take any command-line options yet.)