-- TIME_STAMP 2021-06-08 13:41:48 v 0.1 -- coding:utf-8 --[[ - Skript in "SciTEStartup.lua" starten - zugehöriges AutoItSkript "DebugFuncCallSC.au3" als Include ]] DebugFC = {} ----------------------------------------------------------------------------------------------------------------------------------------------------- DebugFC.IsComment = function(self, _pos) local tComment = {1,2} if tComment[editor.StyleAt[_pos]] == nil then return false else return true end end DebugFC.InSense = function(self, _s) _s = _s:gsub("%a", function(_c) return string.format("[%s%s]", _c:upper(),_c:lower()) end) return _s end DebugFC.FileExists = function(self, _path) local fh = io.open(_path) if fh ~= nil then fh:close() return true else return false end end ----------------------------------------------------------------------------------------------------------------------------------------------------- -- OK DebugFC.IncludeExistsInFolder = function(self, _incl) -- OpenPath (Pfade für Includes) abfragen local sOpen, tOpen = props['openpath.$(au3)'], {} for w in sOpen:gmatch("([^;]+)") do table.insert(tOpen, w) end -- Prüfen ob Include ohne Voranstellen von Ordner existiert (Include im Skriptdir oder kompletter Pfad im Include) if self:FileExists(_incl) then -- Ordnertrennzeichen im Pfad? ( "\" oder "/" ) local p = _incl:find('\\[^\\]+$') if not p then p = _incl:find('/[^/]+$') end if p then return _incl:sub(1, p-1), _incl:sub(p+1) -- Pfad, Dateiname.ext else return props['FileDir'], _incl end end -- in den gefundenen OpenPath nach Include suchen if #tOpen > 0 then for i=1, #tOpen do if self:FileExists(tOpen[i]..'\\'.._incl) then return tOpen[i], _incl end end end return nil, nil end -- OK DebugFC.DeclaredFuncsInEditor = function(self) local pattFunc = '('..self:InSense('func')..'%s+[%w_]+%s-%b())' local pattFuncName = '('..self:InSense('func')..'%s+)([%w_]+)(%s-%b())' local tFunc, e, n, sFunc, a = {}, 1, 0, '' local s = editor:GetText() while e do a, e, fname = s:find(pattFunc, e) if a and not self:IsComment(a) then _, _, _, fname = fname:find(pattFuncName) table.insert(tFunc, fname) n = n +1 end end if n == 0 then return nil else return tFunc end end -- OK DebugFC.DeclaredFuncsInFile = function(self, _file) local pattFunc = '('..self:InSense('func')..'%s+[%w_]+%s-%b())' local pattFuncName = '('..self:InSense('func')..'%s+)([%w_]+)(%s-%b())' local tFunc, e, n, sFunc, s, a = {}, 1, 0, '' local fh = io.open(_file) if fh then s = fh:read('*a') fh:close() end if s ~= nil then while e do a, e, fname = s:find(pattFunc, e) if a then _, _, _, fname = fname:find(pattFuncName) table.insert(tFunc, fname) n = n +1 end end end if n == 0 then return nil else return tFunc end end -- OK DebugFC.GetIncludes = function(self) local text = editor:GetText() local tIncl, incl = {}, '' for _, incl in text:gmatch("[\n]?(#"..self:InSense('include').."%s-<([%w%s_.:\\/]+)>)") do table.insert(tIncl,incl) end -- #include --> abc.au3 for _, _, incl in text:gmatch("[\n]?(#"..self:InSense('include').."%s-([\"'])([%w%s_.:\\/]+)%2)") do table.insert(tIncl,incl) end -- #include 'abc.au3' or #include "abc.au3" --> abc.au3 return tIncl end -- OK DebugFC.WhereDeclared = function(self, _f) -- im Skript deklarierte Funktionen - Rückgabe aktueller Skriptname local tCurrent = self:DeclaredFuncsInEditor() if tCurrent ~= nil then for i=1, #tCurrent do if tCurrent[i]:upper() == _f:upper() then return props['FileNameExt'] end end end -- in Includes deklarierte Funktionen - Rückgabe Includename local tIncluded, tFuncs = self:GetIncludes() if #tIncluded > 0 then for i=1, #tIncluded do local folder, file = self:IncludeExistsInFolder(tIncluded[i]) if folder ~= nil then -- Funktionsdeklarationen aus Includedateien ermitteln tFuncs = self:DeclaredFuncsInFile(folder..'\\'..file) if tFuncs ~= nil then for j=1, #tFuncs do if tFuncs[j]:upper() == _f:upper() then return tIncluded[i] end end end end end end -- nicht deklariert: nativ return 'Native' end -- In 1.te oder 2.te (ermöglicht vorheriges Abfangen von @error) Zeile unter Funktionsaufruf muss gesetzt werden: _DebugFC_Set(ScriptLineNumber) -- Wenn in der 1.ten Zeile vor "_DebugFC_Set" ein "@error" gefunden wird, verwendet das Skript die 2.te Zeile davor DebugFC.FuncFromLine = function(self, _line) -- _line ist @ScriptLineNumber, steht 1 Zeile unter dem gefragten Funktionsaufruf, ist 1-basiert -> für 0-basiert: -2 _line = _line -2 local line = editor:GetLine(_line) if line:find(self:InSense('@error')) then _line = _line -1 line = editor:GetLine(_line) _line = _line +1 end local sfunc = line:match('([%w_]+)(%s-%b())') local swrite, fh = '' if sfunc ~= nil then swrite = swrite..self:WhereDeclared(sfunc)..'\r\n'..sfunc..'()'..'\r\n'.._line..'\r\n' fh = io.open(os.getenv('TEMP')..'\\DebugFuncCall.result','w+') -- "C:\Users\BugFix\AppData\Local\Temp" fh:write(swrite) fh:close() end end -- Gibt die zuletzt gespeicherten Werte aus über: _DebugFC_Get() --[[ Bsp. $result = _EineFunktion('bla', $a) ; Aufruf in Zeile #25, Datei aus UserInclude "_MyUDF.au3" $iErr = @error _DebugFC_Set(ScriptLineNumber) $tDebug = _DebugFC_Get() ConsoleWrite($tDebug.File & '|' & $tDebug.Func & '(' & $tDebug.Line & ')' & @TAB & ($iErr ? 'FEHLER' : 'OK') & @CRLF) ;================================================================================================================== #cs OUTPUT _MyUDF.au3 | _EineFunktion() (25) OK #ce ]]