本文介绍了是否有一种方法在autoit脚本中查找当前文件是否包含在内还是单独运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的意思是像 get_included_files(); 在php或 Error()。stack; in javascript或 $ BASH_SOURCE bash中的数组?

I mean something like get_included_files(); in php or Error().stack; in javascript or $BASH_SOURCE array in bash ?

我只在宏中找到() @ScriptFullPath @ScriptName

I've only found in macros ( https://www.autoitscript.com/autoit3/docs/macros.htm ) @ScriptFullPath and @ScriptName.

推荐答案

你可以使用全局变量实现功能。说 $ includeDepth $ includeDepth 应在任何 #include 之前加1,并在之后递减1。如果 $ includeDepth 0 ,则代码不会作为 #include的一部分运行。例如:

You can implement the functionality by using a global variable. Say $includeDepth. $includeDepth should be incremented by 1 before any #include and decremented by 1 after it. If $includeDepth is 0, then the code is not running as part of an #include. For example:

Global $includeDepth
$includeDepth+= 1
#include <MyScript1.au3>
#include <MyScript2.au3>
$includeDepth-= 1

; Declarations, functions, and initializations to be run in both "include" and "non-include" modes

If $includeDepth <= 0 Then
    ; Code for when in "non-include" mode
EndIf

您需要非常一致但是在这种用法中。但是,只要库 #include s不包含您自己的脚本(或完成此检查的脚本),就不需要修改它们。从这个角度来看,在包含库 #include s时,也没有必要增加/减少 $ includeDepth 。然而,它并没有伤害,它强化了这种做法。

You need to be very consistent in this usage, though. However, as long as library #includes don't include your own scripts (or scripts where this checking is done), there is no need to modify them. From this point of view, it's also not necessary to increment/decrement $includeDepth while including library #includes. However, it doesn't hurt and it reinforces the practice.

这篇关于是否有一种方法在autoit脚本中查找当前文件是否包含在内还是单独运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 02:23