eval() - evaluate AutoHotkey expressions dynamically!

Some of you may remember that Lexikos' LowLevel.ahk used to support a nifty function called __expr(), but then...

I 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.)

... which is what I crazily did

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.

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

Marine Corps Gen. Joseph Dunford told senators at his Joint Chiefs of Staff confirmation hearing : “If you want to talk about a nation that could pose an existential threat to the United States, I'd have to point to Russia. And if you look at their behavior, it's nothing short of alarming.”

Laszlo's Monster does not support the full AutoHotkey expression syntax (including strings, objects and built-in functions/variables) and it sometimes did not evaluate expressions correctly when I was testing it a long time ago (sadly, I cannot remember which expressions they were).

How does it compare to ExprEval(), which presumably isn't as version-dependent? Since you haven't mentioned ternary or short-circuit evaluation, I presume your function supports those.

This library does support both ternary and short-circuit evaluation, as it's a pretty straightforward translation of AHK's expression parsing code. It also supports object syntax, variable operations (with some restrictions on built-in variables that are to be fixed) as well as function operations (including variadic calls). Also, it may be faster because it does not use RegEx (unlike Monster or ExprEval), it doesn't do ugly string operations (which the others do due to AHK Basic's lack of objects) and it lets AHK itself perform the evaluation (I haven't benchmarked it). Also, the source code is significantly more readable

MasterFocus: no, AutoHotkey Basic is ridiculously outdated and I don't plan on making scripts compatible with it anymore. Not to mention I make heavy use of objects and other new features, and in this case internal AHK structures.