Repository navigation
Expand file tree
/
Copy pathexport.ahk
More file actions
114 lines (97 loc) · 3.16 KB
/
Copy pathexport.ahk
File metadata and controls
114 lines (97 loc) · 3.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
; ===================================================================================
; AHK Version ...: Tested with AHK v2.0-beta.1 x64 Unicode
; Win Version ...: Tested with Windows 10 Enterprise x64
; Authors ........: * Original - deo (original)
; ............... * Modifications - hoppfrosch
; License .......: MIT license (c) [2021] [Johannes Kilian] (https://opensource.org/licenses/MIT)
; Source ........: Original: https://autohotkey.com/board/topic/76062-ahk-l-how-to-get-callstack-solution/
; ................ V2 : https://github.com/AutoHotkey-V2/callstack.ahk
; ===================================================================================
/*
Title: callstack.ahk
(see https://img.shields.io/badge/Language-AutoHotkey2-red.svg)
Authors:
<hoppfrosch at hoppfrosch@gmx.de>: Original
License:
<MIT License: https://opensource.org/licenses/MIT> , (c) 2021, Johannes Kilian
*/
release_version() {
return "1.0.2"
}
/*
Function: CallStack
Gets the current callstack, containing information like functionname, filename and linenumber of the function.
Example:
=== Autohotkey ===========
#Include node_modules\callstack.ahk\export.ahk
foo()
return
foo(){
cs := CallStack()
# Print the current callstack
for level, obj in CallStack() {
if (A_Index > 1 )
str := str . " => "
str := str . obj.function ", line " obj.line
}
OutputDebug str
}
===
Parameters:
deepness - determines the depth of the determined callstack (optional, default := 100)
getContents - get the contents of the line, where the current function is called (optional, default := true)
Returns:
A map is returned, containing map elements in range of 0 to -calldepth (negative numbers).
Index 0 contains the info about current function, whereas Index -1 contains info about the parent (caller)
of the current function. (-2: Grandparent ...).
Each map element has the following members:
res[index].function - Name of the function at current index
res[index].depth - Depth (distance from main/Auto-Execute) at current index
res[index].file - name of the file at current index
res[index].line - line number within file at current index
res[index].contents - contents of line number at current index
*/
CallStack(deepness :=100, getContents := true) {
stack := Map()
max := 0
loop deepness {
lvl := -1 - deepness + A_Index
oEx := Error("", lvl)
oExPrev := Error("", lvl - 1)
if (getContents) { ; Get the corresponding line from the file
file := FileOpen(oEx.file, "r")
loop {
if (file.AtEOF)
break
line := File.ReadLine()
if (A_Index == oEx.line)
break
}
file.close()
}
if(oEx.What == lvl)
continue
currStack := {}
currStack.file := oEx.File
currStack.line := oEx.Line
; currStack.function := (oExPrev.What = lvl-1 ? "[Autohotkey.exe]" : oExPrev.What)
currStack.function := oExPrev.What
currStack.depth := deepness - A_Index
if (max < currStack.depth) {
max := currStack.depth
}
if (getContents) {
currStack.contents := line
}
stack[lvl+1] := currStack
}
minDepth := 0
for key,value in stack {
stack[key].depth := max - stack[key].depth -1
if (minDepth > key) {
minDepth := key
}
}
stack.delete(minDepth)
return stack
}