Jump to content
Sign in to follow this  

SciTE - DebugToMsgBox/~Console also with array variables

Recommended Posts


At the moment you can debug with DebugToMsgBox/DebugToConsole only simple variables like $variable but not some like $a[ubound($a) -1][$j] or other complex array variables.

I've made a LUA script that detects simple variables and complex array variables up to 4D-arrays. AutoIt allows dirty syntax with any desired spaces between closing and following opening squared brackets. This cases will respected.

To use this script:

- open your file ..AutoIt3SciTELUAAutoItTools.lua in editor

- copy the function GetVarFromCursor() above the function DebugMsgBoxAdd()

- make following changes in DebugMsgBoxAdd() and DebugConsoleWriteAdd()

function AutoItTools:DebugMsgBoxAdd()
--~  local word = self:GetWord2()
    local word = GetVarFromCursor()

function AutoItTools:DebugConsoleWriteAdd()
--~  local word = self:GetWord2()
    local word = GetVarFromCursor()

Here the function GetVarFromCursor():

-- GetVarFromCursor()
-- Get variable from cursor position (somewhere inside variable, left or right touching).
-- Detection of variables also if they build as an array construct (up to 4 dimensions).
-- i.e. (pipe as cursor position): "$a [ Ubound($a) -1 ] [ |$i ] [ $j ]" gets the whole exception: "$a [ Ubound($a) -1 ] [ $i ] [ $j ]"
-- The bad syntax in AutoIt ( any desired spaces between closing and following opening squared bracket ) will also detect.
-- Variables with following point and method/property are ignored because its not to guess if method/property returns a value.
-- by BugFix
function GetVarFromCursor()
    local iCaret = editor.CurrentPos
    local iTmp = iCaret
    local sSel = string.char(editor.CharAt[iCaret])
    if (string.byte(sSel) == 13) or (sSel == ' ') or (sSel == ',') then
        iCaret = iCaret -1
    local sLeft = string.char(editor.CharAt[iTmp-1])
    local iLine = editor:LineFromPosition(iCaret)
    local iLine1stPos = editor:PositionFromLine(iLine)
    local iDiffPos = iCaret - iLine1stPos +1
    local sLine = editor:GetLine(iLine)
    local tPatternArray = {'%$[%w_]+%s*%b[]%s*%b[]%s*%b[]%s*%b[]','%$[%w_]+%s*%b[]%s*%b[]%s*%b[]','%$[%w_]+%s*%b[]%s*%b[]','%$[%w_]+%s*%b[]'}
    local sPatternNormal = '%$[%w_]+%s*[^[]'
    function SearchVar(_sLine, _sPattern, _iCursor)
        local tVars = {}
        local iMatchStart iMatchEnd = 0
        while true do
            iMatchStart, iMatchEnd = string.find(_sLine, _sPattern, iMatchEnd +1)
            if iMatchStart == nil then break end
            table.insert(tVars, {iMatchStart, iMatchEnd})
        if table.getn(tVars) > 0 then
            for i = 1, table.getn(tVars) do
                if ( _iCursor >= tVars[i][1] ) and ( _iCursor <= tVars[i][2] ) then
                    return string.sub(_sLine, tVars[i][1], tVars[i][2])
        return nil
    local sVarUnderCursor
    for i = 1, 4 do
        sVarUnderCursor = SearchVar(sLine, tPatternArray[i], iDiffPos)
        if sVarUnderCursor ~= nil then return sVarUnderCursor end
    if sVarUnderCursor == nil then
        local fLeftVar = false fRightVar = false
        if string.find(sLeft, '[%w_$]') ~= nil then
            fLeftVar = true
            if sSel == '$' then fRightVar = true end
        if not fLeftVar and not fRightVar then return '' end
        sVarUnderCursor = SearchVar(sLine, sPatternNormal, iDiffPos)
        if sVarUnderCursor == nil then return '' end
    if string.find(sVarUnderCursor, '%.$') then return '' end
    sVarUnderCursor = string.sub(sVarUnderCursor, string.find(sVarUnderCursor, '%$[%w_]+'))
    return sVarUnderCursor
end -- GetVarFromCursor()

Edit: Oops - has detect a mistake and fixed it. If someone find also an mistake - please let me know to fix.

Edit2: Sometimes, i think to complicated... :)

So now i've made it easier. And i hope, all bugs are fixed.

Edited by BugFix

Best Regards BugFix  

Share this post

Link to post
Share on other sites

Brilliant! I will give it a try.

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post

Link to post
Share on other sites

Thanks for your reply.

I'm still a beginner with LUA. It's sure possible to make this script more professional. I still try my best.

Best Regards BugFix  

Share this post

Link to post
Share on other sites


i fixed it to my teaste :-) as.


elseif option == 1 then

ConsoleWrite('@@(' & @ScriptName   & '-' & @ScriptLineNumber  & ') : $VARIABLE = ' & $VARIABLE & @crlf)

Thanks for sharing

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.