ejsval _ejs_fs_module_func (ejsval env, ejsval _this, uint32_t argc, ejsval* args) { ejsval exports = args[0]; EJS_INSTALL_FUNCTION(exports, "readFileSync", _ejs_fs_readFileSync); EJS_INSTALL_FUNCTION(exports, "createWriteStream", _ejs_fs_createWriteStream); return _ejs_undefined; }
ejsval _ejs_path_module_func (ejsval env, ejsval _this, uint32_t argc, ejsval* args) { ejsval exports = args[0]; EJS_INSTALL_FUNCTION(exports, "dirname", _ejs_path_dirname); EJS_INSTALL_FUNCTION(exports, "basename", _ejs_path_basename); EJS_INSTALL_FUNCTION(exports, "resolve", _ejs_path_resolve); return _ejs_undefined; }
static ejsval _ejs_wrapFdWithStream (int fd) { ejsval stream = _ejs_object_create(_ejs_null); EJS_INSTALL_FUNCTION (stream, "write", _ejs_stream_write); EJS_INSTALL_FUNCTION (stream, "end", _ejs_stream_end); _ejs_object_setprop_utf8 (stream, "%internal_fd", NUMBER_TO_EJSVAL(fd)); return stream; }
ejsval _ejs_child_process_module_func (ejsval env, ejsval _this, uint32_t argc, ejsval* args) { ejsval exports = args[0]; EJS_INSTALL_FUNCTION(exports, "spawn", _ejs_child_process_spawn); return _ejs_undefined; }
ejsval _ejs_child_process_module_func (ejsval env, ejsval _this, uint32_t argc, ejsval* args) { ejsval exports = args[0]; EJS_INSTALL_FUNCTION(exports, "spawn", _ejs_child_process_spawn); _ejs_object_setprop_utf8 (exports, "stdout", _ejs_wrapFdWithStream(1)); _ejs_object_setprop_utf8 (exports, "stderr", _ejs_wrapFdWithStream(2)); return _ejs_undefined; }
ejsval _ejs_fs_createWriteStream (ejsval env, ejsval _this, uint32_t argc, ejsval* args) { ejsval stream = _ejs_object_create(_ejs_null); EJS_INSTALL_FUNCTION (stream, "write", _ejs_stream_write); EJS_INSTALL_FUNCTION (stream, "end", _ejs_stream_end); char *utf8_path = ucs2_to_utf8(EJSVAL_TO_FLAT_STRING(args[0])); int fd = open (utf8_path, O_CREAT | O_TRUNC | O_WRONLY, 0777); free (utf8_path); if (fd == -1) { perror ("open"); printf ("we should totally throw an exception here\n"); return _ejs_undefined; } _ejs_object_setprop_utf8 (stream, "%internal_fd", NUMBER_TO_EJSVAL(fd)); return stream; }