... which is what I crazily didI recently realised that __expr cannot easily be made to work with the pre-v1.0.48 beta, since all expressions must be pre-tokenized before evaluation. In other words, it would need to implement a full expression parser, which is simply something I will not do. (If Line::ExpressionToPostfix() were exposed to script it would be possible, but permanent memory would be allocated for each expression evaluated.)
Introducing...
expr() v1.0
This library allows you to dynamically execute AutoHotkey expressions on the fly, with NO temporary scripts at all! It works via parsing the expression manually using AHK source code translated from C++ to AHK (!), then executing it using a bit (understatement) of low-level magic. As such, it may or may not work with AutoHotkey versions newer than v1.1.08.
Usage is really simple:
MsgBox % eval("(1 + sqrt(5)) / 2") eval("DllCall(""MessageBox"", ""ptr"", 0, ""str"", ""Hello, world!"", ""str"", A_ScriptName, ""uint"", 0)") MsgBox % eval("eval(""2+2"")") ; you can even nest calls to eval()! eval("variable := ""value""") ; variables are also supported... eval("obj := { array: [2, 3, 5] }") ; even objects! MsgBox % variable " | " obj.array[2]Download - GitHub
Included with the package is
calculator.ahk
, which allows you to type commands. A fun one is this:ComObjCreate("SAPI.SpVoice").Speak("Hello world!")Limitations[*:1bxrzo80]You can only access global variables
[*:1bxrzo80]Double-derefs are not supported yet
[*:1bxrzo80]Clipboard is read-only
[*:1bxrzo80]ClipboardAll doesn't work
[*:1bxrzo80]
obj.field(something) := val
is not supported yet[*:1bxrzo80]Compound object field assignment is not supported yet