- These 2 lines serve a similar purpose:
#Include <MyPrefix_MyFunc>
MyPrefix_MyFunc()
- Assuming that the function 'MyPrefix_MyFunc' isn't already defined. Both check 3 'Lib' folders for scripts called 'MyPrefix_MyFunc.ahk', and then check 3 'Lib' folders for 'MyPrefix.ahk'.
Code: Select all
;when you do either:
;#Include <MyPrefix_MyFunc>
;or (when the following function does not exist in the current script):
;MyPrefix_MyFunc()
;3 library folders are checked for, listed in the order that they are checked for:
;%A_ScriptDir%\Lib ;local library
;%A_MyDocuments%\Lib ;user library
;%A_AhkDir%\Lib ;standard library [there is no such variable in AHK at present][where 'A_AhkDir' would be the dir taken from 'A_AhkPath']
;6 files are checked for, listed in the order that they are checked for:
;%A_ScriptDir%\Lib\MyPrefix_MyFunc.ahk
;%A_MyDocuments%\Lib\MyPrefix_MyFunc.ahk
;%A_AhkDir%\Lib\MyPrefix_MyFunc.ahk
;%A_ScriptDir%\Lib\MyPrefix.ahk
;%A_MyDocuments%\Lib\MyPrefix.ahk
;%A_AhkDir%\Lib\MyPrefix.ahk
;if no matching file is found, an error is raised:
;either:
;'Error: Function library not found.'
;or:
;'Error: Call to nonexistent function.'
- However, calling a non-existent function appears to #Include the code, but not at the point where the function was called, and not at the beginning or end of the script. Any code in the included script (outside of function definitions) is *not* executed.
- When you call a non-existent function, where does it 'put' the code, what exactly happens. Thanks.
- (I would be tempted to say that a 'return' line is placed at the bottom of the script, followed by the included script.)
Code: Select all
;script 1A ;shows 1 2 3 4
MsgBox, 1
#Include <MyPrefix_MyFunc>
MsgBox, 4
;==================================================
;script 1B ;shows 1 then 4
MsgBox, 1
MyPrefix_MyFunc()
MsgBox, 4
;==================================================
;script 2 ;location: %A_ScriptDir%\Lib\MyPrefix_MyFunc.ahk
MsgBox, 2
MyPrefix_MyFunc()
{
SoundBeep
}
MsgBox, 3
#Include / #IncludeAgain - Syntax & Usage | AutoHotkey
https://autohotkey.com/docs/commands/_Include.htm
Functions - Definition & Usage | AutoHotkey
https://autohotkey.com/docs/Functions.htm#lib
- [EDIT:] Note: I tried using lines like this to cause an error to get a MsgBox which lists nearby lines, to look for a 'return' line or equivalent:
Code: Select all
var := "A_DetectHiddenWindows"
%var% := 1
- Thus the user has a choice: #Include <LibName> to execute any code in the included script (but not execute the function that is being looked for, you have to add a line if you want to explicitly execute it), and auto-include to execute the function (but not execute any other code in the included script).
- However, both have the effect of making any functions available for use.
- And if you use auto-include to include a function that does nothing, that has the effect of making functions available to use, without including any code the library at the specific point.
- In conclusion, an auto-include 'includes' a script, in the sense that all of its functions are made available for use, however, it does not 'copy and paste' the file contents to a specific point.