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

39
LINES

< > BotCompany Repo | #1001996 // loadVariableDefinition - executes a variable definition from up-to-date source

JavaX fragment (include)

1  
static O loadVariableDefinition(S varName) {
2  
  ret loadVariableDefinition(getProgramID(), varName);
3  
}
4  
5  
// currently works with string lists ("= litlist(...)"),
6  
// strings, longs and ints.
7  
static O loadVariableDefinition(S progIDOrSrc, S varName) {
8  
  if (isSnippetID(progIDOrSrc))
9  
    progIDOrSrc = loadSnippet(progIDOrSrc);
10  
  ret loadVariableDefinition(progIDOrSrc, javaTok(progIDOrSrc), varName);
11  
}
12  
    
13  
static O loadVariableDefinition(S src, L<S> tok, S varName) {
14  
  int i = findCodeTokens(tok, varName, "=");
15  
  if (i < 0) ret null;
16  
  
17  
  i += 4;
18  
  S t = tok.get(i);
19  
  
20  
  if (isQuoted(t))
21  
    ret unquote(t);
22  
    
23  
  if (isLongConstant(t))
24  
    ret parseLong(t);
25  
    
26  
  if (isInteger(t))
27  
    ret parseInt(t);
28  
  
29  
  if (eqOneOf(t, "litlist", "ll") && eq(get(tok, i+2), "(")) {
30  
    int opening = i+2;
31  
    int closing = findEndOfBracketPart(tok, opening)-1;
32  
    new L l;
33  
    for (i = opening+2; i < closing; i += 4)
34  
      l.add(unquote(tok.get(i)));
35  
    ret l;
36  
  }
37  
  
38  
  throw fail("Unknown variable type or no definition in source: " + shorten(src, 100) + "/" + varName);
39  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1001996
Snippet name: loadVariableDefinition - executes a variable definition from up-to-date source
Eternal ID of this version: #1001996/9
Text MD5: ade8df98a89ef7c7cc9662ff41e3f373
Author: stefan
Category:
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-12-25 16:11:59
Source code size: 1110 bytes / 39 lines
Pitched / IR pitched: No / No
Views / Downloads: 801 / 1924
Version history: 8 change(s)
Referenced in: [show references]