Skip to content

read tables example#

Put the configuration onto a key, press it and watch the logs. If you're not familiar with provisioning yet: download a backup from your phone's web-UI and replace an existing key-configuration with this xml. Then simply restore the backup.

overview.xml
<keyConfiguration>
    <lua><code><![CDATA[
        local myTools = {}
        myTools.listByType = function(table, typeStr)
            if table == nil then
                return
            end
            local result = {}
            local i = 1
            for k,v in pairs(table) do
                if type(v) == typeStr then
                    result[i] = {k, v}
                    i = i+1
                end
            end
            return result
        end
        myTools.printLine = function(collection, name, offset, level)
            local linestr = ""..offset..name..": "
            if collection == nil or #collection == 0 then
                return
            end
            for i=1,#collection do
                linestr = linestr..collection[i][1]
                local value = collection[i][2]
                if type(value) == "string" then
                    linestr = linestr.." = "..value
                elseif  type(value) == "number" then
                    linestr = linestr.." = "..tostring(value)
                end
                if i ~= #collection then linestr = linestr..", " end
            end
            debug.log(linestr, level)
        end
        myTools.printTable = function(table, name, offset, recursive, level)
            if table == nil then
                return
            end
            local tableCollection = myTools.listByType(table, "table")
            myTools.printLine(tableCollection, name.."-tables", offset, level)
            myTools.printLine(myTools.listByType(table, "function"), name.."-functions", offset, level)
            myTools.printLine(myTools.listByType(table, "string"), name.."-strings", offset, level)
            myTools.printLine(myTools.listByType(table, "number"), name.."-numbers", offset, level)
            if recursive then
                for i=1,#tableCollection do
                    local subKey = tableCollection[i][1]
                    local subVal = tableCollection[i][2]
                    if subKey ~= "_G" and subKey ~= "loaded" then
                        myTools.printTable(subVal, subKey, offset.."  ", true, "e")
                    end
                end
            end
        end
        -- list all tables and functions in global environment
        myTools.printGlobalEnvironment = function()
            myTools.printTable(_G, "global", "", true, "e")
        end
        function onKeyUp()
            debug.log("----------", "e")
            myTools.printGlobalEnvironment()
            debug.log("----------", "e")
        end
    ]]></code></lua>
</keyConfiguration>