-var utils = require("/utils.js");
+var sys = require("/sys.js");
var CRLF = "\r\n";
var STATUS_CODES = {
client._pushRequest = function (req) {
req.addListener("flush", function () {
if (client.readyState == "closed") {
- //utils.debug("HTTP CLIENT request flush. reconnect. readyState = " + client.readyState);
+ //sys.debug("HTTP CLIENT request flush. reconnect. readyState = " + client.readyState);
client.connect(port, host); // reconnect
return;
}
- //utils.debug("client flush readyState = " + client.readyState);
+ //sys.debug("client flush readyState = " + client.readyState);
if (req == requests[0]) flushMessageQueue(client, [req]);
});
requests.push(req);
});
client.addListener("eof", function () {
- //utils.debug("client got eof closing. readyState = " + client.readyState);
+ //sys.debug("client got eof closing. readyState = " + client.readyState);
client.close();
});
return;
}
- //utils.debug("HTTP CLIENT onClose. readyState = " + client.readyState);
+ //sys.debug("HTTP CLIENT onClose. readyState = " + client.readyState);
// If there are more requests to handle, reconnect.
if (requests.length > 0 && client.readyState != "opening") {
- //utils.debug("HTTP CLIENT: reconnecting readyState = " + client.readyState);
+ //sys.debug("HTTP CLIENT: reconnecting readyState = " + client.readyState);
client.connect(port, host); // reconnect
}
});
createIncomingMessageStream(client, function (res) {
- //utils.debug("incoming response!");
+ //sys.debug("incoming response!");
res.addListener("complete", function ( ) {
- //utils.debug("request complete disconnecting. readyState = " + client.readyState);
+ //sys.debug("request complete disconnecting. readyState = " + client.readyState);
client.close();
});
// A repl library that you can include in your own code to get a runtime
// interface to your program. Just require("/repl.js").
-var utils = require("utils.js");
+var sys = require("/sys.js");
-utils.puts("Type '.help' for options.");
+sys.puts("Type '.help' for options.");
var buffered_cmd = '';
var ret = eval(buffered_cmd);
if (ret !== undefined) {
exports.scope['_'] = ret;
- utils.p(ret);
+ sys.p(ret);
}
}
} catch (e) {
// On error: Print the error and clear the buffer
if (e.stack) {
- utils.puts(e.stack);
+ sys.puts(e.stack);
} else {
- utils.puts(e.toString());
+ sys.puts(e.toString());
}
buffered_cmd = '';
}
* Used to display the prompt.
*/
function displayPrompt () {
- utils.print(buffered_cmd.length ? '... ' : exports.prompt);
+ sys.print(buffered_cmd.length ? '... ' : exports.prompt);
}
/**
displayPrompt();
return true;
case ".clear":
- utils.puts("Clearing Scope...");
+ sys.puts("Clearing Scope...");
buffered_cmd = '';
exports.scope = {};
displayPrompt();
node.stdio.close();
return true;
case ".help":
- utils.puts(".break\tSometimes you get stuck in a place you can't get out... This will get you out.");
- utils.puts(".clear\tBreak, and also clear the local scope.");
- utils.puts(".exit\tExit the prompt");
- utils.puts(".help\tShow repl options");
+ sys.puts(".break\tSometimes you get stuck in a place you can't get out... This will get you out.");
+ sys.puts(".clear\tBreak, and also clear the local scope.");
+ sys.puts(".exit\tExit the prompt");
+ sys.puts(".help\tShow repl options");
displayPrompt();
return true;
}
+++ /dev/null
-utils.js
\ No newline at end of file
--- /dev/null
+exports.print = function (x) {
+ node.stdio.write(x);
+};
+
+exports.puts = function (x) {
+ node.stdio.write(x.toString() + "\n");
+};
+
+exports.debug = function (x) {
+ node.stdio.writeError("DEBUG: " + x.toString() + "\n");
+};
+
+exports.error = function (x) {
+ node.stdio.writeError(x.toString() + "\n");
+};
+
+/**
+ * Echos the value of a value. Trys to print the value out
+ * in the best way possible given the different types.
+ *
+ * @param {Object} value The object to print out
+ */
+exports.inspect = function (value) {
+ if (value === 0) return "0";
+ if (value === false) return "false";
+ if (value === "") return '""';
+ if (typeof(value) == "function") return "[Function]";
+ if (value === undefined) return;
+
+ try {
+ return JSON.stringify(value);
+ } catch (e) {
+ // TODO make this recusrive and do a partial JSON output of object.
+ if (e.message.search("circular")) {
+ return "[Circular Object]";
+ } else {
+ throw e;
+ }
+ }
+};
+
+exports.p = function (x) {
+ exports.error(exports.inspect(x));
+};
+
+exports.exec = function (command) {
+ var child = node.createChildProcess("/bin/sh", ["-c", command]);
+ var stdout = "";
+ var stderr = "";
+ var promise = new node.Promise();
+
+ child.addListener("output", function (chunk) {
+ if (chunk) stdout += chunk;
+ });
+
+ child.addListener("error", function (chunk) {
+ if (chunk) stderr += chunk;
+ });
+
+ child.addListener("exit", function (code) {
+ if (code == 0) {
+ promise.emitSuccess(stdout, stderr);
+ } else {
+ promise.emitError(code, stdout, stderr);
+ }
+ });
+
+ return promise;
+};
+++ /dev/null
-exports.print = function (x) {
- node.stdio.write(x);
-};
-
-exports.puts = function (x) {
- node.stdio.write(x.toString() + "\n");
-};
-
-exports.debug = function (x) {
- node.stdio.writeError("DEBUG: " + x.toString() + "\n");
-};
-
-exports.error = function (x) {
- node.stdio.writeError(x.toString() + "\n");
-};
-
-/**
- * Echos the value of a value. Trys to print the value out
- * in the best way possible given the different types.
- *
- * @param {Object} value The object to print out
- */
-exports.inspect = function (value) {
- if (value === 0) return "0";
- if (value === false) return "false";
- if (value === "") return '""';
- if (typeof(value) == "function") return "[Function]";
- if (value === undefined) return;
-
- try {
- return JSON.stringify(value);
- } catch (e) {
- // TODO make this recusrive and do a partial JSON output of object.
- if (e.message.search("circular")) {
- return "[Circular Object]";
- } else {
- throw e;
- }
- }
-};
-
-exports.p = function (x) {
- exports.error(exports.inspect(x));
-};
-
-exports.exec = function (command) {
- var child = node.createChildProcess("/bin/sh", ["-c", command]);
- var stdout = "";
- var stderr = "";
- var promise = new node.Promise();
-
- child.addListener("output", function (chunk) {
- if (chunk) stdout += chunk;
- });
-
- child.addListener("error", function (chunk) {
- if (chunk) stderr += chunk;
- });
-
- child.addListener("exit", function (code) {
- if (code == 0) {
- promise.emitSuccess(stdout, stderr);
- } else {
- promise.emitError(code, stdout, stderr);
- }
- });
-
- return promise;
-};
--- /dev/null
+sys.js
\ No newline at end of file
};
node.exec = function () {
- throw new Error("node.exec() has moved. Use require('/utils.js') to bring it back.");
+ throw new Error("node.exec() has moved. Use require('/sys.js') to bring it back.");
}
node.http.createServer = function () {
puts = function () {
- throw new Error("puts() has moved. Use require('/utils.js') to bring it back.");
+ throw new Error("puts() has moved. Use require('/sys.js') to bring it back.");
}
print = function () {
- throw new Error("print() has moved. Use require('/utils.js') to bring it back.");
+ throw new Error("print() has moved. Use require('/sys.js') to bring it back.");
}
p = function () {
- throw new Error("p() has moved. Use require('/utils.js') to bring it back.");
+ throw new Error("p() has moved. Use require('/sys.js') to bring it back.");
}
node.debug = function () {
- throw new Error("node.debug() has moved. Use require('/utils.js') to bring it back.");
+ throw new Error("node.debug() has moved. Use require('/sys.js') to bring it back.");
}
node.error = function () {
- throw new Error("node.error() has moved. Use require('/utils.js') to bring it back.");
+ throw new Error("node.error() has moved. Use require('/sys.js') to bring it back.");
}