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

53
LINES

< > BotCompany Repo | #1003201 - addStdFunction - Add a standard function to list (edits #761, works/LIVE)

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (9340L/71K).

// add latest include
static S addStdFunction() {
  loading {
    ret addStdFunction(findLatestInclude().id, true);
  }
}

static S addStdFunction(bool realEdit) {
  ret addStdFunction(findLatestInclude().id, realEdit);
}

static S addStdFunction_1006654;

static S addStdFunction(S snippetID, bool realEdit) {
  loading {
    LS names = 
      // OLD findFunctionDefinitions(loadSnippet(snippetID));
      findFunctionDefs(loadSnippet(snippetID));
    printStructure("Functions defined in " + snippetID + ": ", names);
    if (empty(names)) ret "No functions found in " + snippetID;
    S name = firstNotStartingWith(names, "_onLoad_");
    if (empty(names)) ret "No definable functions found in " + snippetID;
    
    if (addStdFunction_1006654 == null)
      addStdFunction_1006654 = loadSnippet(#1006654);
    Map<S, S> map = parseStdFunctionsList(addStdFunction_1006654);
    S text = loadSnippet("#761");
    map.putAll(parseStdFunctionsList(text));
    S def = map.get(name);
    S result = "";
    if (def == null) {
      print(result = "Defining " + name + ".");
      
      S newText = addToStdFunctionsList(text, name, snippetID);
      print();
      print(unidiff(text, newText));
      if (!realEdit)
        print(result += " Not editing (test mode).");
      else {
        editSnippet("#761", newText);
        triggerTranspilerDirty();
        print(result += " Edited #761. Now " + countLines(newText) + " lines - " + n(l(map)+1, "total function") + "!");
      }
    } else {
      print(result = "Function " + name + " already defined as " + def);
      if (sameSnippetID(def, snippetID))
        print("Exiting.");
      else
        print("Will not redefine as " + snippetID + ".");
    }
    ret result;
  }
}

Author comment

Began life as a copy of #1003192

download  show line numbers  debug dex   

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

No comments. add comment

Snippet ID: #1003201
Snippet name: addStdFunction - Add a standard function to list (edits #761, works/LIVE)
Eternal ID of this version: #1003201/10
Text MD5: b76fd42bae139c3225d1145410e3ad24
Transpilation MD5: 5bfff71f08b5a0596d0aec5ca1dbb045
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-08-11 12:38:22
Source code size: 1788 bytes / 53 lines
Pitched / IR pitched: No / No
Views / Downloads: 504 / 472
Version history: 9 change(s)
Referenced in: [show references]

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