Global $gSciTECmd GUIRegisterMsg(74, "MY_WM_COPYDATA") ; $WM_COPYDATA = 74 ; -------------------------------------------------------------------------------------------------- ; extrahiert für alle gefundenen Variablen: ; Var_1 @ Var_1_Name & optional Indexwert | Var_3 @ Var_2_Name ... etc. ; Der Ergebnisstring wird in der Weiterverarbeitung noch in ".." eingeschlossen. ;~ ConsoleWrite(_GetVarsFromLine("$xyz = $abc['xy']") & @CRLF) ; OK: $abc['xy']@$abc[" & 'xy' & "]|$xyz@$xyz ;~ ConsoleWrite(_GetVarsFromLine("$n = $a[$a[0][0]][0]") & @CRLF) ; OK: $a[$a[0][0]][0]@$a[" & $a[0][0] & "][0]|$n@$n ConsoleWrite(_GetVarsFromLine("$m[""x""] = 'c'") & @CRLF) ; FAIL: sParam ist i.O.: ("$m[\"x\"] = 'c'") ; [string "do function MatchVarsFromLine(_l) tpatt = ..."]:1: ')' expected near 'x' ; Ausführen direkt in Lua: print(MatchVarsFromLine("$m[\"x\"] = 'c'")) --> OK: $m["x"]@$m[" & 'x' & "] ; -------------------------------------------------------------------------------------------------- Func _GetVarsFromLine($_line) ;~ -- matches: ($abc)[*][*][*] ($abc)[*][*] ($abc)[*] $a[*][*][*] ;~ -- $a[*][*] $a[*] $abc.Bla $abc local $sFunc = _ "function MatchVarsFromLine(_l)" & _ " tpatt = {'(%b()%b[]%b[]%b[])', '(%b()%b[]%b[])', '(%b()%b[])', '(%$[_%w]+%b[]%b[]%b[])'," & _ " '(%$[_%w]+%b[]%b[])', '(%$[_%w]+%b[])', '(%$[_%w]+%.%w+)', '(%$[_%w]+)'}" & _ " local sgl, dbl, sVars, sVarsStr, n, s0, s1 = string.char(39), string.char(34), '', '', 0" & _ " for i=1, #tpatt do" & _ " while true do" & _ " local s, e, v = _l:find(tpatt[i])" & _ " if s == nil then break end" & _ " n = n +1" & _ " sVarsStr = v:gsub('%b[]'," & _ " function(_b) _b = _b:gsub('^%[', ''):gsub('^%s+', '')" & _ " _b = _b:gsub('%]$', ''):gsub('%s+$', '')" & _ " if _b:find('^%d+$') then return '['.._b..']' end" & _ " if (_b:find('^'..sgl) or _b:find('^'..dbl)) then" & _ " _b = ('%s%s%s'):format(sgl, _b:sub(2, _b:len()-1), sgl) end" & _ " return ('[%s & %s & %s]'):format(dbl, _b, dbl) end)" & _ " sVars = sVars..v..'@'..sVarsStr..'|'" & _ " s0, s1 = _l:sub(1, s-1), _l:sub(e +1)" & _ " _l = s0..s1" & _ " end" & _ " end" & _ " return sVars:gsub('|$', '') " & _ "end" Return _ScI_DostringGet($sFunc, $_line) EndFunc ;=============================================================================== ; Function Name....: _ScI_DostringGet ; Description......: Eine Luafunktion mit/ohne Parameter aufrufen UND ein Ergebnis erhalten ; : Maximal 10 Parameter können übergeben werden. ; Parameter(s).....: $_sLuaFunc - String mit der Lua-Funktion ; : $p1 - [optional] Parameter1 für die Funktion ; : ... bis ; : $p10 - [optional] Parameter10 für die Funktion ; Return Value(s)..: Rückgabewert der Lua-Funktion ; Author(s)........: BugFix ; Note.............: Achtung! Der Code darf !keine! Kommentare enthalten! ;------------------------------------------------------------------------------- ; Bsp.: ; ohne Parameter: ; Local $sFunc = "function LineFromCursor() return editor:LineFromPosition(editor.CurrentPos)+1 end" ; ConsoleWrite(_ScI_DostringGet($sFunc) & @CRLF) ; ; mit Parameter: ; Local $sFunc = "function LineEnd(iLine) return editor.LineEndPosition[iLine] end" ; ConsoleWrite(_ScI_DostringGet($sFunc, 130) & @CRLF) ;=============================================================================== Func _ScI_DostringGet($_sLuaFunc, $p1=Null, $p2=Null, $p3=Null, $p4=Null, $p5=Null, $p6=Null, $p7=Null, $p8=Null, $p9=Null, $p10=Null) Local $aParamCall[] = [$p1,$p2,$p3,$p4,$p5,$p6,$p7,$p8,$p9,$p10] ; extract function name Local $sFunc = (StringRegExp($_sLuaFunc, 'function (\w+)\(', 1))[0], $sParam = '()' Local $sPart If $p1 <> Null Then ; extract parameters $sParam = (StringRegExp($_sLuaFunc, 'function \w+\(([^)]+)\)', 1))[0] Local $aParam = StringSplit($sParam, ',') ; rebuild sParam with given values $sParam = '' For $i = 1 To $aParam[0] $sPart = StringReplace($aParamCall[$i-1], '"', '\"') $sParam &= '"' & $sPart & '"' & ',' Next $sParam = '(' & StringTrimRight($sParam,1) & ')' EndIf ConsoleWrite('-> sParam: ' & $sParam & @CRLF) SendSciTE_Command("extender:dostring do props['extender.result'] = '' end") SendSciTE_Command("extender:dostring do " & $_sLuaFunc & " props['extender.result'] = " & $sFunc & $sParam & " end") SendSciTE_Command('askproperty:extender.result') Return StringTrimLeft($gSciTECmd,StringInStr($gSciTECmd, ':', 1, 4)) EndFunc Func _GetHwndDirectorExtension() Local $hActive = WinGetHandle('[ACTIVE]') Local $PIDActive = WinGetProcess($hActive) Local $aExtension = WinList("DirectorExtension") Local $PIDExt For $i = 1 To $aExtension[0][0] $PIDExt = WinGetProcess($aExtension[$i][1]) If $PIDExt = $PIDActive Then Return $aExtension[$i][1] Next EndFunc Func SendSciTE_Command($_sCmd, $Wait_For_Return_Info=0) Local $WM_COPYDATA = 74 Local $Scite_hwnd = _GetHwndDirectorExtension() ; Get SciTE Director Handle Local $My_Hwnd = GUICreate("AutoIt3-SciTE interface") ; Create GUI to receive SciTE info Local $My_Dec_Hwnd = Dec(StringTrimLeft($My_Hwnd, 2)) ; Convert my Gui Handle to decimal $_sCmd = ":" & $My_Dec_Hwnd & ":" & $_sCmd ; Add dec my gui handle to commandline to tell SciTE where to send the return info Local $CmdStruct = DllStructCreate('Char[' & StringLen($_sCmd) + 1 & ']') DllStructSetData($CmdStruct, 1, $_sCmd) Local $COPYDATA = DllStructCreate('Ptr;DWord;Ptr') DllStructSetData($COPYDATA, 1, 1) DllStructSetData($COPYDATA, 2, StringLen($_sCmd) + 1) DllStructSetData($COPYDATA, 3, DllStructGetPtr($CmdStruct)) $gSciTECmd = '' DllCall('User32.dll', 'None', 'SendMessage', 'HWnd', $Scite_hwnd, _ 'Int', $WM_COPYDATA, 'HWnd', $My_Hwnd, _ 'Ptr', DllStructGetPtr($COPYDATA)) GUIDelete($My_Hwnd) If $Wait_For_Return_Info Then Local $n = 0 While $gSciTECmd = '' Or $n < 10 Sleep(20) $n += 1 WEnd EndIf Return $gSciTECmd EndFunc ;==>SendSciTE_Command Func MY_WM_COPYDATA($hWnd, $msg, $wParam, $lParam) Local $COPYDATA = DllStructCreate('Ptr;DWord;Ptr', $lParam) Local $gSciTECmdLen = DllStructGetData($COPYDATA, 2) Local $CmdStruct = DllStructCreate('Char[' & $gSciTECmdLen+1 & ']',DllStructGetData($COPYDATA, 3)) $gSciTECmd = StringLeft(DllStructGetData($CmdStruct, 1), $gSciTECmdLen) EndFunc ;==>MY_WM_COPYDATA