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

55
LINES

< > BotCompany Repo | #1022766 // Standard function as module (transpiled on the spot)

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 911K of libraries. Click here for Pure Java version (12637L/70K).

!7

set flag replaceACCInClassLoader_fullException.
set flag DynModule. // use central transpiler

cmodule StandardFunction {
  switchable S functionName;
  transient DynamicCallable f;
  transient Throwable error;
  
  start {
    dm_registerAs('standardFunctionHolder);
    onChange(r updateStatuses);
    loadFunction();
  }
  
  visual
    vstack(centerAndEastWithMargins(
      withLabel("Function:", dm_label('functionName)),
      jThreadedButton("Choose...", rEnter { dm_stringFieldDialog('functionName, onSet := rEnter newFunctionName) })));
      
  void newFunctionName() {
    setField(f := null);
    setField(error := null);
    loadFunction();
  }
  
  void updateStatuses {
    setModuleName(
      empty(functionName) ? "Standard function as module"
      : "Function " + functionName + " - "
      + (hasError() ? "Error" : loaded() ? "loaded" : "not loaded"));
  }
  
  void loadFunction() q {
    try {
      setField(f := methodAsDynamicCallable(loadFunctions_cached(functionName), functionName));
    } catch e {
      setFields(f := null, error := e);
    }
  }
  
  // API
  
  S functionName() { ret functionName; }
  
  O callTheFunction(O... args) {
    while (f == null && error == null) sleep(10);
    if (error != null) throw rethrow(error);
    ret callF(f, args);
  }
  
  bool loaded() { ret f != null; }
  bool hasError() { ret error != null; }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1022766
Snippet name: Standard function as module (transpiled on the spot)
Eternal ID of this version: #1022766/15
Text MD5: fcd3bc2493fd338eb4808b247e759e14
Transpilation MD5: 56846eb6a9d088484cc85fd49a8571aa
Author: stefan
Category: javax / stefan's os
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-04-06 23:37:52
Source code size: 1434 bytes / 55 lines
Pitched / IR pitched: No / No
Views / Downloads: 201 / 572
Version history: 14 change(s)
Referenced in: [show references]