From 8c41adb6288a3a4e7dd31c95d02d1828d2fafbcb Mon Sep 17 00:00:00 2001 From: Ryan Date: Fri, 11 Sep 2009 20:32:24 +0200 Subject: [PATCH] Add node-repl --- node-repl | 43 +++++++++++++++++++++++++++++++++++++++++++ wscript | 1 + 2 files changed, 44 insertions(+) create mode 100755 node-repl diff --git a/node-repl b/node-repl new file mode 100755 index 0000000000..e2e742f9e8 --- /dev/null +++ b/node-repl @@ -0,0 +1,43 @@ +#!/usr/bin/env node + +node.stdio.open(); + +var buffered_cmd = ''; + +function prompt () { + node.stdio.write(buffered_cmd.length ? '... ' : "\nnode> "); +} + +node.stdio.write("Welcome to the Node.js REPL.\n"); +node.stdio.write("Enter ECMAScript at the prompt.\n"); +node.stdio.write("Type Control-D to exit.\n"); +node.stdio.write("For more information, see http://tinyclouds.org/node\n"); + +prompt(); + +var trimmer = /^\s*(.+)\s*$/m; + +node.stdio.addListener("data", function (cmd) { + var matches = trimmer.exec(cmd); + + if (matches && matches.length == 2) { + cmd = matches[1]; + try { + buffered_cmd += cmd; + try { + node.stdio.write(JSON.stringify(eval(buffered_cmd)) + "\n"); + buffered_cmd = ''; + } catch (e) { + if (!(e instanceof SyntaxError)) + throw e; + } + } catch (e) { + node.stdio.writeError('caught an exception: ' + e + '\n'); + buffered_cmd = ''; + } + } + + prompt(); +}); + +// vim:ft=javascript diff --git a/wscript b/wscript index 232bf47acc..800b212a79 100644 --- a/wscript +++ b/wscript @@ -348,3 +348,4 @@ def build(bld): src/net.h """); bld.install_files('${PREFIX}/share/man/man1/', 'doc/node.1'); + bld.install_files('${PREFIX}/bin/', 'node-repl', chmod=0755);