Eval [v1.2T]

作者: Laszlo 最近更新时间: 20100818


This is a way of getting the result of dynamically processed math operations in a string. The main point is not providing a standalone calculator, because there are hundreds of free ones available, but to allow evaluating a math expression typed in an editor or word processor.

Eval(x)
Eval_1(x)
Eval_Choose(n,k)
Eval_fac(n)
Eval_Fib(n)
Eval_FromBin(bits)
Eval_GCD(a,b)
Eval_MAX(a,b)
Eval_MIN(a,b)
Eval_Sgn(x)
Eval_ToBin(n)
Eval_ToBinW(n,W=8)

关于函数的参数和返回值, 请参阅其源码或 此文档.

备注

Requires Ahk Version 1.0.48+

The documentation is part of original author`s post at the forum.

I have modified the source (version number contains T for Tuncay)to make it stdlib conform. To accomplish that, I have outcommented lines from autoexecution section and added the prefix Eval_ to all functions. Eval1() becomes Eval_1() and Fib() becomes Eval_Fib() etc...

关于此函数(集)的更新细节和注意事项, 请参见 AutoHotkey 论坛: http://www.autohotkey.com/forum/viewtopic.php?t=17058

许可

不存在

示例

; #Include Eval.ahk
#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%
#SingleInstance Force
SetBatchLines -1
Process Priority,,High

MsgBox % "Eval(""100 + 22 - 55"") expresses to: " .  Eval("100 + 22 - 55")
MsgBox Next, the script waits for the hotkeys WIN+- and WIN+= (Win and minus key and Win and equal sign). Select any text to express and see the result. One key replaces and the other one append the result.

; Monster by Laszlo
#-::                                  ; Replace selection or `expression with result
#=::                                  ; Append result to selection or `expression
   ClipBoard =
   SendInput ^c                        ; copy selection
   ClipWait 0.5
   If (ErrorLevel) {
      SendInput +{HOME}^c              ; copy, keep selection to overwrite (^x for some apps)
      ClipWait 1
      IfEqual ErrorLevel,1, Return
      If RegExMatch(ClipBoard, "(.*)(``)(.*)", y)
         SendInput %  "{RAW}" y1 . (A_ThisHotKey="#=" ? y3 . " = "  : "") . Eval(y3)
   } Else
      SendInput % "{RAW}" . (A_ThisHotKey="#=" ? ClipBoard . " = "  : "") . Eval(ClipBoard)
Return