Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

45
LINES

< > BotCompany Repo | #1035280 // VarContext backup

JavaX fragment (include)

1  
// VarContext is thread-safe AFTER the first variable has been defined
2  
// or after you call makeThreadSafe(), whichever comes first
3  
sclass VarContext {
4  
  gettable VarContext parent;
5  
  MapSO vars;
6  
  
7  
  *() {}
8  
  *(VarContext *parent) {}
9  
  
10  
  O get(S name) {
11  
    if (containsKey(vars, name))
12  
      ret mapGet(vars, name);
13  
    if (parent != null)
14  
      ret parent.get(name);
15  
    null;
16  
  }
17  
  
18  
  void set aka put(S name, O value) {
19  
    vars = putOrCreateSyncMap(vars, name, value);
20  
  }
21  
  
22  
  AutoCloseable tempSet aka tempPut(S name, O value) {
23  
    initMap();
24  
    ret main tempPut(vars, name, value);
25  
  }
26  
  
27  
  void unset(S name) {
28  
    remove(vars, name);
29  
  }
30  
  
31  
  void printMe {
32  
    pnl(vars);
33  
    print(+parent);
34  
  }
35  
  
36  
  void makeThreadSafe aka initMap() {
37  
    vars if null = syncHashMap();
38  
  }
39  
  
40  
  // mechanism for returning from a script
41  
  
42  
  settable O exitFromScript;
43  
  settable O returnValue;
44  
  bool exiting() { ping(); ret exitFromScript != null; }
45  
}

Author comment

Began life as a copy of #1033977

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1035280
Snippet name: VarContext backup
Eternal ID of this version: #1035280/1
Text MD5: 3b590f29956b73c75e64797498dafe4d
Author: stefan
Category: javax / parsing
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-04-28 22:42:32
Source code size: 996 bytes / 45 lines
Pitched / IR pitched: No / No
Views / Downloads: 161 / 174
Referenced in: [show references]