#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
+#include <unistd.h>
using namespace v8;
file_template->InstanceTemplate()->SetInternalFieldCount(1);
target->Set(String::NewSymbol("File"), file_template->GetFunction());
+ // class method for File
+ file_template->GetFunction()->Set(String::NewSymbol("STDIN_FILENO"),
+ Integer::New(STDIN_FILENO));
+
+ file_template->GetFunction()->Set(String::NewSymbol("STDOUT_FILENO"),
+ Integer::New(STDOUT_FILENO));
+
+ file_template->GetFunction()->Set(String::NewSymbol("STDERR_FILENO"),
+ Integer::New(STDERR_FILENO));
+
JS_SET_METHOD(file_template->InstanceTemplate(), "open", file_open);
JS_SET_METHOD(file_template->InstanceTemplate(), "close", file_close);
JS_SET_METHOD(file_template->InstanceTemplate(), "write", file_write);
+File.prototype.puts = function (data, callback) {
+ this.write(data + "\n", callback);
+};
+var stdout = new File();
+stdout.fd = File.STDOUT_FILENO;
+
+var stderr = new File();
+stderr.fd = File.STDERR_FILENO;
+
// module search paths
node.includes = ["."];
}
}
-
-
function __require (path, loading_file) {
var filename = path;
} else {
//filename = node.path.join(node.path.dirname(loading_file), path);
}
- node.blocking.print("require: " + filename);
-
- /*
- for (var i = 0; i < suffixes.length; i++) {
- var f = filename + "." + suffixes[i];
-
- var stats = node.blocking.stat(f);
- for (var j in stats) {
- node.blocking.print("stats." + j + " = " + stats[j].toString());
- }
- }
- */
+ stdout.puts("require: " + filename);
var source = node.blocking.cat(filename);
// main script execution.
__require(ARGV[1], ".");
-/*
-fs.stat("/tmp/world", function (stat, status, msg) {
- for ( var i in stat ) {
- node.blocking.print(i + ": " + stat[i]);
- }
- node.blocking.print("done: " + status.toString() + " " + msg.toString());
-
-});
-*/
-
-//var f = new File();
return scope.Close(result);
}
-JS_METHOD(print)
-{
- if (args.Length() < 1) return v8::Undefined();
- HandleScope scope;
- Handle<Value> arg = args[0];
- String::Utf8Value value(arg);
-
- printf("%s\n", *value);
- fflush(stdout);
-
- return Undefined();
-}
-
-
JS_METHOD(cat)
{
if (args.Length() < 1) return v8::Undefined();
JS_SET_METHOD(blocking, "exec", exec);
JS_SET_METHOD(blocking, "cat", cat);
- JS_SET_METHOD(blocking, "print", print);
Local<Array> arguments = Array::New(argc);
for (int i = 0; i < argc; i++) {
f.open("/tmp/world", "a+", function (status) {
if (status == 0) {
- node.blocking.print("file opened");
+ stdout.puts("file open");
f.write("hello world\n", function (status, written) {
- node.blocking.print("written. status: "
- + status.toString()
- + " written: "
- + written.toString()
- );
+ stdout.puts("written. status: "
+ + status.toString()
+ + " written: "
+ + written.toString()
+ );
f.close();
});
} else {
- node.blocking.print("file open failed: " + status.toString());
+ stdout.puts("file open failed: " + status.toString());
}
});