1 | sbool codeWithHintsToFunctionOnString_verbose; |
2 | |
3 | static <A> F1<S, A> codeWithHintsToFunctionOnString(S code) {
|
4 | ret codeWithHintsToFunctionOnString(code, ""); |
5 | } |
6 | |
7 | static <A> F1<S, A> codeWithHintsToFunctionOnString(S code, S hints) {
|
8 | code = trim(code); |
9 | Class c; |
10 | S methodName; |
11 | if (isIdentifier(code)) { // name of standard function
|
12 | c = loadFunctions_cached_withInit(code); |
13 | methodName = code; |
14 | } else if (jcontains(code, "calc(")) { // code defines its own calc function
|
15 | c = veryQuickJava(code); |
16 | methodName = 'calc; |
17 | } else { // code is an expression or block working on variable s
|
18 | S main = "sO calc(fS s) {\n" + tok_addReturn(code) + "\n}";
|
19 | if (codeWithHintsToFunctionOnString_verbose) print(main); |
20 | c = veryQuickJava(main); |
21 | if (codeWithHintsToFunctionOnString_verbose) print(c); |
22 | methodName = 'calc; |
23 | } |
24 | |
25 | final Method m = findMethod_precise(c, methodName, ""); |
26 | if (m == null) fail("Not a method on a string: " + code);
|
27 | ret func(S s) -> A { (A) invokeMethod(m, null, s) };
|
28 | } |
download show line numbers debug dex old transpilations
Travelled to 8 computer(s): bhatertpkbcr, cfunsshuasjs, gwrvuhgaqvyk, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1020643 |
| Snippet name: | codeWithHintsToFunctionOnString |
| Eternal ID of this version: | #1020643/11 |
| Text MD5: | d1b2c073a14d25d4268947326415be2c |
| Author: | stefan |
| Category: | javax |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2019-02-05 14:47:19 |
| Source code size: | 1051 bytes / 28 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 627 / 676 |
| Version history: | 10 change(s) |
| Referenced in: | [show references] |