Home /Modules/operating-system/SLEnvironment.sleela

SLEnvironment.sleela

lib/operating-system/SLEnvironment.sleela · 97 line(s) · sleela

<< lib/operating-system/SLEnvironment.sleela
   SLeeLa Standard Library Definition.
   Definition: Defines SLEnvironment — read/write access to the host process
     environment (environment variables) and a few well-known entries. Reads go
     through osGetEnv and writes through osSetEnv, which call the real host API
     (GetEnvironmentVariable/SetEnvironmentVariable on Windows, getenv/setenv on
     POSIX). A variable that is unset reads back as the empty string.
   
   Family: operating-system. Native VM/OS work crosses the explicit `os*` SLVM bridge. >>
#sleela 2.5
material;
class SLEnvironment {
  < ---- Descriptive metadata (version 1.11 nested-friendly accessors) ---- >
  << Eleven catalogued attributes with getter/setter pairs, so a GUI, loader,
     or catalog can read and (where appropriate) override this record.
     Values are faithful to the subject's real origin where publicly known. >>
  String metaVersion = "1.0.0";
  int metaId = 356;
  String metaAuthor = "Max Rupplin vs. Dr. Mrs. Elisabeth Harkins";
  String metaDate = "2026-10-16";
  String metaCopyright = "SLeeLa project";
  String metaTrademark = "none";
  String metaCorporation = "none";
  < metaOrigin: National | <nation> | International | Galactic >
  String metaOrigin = "International";
  String metaBirthDate = "2026-09-28";
  < metaScienceRating: maturity/robustness on a 1..10 scale >
  int metaScienceRating = 9;
  < metaNationalSchedule: a real, citable instrument or "none" >
  String metaNationalSchedule = "none";

  String getMetaVersion() { return metaVersion; }
  void setMetaVersion(String v) { metaVersion = v; }
  int getMetaId() { return metaId; }
  void setMetaId(int v) { metaId = v; }
  String getAuthor() { return metaAuthor; }
  void setAuthor(String v) { metaAuthor = v; }
  String getDate() { return metaDate; }
  void setDate(String v) { metaDate = v; }
  String getCopyright() { return metaCopyright; }
  void setCopyright(String v) { metaCopyright = v; }
  String getTrademark() { return metaTrademark; }
  void setTrademark(String v) { metaTrademark = v; }
  String getCorporation() { return metaCorporation; }
  void setCorporation(String v) { metaCorporation = v; }
  String getOrigin() { return metaOrigin; }
  void setOrigin(String v) { metaOrigin = v; }
  String getBirthDate() { return metaBirthDate; }
  void setBirthDate(String v) { metaBirthDate = v; }
  int getScienceRating() { return metaScienceRating; }
  void setScienceRating(int v) { metaScienceRating = v; }
  String getNationalSchedule() { return metaNationalSchedule; }
  void setNationalSchedule(String v) { metaNationalSchedule = v; }
  int reads;
  int writes;

  void configure() { reads = 0; writes = 0; }

  < Read a variable; "" when unset. Tracks a read count for observability. >
  String get(String key) { reads = reads + 1; return osGetEnv(key); }

  < Read with a fallback used when the variable is unset (empty). >
  String getOrDefault(String key, String fallback) {
    String v = osGetEnv(key);
    reads = reads + 1;
    if (v == "") { return fallback; }
    return v;
  }

  < True when the variable is present (non-empty). >
  boolean has(String key) { reads = reads + 1; return osGetEnv(key) != ""; }

  < Set (overwrite) a variable; returns true on success. >
  boolean set(String key, String value) {
    writes = writes + 1;
    return osSetEnv(key, value) == 0;
  }

  < Common entries, resolved per-OS by the host (PATH, HOME/USERPROFILE, ...). >
  String path() { return osGetEnv("PATH"); }
  String home() {
    String h = osGetEnv("HOME");
    if (h != "") { return h; }
    < Windows >
    return osGetEnv("USERPROFILE");
  }
  String shell() {
    String s = osGetEnv("SHELL");
    if (s != "") { return s; }
    < Windows (cmd.exe) >
    return osGetEnv("COMSPEC");
  }

  int readCount() { return reads; }
  int writeCount() { return writes; }
}