Added get-environment-variable

This commit is contained in:
Justin Ethier 2016-01-10 22:44:51 -05:00
parent 0b3e2533f1
commit 0f8efe9693

View file

@ -3,7 +3,7 @@
command-line
;exit - already defined as a primitive, at least for now
emergency-exit
; TODO: get-environment-variable
get-environment-variable
; TODO: get-environment-variables
)
; (import (scheme base)
@ -28,4 +28,18 @@
lis = pl;
}
return_closcall1(data, k, lis); ")
(define-c get-environment-variable
"(void *data, int argc, closure _, object k, object env_var)"
;; TODO: consolidate with Cyc_command_line_arguments from runtime.c
"
const char *v = NULL;
Cyc_check_str(data, env_var);
v = getenv(string_str(env_var));
if (v == NULL) {
return_closcall1(data, k, boolean_f);
} else {
make_string(str, v);
return_closcall1(data, k, &str);
}
")
))