|
@ -117,13 +117,12 @@ will share the same global object but will have unique I/O. |
|
|
|
|
|
|
|
|
Here is an example that starts a REPL on stdin, a Unix socket, and a TCP socket: |
|
|
Here is an example that starts a REPL on stdin, a Unix socket, and a TCP socket: |
|
|
|
|
|
|
|
|
var net = require("net"), |
|
|
var net = require('net'), |
|
|
repl = require("repl"); |
|
|
repl = require('repl'), |
|
|
|
|
|
|
|
|
connections = 0; |
|
|
connections = 0; |
|
|
|
|
|
|
|
|
repl.start({ |
|
|
repl.start({ |
|
|
prompt: "Node.js via stdin> ", |
|
|
prompt: 'Node.js via stdin> ', |
|
|
input: process.stdin, |
|
|
input: process.stdin, |
|
|
output: process.stdout |
|
|
output: process.stdout |
|
|
}); |
|
|
}); |
|
@ -131,18 +130,18 @@ Here is an example that starts a REPL on stdin, a Unix socket, and a TCP socket: |
|
|
net.createServer(function (socket) { |
|
|
net.createServer(function (socket) { |
|
|
connections += 1; |
|
|
connections += 1; |
|
|
repl.start({ |
|
|
repl.start({ |
|
|
prompt: "Node.js via Unix socket> ", |
|
|
prompt: 'Node.js via Unix socket> ', |
|
|
input: socket, |
|
|
input: socket, |
|
|
output: socket |
|
|
output: socket |
|
|
}).on('exit', function() { |
|
|
}).on('exit', function() { |
|
|
socket.end(); |
|
|
socket.end(); |
|
|
}) |
|
|
}) |
|
|
}).listen("/tmp/node-repl-sock"); |
|
|
}).listen('/tmp/node-repl-sock'); |
|
|
|
|
|
|
|
|
net.createServer(function (socket) { |
|
|
net.createServer(function (socket) { |
|
|
connections += 1; |
|
|
connections += 1; |
|
|
repl.start({ |
|
|
repl.start({ |
|
|
prompt: "Node.js via TCP socket> ", |
|
|
prompt: 'Node.js via TCP socket> ', |
|
|
input: socket, |
|
|
input: socket, |
|
|
output: socket |
|
|
output: socket |
|
|
}).on('exit', function() { |
|
|
}).on('exit', function() { |
|
@ -191,7 +190,7 @@ be emitted. |
|
|
Example of listening for `reset`: |
|
|
Example of listening for `reset`: |
|
|
|
|
|
|
|
|
// Extend the initial repl context. |
|
|
// Extend the initial repl context. |
|
|
r = repl.start({ options ... }); |
|
|
var r = repl.start({ options ... }); |
|
|
someExtension.extend(r.context); |
|
|
someExtension.extend(r.context); |
|
|
|
|
|
|
|
|
// When a new context is created extend it as well. |
|
|
// When a new context is created extend it as well. |
|
@ -213,7 +212,7 @@ accessing `fs` will `require()` the `fs` module as `global.fs`. |
|
|
|
|
|
|
|
|
The special variable `_` (underscore) contains the result of the last expression. |
|
|
The special variable `_` (underscore) contains the result of the last expression. |
|
|
|
|
|
|
|
|
> [ "a", "b", "c" ] |
|
|
> [ 'a', 'b', 'c' ] |
|
|
[ 'a', 'b', 'c' ] |
|
|
[ 'a', 'b', 'c' ] |
|
|
> _.length |
|
|
> _.length |
|
|
3 |
|
|
3 |
|
@ -225,10 +224,10 @@ a variable to the REPL explicitly by assigning it to the `context` object |
|
|
associated with each `REPLServer`. For example: |
|
|
associated with each `REPLServer`. For example: |
|
|
|
|
|
|
|
|
// repl_test.js |
|
|
// repl_test.js |
|
|
var repl = require("repl"), |
|
|
var repl = require('repl'), |
|
|
msg = "message"; |
|
|
msg = 'message'; |
|
|
|
|
|
|
|
|
repl.start("> ").context.m = msg; |
|
|
repl.start('> ').context.m = msg; |
|
|
|
|
|
|
|
|
Things in the `context` object appear as local within the REPL: |
|
|
Things in the `context` object appear as local within the REPL: |
|
|
|
|
|
|
|
|