1
0
Fork 0
forked from fun/fun

Added new opcode OP_ENV to provide an env() function to get environment variables from your OS.

This commit is contained in:
Johannes Findeisen 2025-09-27 10:06:04 +02:00
commit 4345fc6f0c
6 changed files with 47 additions and 3 deletions

14
src/vm/os/env.c Normal file
View 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;
}