Skip to content

Commit

Permalink
add Eval command (only available in AHK_X11, not Windows)
Browse files Browse the repository at this point in the history
  • Loading branch information
phil294 committed Dec 10, 2023
1 parent da43e34 commit 1f3e9da
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 8 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ AHK_X11 can be used completely without a terminal. You can however if you want u
<details><summary>*Click here* to see which commands are implemented and which are missing. Note however that this is not very representative. For example, no `Gui` sub command is included in the listing. For a better overview on what is already done, skim through the <a href="https://phil294.github.io/AHK_X11"><b>full documentation here</b></a>. Generally speaking, everything important is done.</summary>

```diff
DONE 57% (126/220):
DONE 57% (126/221):
+ Else, { ... }, Break, Continue, Return, Exit, GoSub, GoTo, IfEqual, Loop, SetEnv, Sleep, FileCopy,
+ SetTimer, WinActivate, MsgBox, Gui, SendRaw, #Persistent, ExitApp,
+ EnvAdd, EnvSub, EnvMult, EnvDiv, ControlSendRaw, IfWinExist/IfWinNotExist, SetWorkingDir,
Expand All @@ -155,11 +155,11 @@ DONE 57% (126/220):
+ WinWaitClose, WinWaitActive, WinWaitNotActive, DriveSpaceFree, FileGetSize, FileRecycle,
+ FileRecycleEmpty, SplitPath, StringSplit

NEW 4% (9/220): (not part of spec or from a more recent version)
NEW 4% (10/221): (not part of spec or from a more recent version)
@@ Echo, ahk_x11_print_vars, FileRead, RegExGetPos, RegExReplace, EnvGet, Click @@
@@ ahk_x11_track_performance_start, ahk_x11_track_performance_stop @@
@@ Eval, ahk_x11_track_performance_start, ahk_x11_track_performance_stop @@

REMOVED 5% (11/220):
REMOVED 5% (11/221):
# ### Those that simply make no sense in Linux:
# EnvUpdate, PostMessage, RegDelete, RegRead, RegWrite, SendMessage, #InstallKeybdHook,
# #InstallMouseHook, #UseHook, Loop (registry)
Expand All @@ -168,7 +168,7 @@ REMOVED 5% (11/220):
# AutoTrim: It's always Off. It would not differentiate between %a_space% and %some_var%.
# It's possible but needs significant work.

TO DO 32% (71/220): alphabetically
TO DO 32% (71/221): alphabetically
- BlockInput, Control, ControlFocus, ControlGet, ControlGetFocus, ControlMove, DetectHiddenText,
- DetectHiddenWindows, Drive, DriveGet, FileCopyDir, FileCreateShortcut, FileInstall, FileGetAttrib,
- FileGetShortcut, FileGetTime, FileGetVersion, FileMove, FileMoveDir, FileRemoveDir, FormatTime,
Expand Down
40 changes: 40 additions & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,9 @@ <h2>Table of contents </h2>
<li>
<a href="#Edit.htm">Edit</a>
</li>
<li>
<a class="x11" href="#Eval.htm">Eval</a>
</li>
<li>
<a class="tbd" href="#ListLines.htm">ListLines</a>
</li>
Expand Down Expand Up @@ -733,6 +736,7 @@ <h2>Table of contents </h2>
<li>
<a class="tbd" href="#WinGetActiveStats.htm">WinGetActiveStats</a>
</li>

<li>
<a class="tbd" href="#WinGetActiveTitle.htm">WinGetActiveTitle</a>
</li>
Expand Down Expand Up @@ -2150,6 +2154,10 @@ <h2 class="calibre9"><span class="calibre23">The "Last Found" Window </span></h2
<td height="16" class="calibre4"><a href="#EnvSub.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">EnvSub</a></td>
<td height="16" class="calibre4">Sets a <a href="#Variables.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">variable</a> to itself minus the given value (can also compare <a href="#FileSetTime.htm__YYYYMMDD" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">date-time</a> values). Synonymous with: var -= value</td>
</tr>
<tr class="calibre3">
<td height="16" class="calibre4"><a href="#Eval.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">Eval</a></td>
<td height="16" class="calibre4">Takes a string argument and runs it as commands.</td>
</tr>
<tr class="calibre3">
<td height="16" class="calibre4"><a href="#Exit.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">Exit</a></td>
<td height="16" class="calibre4">Exits the <a href="#Threads.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">current thread</a> or (if the script is not <a href="#h_Persistent.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">persistent</a> contains no hotkeys) the entire script.</td>
Expand Down Expand Up @@ -9573,6 +9581,38 @@ <h2 class="calibre9"><span class="calibre23">The "Last Found" Window </span></h2
<p class="calibre8"> </p>
</div>
</div>
<div class="calibreMain x11">
<div class="calibreEbookContent">
<a id="Eval.htm" href="#Eval.htm">#</a> <h2 class="calibre17">Eval</h2>
<hr size="2" class="calibre24" />
<p class="calibre8">Takes a string argument and runs it as commands.</p>
<table cellspacing="5" width="100%" class="calibre28">
<tbody class="calibre2">
<tr class="calibre3">
<td height="48" class="calibre4">Eval, Commands</td>
</tr>
</tbody>
</table>
<p class="calibre8"> </p>
<p class="calibre8"><strong class="calibre14">Parameters</strong></p>
<table border="1" bordercolor="#C0C0C0" cellpadding="3" cellspacing="0" width="100%" class="calibre1">
<tbody class="calibre2">
<tr class="calibre3">
<td width="15%" class="calibre4">Commands</td>
<td width="85%" class="calibre4">
The commands to run. May include line breaks to run multiple. E.g. <code>Eval, Msgbox 1`nMsgbox 2</code>
</td>
</tr>
</tbody>
</table>
<p class="calibre8"> </p>
<p class="calibre8"><strong class="calibre14">Remarks</strong></p>
<p class="calibre8">Thread variables such as ErrorLevel cannot be accessed as the code is executed in its own thread, run immediately.</p>
<p class="calibre8"> </p>
<p class="calibre8"><strong class="calibre14">Example</strong></p>
<p class="calibre8">; Run a dynamic command:<br class="calibre12" /> cmd = MsgBox<br class="calibre12" /> Eval, %cmd% Hello</p>
</div>
</div>
<div class="calibreMain tbd">
<div class="calibreEbookContent">
<a id="ListLines.htm" href="#ListLines.htm">#</a> <h2 class="calibre17">ListLines</h2>
Expand Down
8 changes: 8 additions & 0 deletions src/cmd/misc/eval.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# This command doesn't exist in Windows AHK
class Cmd::Misc::Eval < Cmd::Base
def self.min_args; 1 end
def self.max_args; 1 end
def run(thread, args)
thread.runner.eval args[0].split('\n')
end
end
10 changes: 7 additions & 3 deletions src/run/runner.cr
Original file line number Diff line number Diff line change
Expand Up @@ -214,16 +214,20 @@ module Run
break # i.e. there is no stdin, it was closed or never existed like when run via double click.
end
begin
@builder.build [line]
add_thread @builder.start.not_nil!, "", 0 if @builder.start
Fiber.yield
eval [line]
rescue e
STDERR.puts e.message
end
end
end
end

def eval(lines)
@builder.build lines
add_thread @builder.start.not_nil!, "", 0 if @builder.start
Fiber.yield
end

# Do not use directly, use `Thread.get_var` instead.
# Get the value of global values, regardless if user set or not.
# Case sensitive.
Expand Down

0 comments on commit 1f3e9da

Please sign in to comment.