API:DUMP TABLE

Aus WARWiki

Keine Beschreibung verfügbar.

Nutzung

API:DUMP TABLE()


Diese Funktion übernimmt keine Argumente.


Diese Funktion gibt keine Werte zurück.


Source Code

-- Outputs the table contents to a function that takes a string as a parameter.
--   calls this function once per line.
function DUMP_TABLE_TO( t, printFunction, indent, tableHistory )

    if ( printFunction == nil)
    then
        DEBUG(L" Error in: DUMP_TABLE_TO(table, printFunctions), function for output is nil")
        return
    end
    
    if (t == nil) 
    then 
        -- Don't ERROR out on this, it stops your script execution...not so desirable for debugging.
        printFunction (L" Error in: DUMP_TABLE_TO(table), table param is nil")
        return;
    end

    if (type (t) ~= "table") 
    then
        -- Don't ERROR out on this, it stops your script execution...not so desirable for debugging.
        printFunction (L" Error in: DUMP_TABLE_TO(table), table param is not a table, type="..towstring(type(t)))
        return;
    end

    tableHistory = tableHistory or {}

    if (indent == nil or (type (indent) ~= "wstring")) 
    then
        indent = L"";
    end
    
    for k, v in pairs (t) 
    do
        local valueType = towstring (type (v))
        local keyName   = towstring (tostring (k))
        local value     = towstring (tostring (v))

        printFunction (indent..L"("..valueType..L") "..keyName..L" = "..value)

        if type (v) == "table" 
        then
            if (tableHistory[v] == nil)
            then
                tableHistory[v] = true
                DUMP_TABLE_TO (v, printFunction, indent..L"   ", tableHistory)                
            else
                printFunction (indent..L"Preventing cycle on table ["..value..L"]")
            end
        end
    end

    printFunction (indent..L"end")

end


Persönliche Werkzeuge
Anzeige

Sponsoren