PageRenderTime 20ms CodeModel.GetById 14ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 1ms

/lib/Debug.ahk

http://github.com/Skiouros/Macro
AutoHotKey | 44 lines | 39 code | 5 blank | 0 comment | 6 complexity | 253a28b4da9aee10e9eebe03c1d4fedb MD5 | raw file
 1debug(msg, delimiter = False) {
 2    global debugfile, s_name
 3    if (!s_name)
 4        s_name := A_ScriptName
 5    static stdout, ft := True ; First time.
 6    
 7    args := arg()
 8    for index, arg in args
 9        parameters .= (A_Index > 1 ? arg . " " : "")
10        
11    file := Exception("", -1).File
12    SplitPath, file, fileName
13    msg := fileName . ":" . Exception("", -1).Line . " - " . msg
14    
15    if (ft)
16        stdout := FileOpen(DllCall("GetStdHandle", "int", -11, "ptr"), "h `n")
17
18    t := delimiter = 1 ? msg := "* ----------------------------------------`n" . msg
19    t := delimiter = 2 ? msg := msg . "* ----------------------------------------`n"
20    t := delimiter = 3 ? (msg := "* ----------------------------------------`n" . msg
21                                       .   "`n* ----------------------------------------")
22    t := delimiter = 4 ? (msg := "* " . s_name . " Debug OFF`n* " . s_name . "[Stop]`n"
23                                       . "* ----------------------------------------`n")
24    if (!debugfile) {
25        ft ? (msg := "* ----------------------------------------`n"
26                                       .   "* " . s_name . " Debug ON`n* " . s_name . "[Start]`n"
27                                       .   "* Parameters: " . parameters "`n" . msg, ft := 0)
28        OutputDebug % msg
29        stdout.Write(msg . "`n")
30        stdout.Read(0) ; Flush the write buffer.
31    }                           
32    else if (debugfile) {
33        ft ? (msg := "* ----------------------------------------`n"
34                      .   "* " . s_name . " Debug ON`n* " . s_name . "[Start]`n"
35                      .   "* Parameters: " . parameters . "`n" . msg, ft := 0)         
36        FileAppend, %msg%`n, %debugfile%
37    }
38}
39
40arg() {
41    Loop, % (arg := {0: %false%}) [0]
42        arg[A_Index] := %A_Index%
43    return arg
44}