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

38
LINES

< > BotCompany Repo | #1000797 - "set" - Run program with changed variables [old]

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (893L/6K/20K).

// Syntax example: javax 1000797 timeout=500 1000796

!747
!class _javax 19

m {
  p {
    int i;
    for (i = 0; i < args.length; i++) {
      int idx = args[i].indexOf("=");
      if (idx < 0) break;
    }
    
    S progID = args[i];
    Class prog = hotwire(progID);
    for (int j = 0; j < i; j++) {
      S arg = args[j];
      int idx = arg.indexOf("=");
      S var = arg.substring(0, idx);
      S value = arg.substring(idx+1);
      setFlex(prog, var, value);
    }
    callMain(prog, dropFirst(i+1, args));
  }
  
  static void setFlex(Class c, String var, String value) {
    Field f = findField(c, var);
    Class t = f.getType();
    O v = value;
    if (t == Integer.class || t == int.class)
      v = Integer.parseInt(value);
    else if (t == Long.class || t == long.class)
      v = Long.parseLong(value);
    else if (t == Boolean.class || t == boolean.class)
      v = Boolean.parseBoolean(value);
    set(c, var, v);
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 16 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, jtubtzbbkimh, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, teubizvjbppd, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1000797
Snippet name: "set" - Run program with changed variables [old]
Eternal ID of this version: #1000797/1
Text MD5: ce4a96db9503d7bfc6c7d12459416bf0
Transpilation MD5: b777fc477fd6683dc4bf975a4e97d843
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-09-13 14:05:34
Source code size: 980 bytes / 38 lines
Pitched / IR pitched: No / No
Views / Downloads: 539 / 901
Referenced in: [show references]