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

52
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 (12772L/85K).

// 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 = 
      findFunctionDefsAtCurlyLevel(0, 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  old transpilations   

Travelled to 16 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, 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/11
Text MD5: 943b37deb64efdb7eb66294c5b2e9ea0
Transpilation MD5: f983ae7710536414c88feb2afe3a837c
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-02-10 00:19:24
Source code size: 1740 bytes / 52 lines
Pitched / IR pitched: No / No
Views / Downloads: 802 / 815
Version history: 10 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)
#1015595 - addStdFunctionWithAnimation
#1015881 - addStdClass - Add a standard class to list (edits #1003674)
#1022537 - addAlternateStdFunction