Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Add access to user environment via ENV
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Sep 10, 2009
1 parent 68dda0a commit dc39e82
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions doc/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ Returns the current working directory of the process.
+ARGV+ ::
An array containing the command line arguments.

+ENV+ ::
An object containing the user environment. See environ(7).

+__filename+ ::
The filename of the script being executed.
Expand Down
15 changes: 14 additions & 1 deletion src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -378,13 +378,26 @@ Load (int argc, char *argv[])

node_obj->Set(String::NewSymbol("version"), String::New(NODE_VERSION));

int i,j;
Local<Array> arguments = Array::New(argc);
for (int i = 0; i < argc; i++) {
for (i = 0; i < argc; i++) {
Local<String> arg = String::New(argv[i]);
arguments->Set(Integer::New(i), arg);
}
global_obj->Set(String::NewSymbol("ARGV"), arguments);

Local<Object> env = Object::New();
for (i = 0; environ[i]; i++) {
for (j = 0; environ[i][j] && environ[i][j] != '='; j++) { ; }
Local<String> field = String::New(environ[i], j);
Local<String> value = Local<String>();
if (environ[i][j] == '=') {
value = String::New(environ[i]+j+1);
}
env->Set(field, value);
}
global_obj->Set(String::NewSymbol("ENV"), env);

NODE_SET_METHOD(node_obj, "compile", compile);
NODE_SET_METHOD(node_obj, "reallyExit", node_exit);
NODE_SET_METHOD(node_obj, "cwd", Cwd);
Expand Down

0 comments on commit dc39e82

Please sign in to comment.