Hi, here's something I have been toying with. It can evaluate functions/methods and can access/define global variables/arrays/objects. It can only access array/objects through a[1][2][3]... form (does not support a.b.c.d form or a[1,2,3...] form). It does not recognize operators, so everything needs to be wrapped in a function. The ones I wrote can be found inside class f (f.add, f.mul, f.div ...). I have also written some basic Boolean logic functions (AND, OR) and they support short-circuiting (f.and, f.or). There is also a simple if/else function (f._if). If everything is working properly you should be able to nest functions/arrays inside each other.
I originally built this with the intention of using this over WM_COPYDATA so I can remote control my scripts and not have to write extra wrapper functions.
edit1: Having trouble with indentation. GitHub: https://github.com/oif2003/AHK_v2_64bit ... r/eval.ahk
edit2: Added support for nested variadic functions. ie: f( g( h( param* )* )* )
[AHK v2] Evaluate Function
[AHK v2] Evaluate Function
Last edited by oif2003 on 31 Oct 2018, 16:52, edited 1 time in total.
Re: [AHK v2] Evaluate Function
Added support for operator notations. The script now does the following:
1) User input string for evaluation
2) Save all string literals (stuff inside quotation marks) and replace them with tokens
3) Convert Infix operators to Prefix (functions)
4) Parse the functions based on its type:
Currently, arrays and objects must be referred to in a[1][2][3]... form
Assignments such as a:=[1,2,3] is not supported. Use a:=Array(1,2,3) instead
Edit: Added Ternary operator support
1) User input string for evaluation
2) Save all string literals (stuff inside quotation marks) and replace them with tokens
3) Convert Infix operators to Prefix (functions)
4) Parse the functions based on its type:
- a) string - get rid of quotation marks
b) function / method - evaluate
c) object / array - get its value
d) number - convert it from string to value (=> number + 0)
e) variable - %variable%
f) keep parsing until we get one of the above
Currently, arrays and objects must be referred to in a[1][2][3]... form
Assignments such as a:=[1,2,3] is not supported. Use a:=Array(1,2,3) instead
Edit: Added Ternary operator support
Re: [AHK v2] Evaluate Function
A few simple tests works fine, nice work. Thanks for sharing.
Cheers .
Cheers .
Return to “Scripts and Functions (v2)”
Who is online
Users browsing this forum: No registered users and 35 guests