Added new opcode OP_ENV to provide an env() function to get environment variables from your OS.
This commit is contained in:
parent
f3b979c07f
commit
4345fc6f0c
6 changed files with 47 additions and 3 deletions
14
src/vm/os/env.c
Normal file
14
src/vm/os/env.c
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
case OP_ENV: {
|
||||
Value key = pop_value(vm);
|
||||
if (key.type != VAL_STRING) {
|
||||
fprintf(stderr, "Runtime type error: ENV expects string name\n");
|
||||
free_value(key);
|
||||
exit(1);
|
||||
}
|
||||
const char *name = key.s ? key.s : "";
|
||||
const char *val = getenv(name);
|
||||
/* Return empty string if not set (consistent with read_file fallback style) */
|
||||
push_value(vm, make_string(val ? val : ""));
|
||||
free_value(key);
|
||||
break;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue