Best way to run standalone library when not #included

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
iseahound
Posts: 1434
Joined: 13 Aug 2016, 21:04
Contact:

Best way to run standalone library when not #included

Post by iseahound » 19 Jan 2022, 00:51

The idea is to emulate what python does with __name__ == __main__:
1) If imported it does nothing.
2) If run standalone, the code will execute.


I believe the AutoHotkey equivalent is this?

Code: Select all

if (A_LineFile == A_ScriptFullPath) {
   MsgBox % "hi"
}
But note: If the script was compiled based on a .bin file, this is the full path and name of the current executable file, the same as A_ScriptFullPath.

Lorien
Posts: 33
Joined: 10 Dec 2019, 11:16

Re: Best way to run standalone library when not #included

Post by Lorien » 07 Apr 2022, 06:03

I was looking for a way to do this too. What about checking A_IsCompiled into the expression?

Code: Select all

If ((! A_IsCompiled) and (A_LineFile == A_ScriptFullPath)) {
	;Do something cool.
}

Post Reply

Return to “Ask for Help (v1)”