53f2df500d
Add the following functions that dharma registry calls but were missing from the El runtime: el_runtime.c (consumed by the old build system via released SDK): - list_len, list_get — aliases for el_list_len/el_list_get (handlers.el) - json_array_push — append pre-encoded element to JSON array string - now_millis, unix_timestamp_ms, time_now_ms — ms-since-epoch aliases - log_info, log_warn — structured stderr log helpers - config — reads config from environment (alias for getenv) - http_patch — HTTP PATCH with Content-Type: application/json - http_post_engram — HTTP POST with optional X-API-Key header - http_get_engram — HTTP GET with optional X-API-Key header - str_to_bytes — encode string as JSON byte array [72,101,...] - bytes_to_str — decode JSON byte array back to string - hash_sha256 — SHA-256 hex digest using built-in sha256 impl runtime/*.el (consumed by the new build system): - http.el: http_patch, http_post_engram, http_get_engram - time.el: now_millis, unix_timestamp_ms, time_now_ms - env.el: config, log_info, log_warn, list_len, list_get - json.el: json_array_push, bytes_to_str - string.el: str_to_bytes, hash_sha256 (via __sha256_hex seed) el_seed.h / el_seed.c: - __sha256_hex primitive with self-contained SHA-256 implementation
106 lines
3.4 KiB
EmacsLisp
106 lines
3.4 KiB
EmacsLisp
// runtime/env.el — environment and process
|
|
// Covers: environment variables, command-line args, process exit, in-process
|
|
// state store, UUID generation, and list convenience helpers.
|
|
|
|
// env — read an environment variable. Returns "" if the variable is not set.
|
|
fn env(key: String) -> String {
|
|
return __env_get(key)
|
|
}
|
|
|
|
// args — command-line arguments as a list of strings.
|
|
// __args_json returns a JSON array (e.g. ["prog","arg1","arg2"]).
|
|
// The list is built by iterating over the array.
|
|
fn args() -> [String] {
|
|
let json: String = __args_json()
|
|
let n: Int = json_array_len(json)
|
|
let result: [String] = el_list_empty()
|
|
let i: Int = 0
|
|
while i < n {
|
|
let item: String = json_array_get_string(json, i)
|
|
let result = el_list_append(result, item)
|
|
let i = i + 1
|
|
}
|
|
return result
|
|
}
|
|
|
|
// exit_program — terminate the process with the given exit code.
|
|
fn exit_program(code: Int) {
|
|
__exit_program(code)
|
|
}
|
|
|
|
// ── List convenience helpers ───────────────────────────────────────────────
|
|
|
|
// get — index into a list. Thin alias for el_list_get used throughout the
|
|
// El stdlib so call sites read like `get(lst, i)` rather than the verbose form.
|
|
fn get(lst: [String], i: Int) -> String {
|
|
return el_list_get(lst, i)
|
|
}
|
|
|
|
// len — length of a list.
|
|
fn len(lst: [String]) -> Int {
|
|
return el_list_len(lst)
|
|
}
|
|
|
|
// ── In-process key-value state store ──────────────────────────────────────
|
|
|
|
// state_set — store a string value under key.
|
|
fn state_set(key: String, val: String) {
|
|
__state_set(key, val)
|
|
}
|
|
|
|
// state_get — retrieve value for key; returns "" if key not present.
|
|
fn state_get(key: String) -> String {
|
|
return __state_get(key)
|
|
}
|
|
|
|
// state_del — remove key from the store.
|
|
fn state_del(key: String) {
|
|
__state_del(key)
|
|
}
|
|
|
|
// state_keys — all keys currently in the store as a JSON array string.
|
|
fn state_keys() -> String {
|
|
return __state_keys()
|
|
}
|
|
|
|
// ── DHARMA runtime helpers ─────────────────────────────────────────────────
|
|
|
|
// config — read a configuration value from the environment.
|
|
// Returns "" if the variable is not set. Alias for env().
|
|
fn config(key: String) -> String {
|
|
return __env_get(key)
|
|
}
|
|
|
|
// log_info — write an [INFO] log line to stdout.
|
|
fn log_info(msg: String) {
|
|
__println("[INFO] " + msg)
|
|
}
|
|
|
|
// log_warn — write a [WARN] log line to stdout.
|
|
fn log_warn(msg: String) {
|
|
__println("[WARN] " + msg)
|
|
}
|
|
|
|
// list_len — return the number of elements in a list. Alias for el_list_len.
|
|
fn list_len(lst: [String]) -> Int {
|
|
return el_list_len(lst)
|
|
}
|
|
|
|
// list_get — return the element at index i in a list. Alias for el_list_get.
|
|
fn list_get(lst: [String], i: Int) -> String {
|
|
return el_list_get(lst, i)
|
|
}
|
|
|
|
// ── UUID generation ────────────────────────────────────────────────────────
|
|
|
|
// uuid_new — generate a new random UUID v4.
|
|
fn uuid_new() -> String {
|
|
return __uuid_v4()
|
|
}
|
|
|
|
// uuid_v4 — alias for uuid_new(); explicit version name for callers that
|
|
// need to be precise about the UUID variant.
|
|
fn uuid_v4() -> String {
|
|
return __uuid_v4()
|
|
}
|