Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

env: Add Env type and set() and get() functions #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions env.jk
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
link_with("libc.so.6")

// FIXME: These functions can return NULL, how do we check for this?
// Do we promote NULL to an empty string? Do we return a Pointer instead?
ext func getenv(name: string) -> string;
ext func setenv(name: string, value: string);

type Env(from: string);

func get(env: Env) -> string {
getenv(env.from)
}

func set(env: Env, new_value: string) {
setenv(env.from, new_value)
}

// FIXME: Add assertions
test get_home() {
println(Env(from: "HOME").get())
}

test set_var() {
random_env_var = Env(from: "__jinko_RANDOM_ENV_VAR");
random_env_var.set("is_set")

// random_env_var.get().should_be("is_set")
}