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).

1  
// add latest include
2  
static S addStdFunction() {
3  
  loading {
4  
    ret addStdFunction(findLatestInclude().id, true);
5  
  }
6  
}
7  
8  
static S addStdFunction(bool realEdit) {
9  
  ret addStdFunction(findLatestInclude().id, realEdit);
10  
}
11  
12  
static S addStdFunction_1006654;
13  
14  
static S addStdFunction(S snippetID, bool realEdit) {
15  
  loading {
16  
    LS names = 
17  
      findFunctionDefsAtCurlyLevel(0, loadSnippet(snippetID));
18  
    printStructure("Functions defined in " + snippetID + ": ", names);
19  
    if (empty(names)) ret "No functions found in " + snippetID;
20  
    S name = firstNotStartingWith(names, "_onLoad_");
21  
    if (empty(names)) ret "No definable functions found in " + snippetID;
22  
    
23  
    if (addStdFunction_1006654 == null)
24  
      addStdFunction_1006654 = loadSnippet(#1006654);
25  
    Map<S, S> map = parseStdFunctionsList(addStdFunction_1006654);
26  
    S text = loadSnippet("#761");
27  
    map.putAll(parseStdFunctionsList(text));
28  
    S def = map.get(name);
29  
    S result = "";
30  
    if (def == null) {
31  
      print(result = "Defining " + name + ".");
32  
      
33  
      S newText = addToStdFunctionsList(text, name, snippetID);
34  
      print();
35  
      print(unidiff(text, newText));
36  
      if (!realEdit)
37  
        print(result += " Not editing (test mode).");
38  
      else {
39  
        editSnippet("#761", newText);
40  
        triggerTranspilerDirty();
41  
        print(result += " Edited #761. Now " + countLines(newText) + " lines - " + n(l(map)+1, "total function") + "!");
42  
      }
43  
    } else {
44  
      print(result = "Function " + name + " already defined as " + def);
45  
      if (sameSnippetID(def, snippetID))
46  
        print("Exiting.");
47  
      else
48  
        print("Will not redefine as " + snippetID + ".");
49  
    }
50  
    ret result;
51  
  }
52  
}

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: 693 / 712
Version history: 10 change(s)
Referenced in: [show references]