Code Explorer (code snippet)

Description

Quick mini plugin which will search for all the functions defined on a selected code source and list the line numbers. Handy when combined with the new goto line number option in V5.0.5 of Family Historian.

Requires: None

Code

--[[
@Title: Code Explorer
@Author: Jane Taubman
@Version: 0.1
@LastUpdated: June 2010 
@Description: Quick display of functions in code with their line numbers.
]]
-- require "iup"
function main()
    strAppData = fhGetContextInfo('CI_APP_DATA_FOLDER')
    strLuaDir = strAppData..'\\Plugins\\*.fh_lua'
    f, err = iup.GetFile(strLuaDir)
    if err == 0 then
        local script = searchCode(f)
        iup.GetText('Functions in '..f, table.concat(script,'\n'))
    end
end
 
 
-- Load lines in table from file 
function searchCode(strFileName)
    local    t = {}
    local    l = 0
    for line in io.lines(strFileName) do
       l = l + 1
       sfind = line:find('function[%s]')
       if sfind then
          cfind = line:find('%-%-')
          if not(cfind and cfind < sfind) then
             table.insert(t,l..'\t '..string.gsub(line:gsub('function','   '),'\t',' '))
          end
       end
    end
    return t
end 
-------------------------------------------- End of functions
 
main()