Skip to content

Commit

Permalink
Add built-in var A_IsCompiled (not part of v1.0.24 spec)
Browse files Browse the repository at this point in the history
  • Loading branch information
phil294 committed Jul 20, 2023
1 parent aa2e1c3 commit 775320b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
4 changes: 4 additions & 0 deletions docs/index.html
Expand Up @@ -1581,6 +1581,10 @@ <h4 class="calibre25"><a id="Variables.htm__prop" href="#Variables.htm__prop" cl
<td class="calibre4">A_AhkVersion</td>
<td class="calibre4"><a id="Variables.htm__AhkVersion" href="#Variables.htm__AhkVersion" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">#</a><span class="rm"> In versions prior to 1.0.22, this variable is blank. Otherwise, it contains the version of AutoHotkey that is running the script, such as 1.0.22. In the case of a <a href="#Scripts.htm__ahk2exe" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">compiled script</a>, the version that was originally used to compile it is reported.</span><span class="x11"> Always contains 1.0.24.</span></td>
</tr>
<tr class="calibre3">
<td class="calibre4">A_IsCompiled</td>
<td class="calibre4"><a id="Variables.htm__IsCompiled" href="#Variables.htm__IsCompiled" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">#</a>Contains 1 if the script is running as a compiled EXE and an empty string <span class="rm">(which is considered false)</span> if it is not.</td>
</tr>
<tr class="calibre3">
<td class="calibre4">A_ExitReason</td>
<td class="calibre4"><a id="Variables.htm__ExitReason" href="#Variables.htm__ExitReason" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">#</a><span class="tbd"> The most recent reason the script was asked to terminate. This variable is blank unless the script has an <a href="#OnExit.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">OnExit</a> subroutine and that subroutine is currently running or has been called at least once by an exit attempt. See <a href="#OnExit.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">OnExit</a> for details. </span></td>
Expand Down
3 changes: 2 additions & 1 deletion src/ahk_x11.cr
Expand Up @@ -59,6 +59,7 @@ end
script_file = nil
version = {{ read_file("./shard.yml").split("\n")[1][9..] }}
lines = Compiler.new.extract.try &.split('\n')
is_compiled = !! lines
if ! lines
# Only needed for installer script, this can't (yet) really be part of ahk code. TODO: rm on exit
File.write("/tmp/tmp_ahk_x11_logo.png", logo_blob)
Expand Down Expand Up @@ -104,7 +105,7 @@ rescue e : Build::SyntaxException | Build::ParsingException
end

begin
runner = Run::Runner.new builder: builder, script_file: script_file, headless: HEADLESS
runner = Run::Runner.new builder: builder, script_file: script_file, is_compiled: is_compiled, headless: HEADLESS
runner.run
rescue e : Run::RuntimeException
build_error e
Expand Down
4 changes: 3 additions & 1 deletion src/run/runner.cr
Expand Up @@ -62,14 +62,15 @@ module Run
property current_input_channel : Channel(String)?
@builder : Build::Builder
getter script_file : Path?
getter is_compiled : Bool
getter headless : Bool
@display : Display?
def display
raise "Cannot access Display in headless mode" if @headless
@display.not_nil!
end

def initialize(*, @builder, @script_file, @headless)
def initialize(*, @builder, @script_file, @is_compiled, @headless)
@labels = @builder.labels
@settings = @builder.runner_settings
script = @script_file ? @script_file.not_nil! : Path[binary_path].expand
Expand Down Expand Up @@ -257,6 +258,7 @@ module Run
when "a_isadmin" then Hacks.username == "root" ? "1" : "0"
when "a_computername" then `uname -n`
when "a_issuspended" then @suspension ? "1" : "0"
when "a_iscompiled" then @is_compiled ? "1" : ""
when "0" then (ARGV.size - (@script_file ? 1 : 0)).to_s
else
if i = var.to_i?
Expand Down

0 comments on commit 775320b

Please sign in to comment.