Local<Object> node = Object::New();
g->Set(String::New("node"), node);
- NODE_SET_METHOD(node, "compile", compile);
+ NODE_SET_METHOD(node, "compile", compile); // internal
NODE_SET_METHOD(node, "debug", debug);
- NODE_SET_METHOD(g, "exit", node_exit);
+ NODE_SET_METHOD(node, "exit", node_exit);
Local<Array> arguments = Array::New(argc);
for (int i = 0; i < argc; i++) {
findScript(base_directory, name, function (filename) {
if (filename === null) {
stderr.puts("Cannot find a script matching: " + name);
- exit(1);
+ node.exit(1);
}
loadScript(filename, target, callback);
});
node.fs.cat(filename, "utf8", function (status, content) {
if (status != 0) {
stderr.puts("Error reading " + filename + ": " + node.fs.strerror(status));
- exit(1);
+ node.exit(1);
}
var scaffold = new Scaffold(content, filename, target);
<dt><code class="sh_javascript">node.debug(string)</code></dt>
<dd>A synchronous output function. Will <i>block</i> the process and output the
string immediately to stdout. Use with care.</dd>
+
+ <dt><code class="sh_javascript">node.exit(code)</code></dt>
+ <dd>Immediately ends the process with the specified code.</dd>
</dl>
<h3 id="timers">Timers</h3>
<dt><code class="sh_javascript">new node.fs.File</code></dt>
<dd>Creates a new file object. </dd>
+ <dt><code class="sh_javascript">file.onError</code></dt>
+ <dd>Callback. This is called internally anytime an error occurs with this
+ file. There are three arguments: the method name, the POSIX errno, and a
+ string describing the error.
+
+ <p>Example</p>
+<pre class="sh_javascript">
+var path = "/some/path/that/doesnt/exist";
+var file = new node.fs.File();
+file.onError = function (method, errno, msg) {
+ stderr.puts("An error occurred calling " + method + " on " + path);
+ stderr.puts(msg);
+ exit(1);
+}
+file.open(path, "w+")
+</pre>
+
<dt><code class="sh_javascript">file.open(path, mode, on_completion)</code></dt>
<dd>Opens the file at <code>path</code>.
<p><code>mode</code> is a string:
function deepEquals (a, b) {
// ...
}
-<span class="highlight">exports</span>.assertEquals = function (expected, found, name_opt) {
+exports.assertEquals = function (expected, found, name_opt) {
if (!deepEquals(found, expected)) {
fail(expected, found, name_opt);
}
when all the included modules are loaded. Each file/module can have an <code
class="sh_javascript">onLoad</code> callback.
-<p> To export an object, add to the special <code
- class="highlight">exports</code> object.
+<p>To export an object, add to the special <code>exports</code> object.
<p> The functions <code class="sh_javascript">fail</code> and <code class="sh_javascript">deepEquals</code> are not
exported and remain private to the module.