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)

static O loadVariableDefinition(S varName) {
  ret loadVariableDefinition(getProgramID(), varName);
}

// currently works with string lists ("= litlist(...)"),
// strings, longs and ints.
static O loadVariableDefinition(S progIDOrSrc, S varName) {
  if (isSnippetID(progIDOrSrc))
    progIDOrSrc = loadSnippet(progIDOrSrc);
  ret loadVariableDefinition(progIDOrSrc, javaTok(progIDOrSrc), varName);
}
    
static O loadVariableDefinition(S src, L<S> tok, S varName) {
  int i = findCodeTokens(tok, varName, "=");
  if (i < 0) ret null;
  
  i += 4;
  S t = tok.get(i);
  
  if (isQuoted(t))
    ret unquote(t);
    
  if (isLongConstant(t))
    ret parseLong(t);
    
  if (isInteger(t))
    ret parseInt(t);
  
  if (eqOneOf(t, "litlist", "ll") && eq(get(tok, i+2), "(")) {
    int opening = i+2;
    int closing = findEndOfBracketPart(tok, opening)-1;
    new L l;
    for (i = opening+2; i < closing; i += 4)
      l.add(unquote(tok.get(i)));
    ret l;
  }
  
  throw fail("Unknown variable type or no definition in source: " + shorten(src, 100) + "/" + varName);
}

download  show line numbers  debug dex   

Travelled to 10 computer(s): aoiabmzegqzx, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, tslmcundralx, tvejysmllsmz

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: 488 / 1473
Version history: 8 change(s)
Referenced in: [show references]

Formerly at http://tinybrain.de/1001996 & http://1001996.tinybrain.de