API:SHOW STACK TRACE

Aus WARWiki

Keine Beschreibung verfügbar.

Nutzung

API:SHOW STACK TRACE()


Diese Funktion übernimmt keine Argumente.


Diese Funktion gibt keine Werte zurück.


Source Code

function SHOW_STACK_TRACE( startLevel )

    if( debug == nil ) then
        return
    end
    
    if( debug.getinfo == nil ) then
        DEBUG( L" SHOW_STACK_TRACE - Lua Debug Library is not loaded. ")
        return
    end
    
    local traceLines = {}
    local numLines = 0
    
    -- Determine the stack trace lines
    local level = 2 -- Skip Level 1 because we dont' want to display the SHOW_STACK_TRACE() funcion call
    if( startLevel ~= nil ) then
        level = startLevel
    end
    while true do
        local info = debug.getinfo(level, "Sln")
        if not info then break end
        
        local text = L""
                
        -- Exposed C Functions
        if info.what == "C" then  
            local name = info.name;
            if( name == nil ) then
                name =  "NAME_NOT_FOUND"
            end     
            text = L""..StringToWString(name)..L": C-Function"
        
        -- Lua Function
        elseif  info.what == "Lua" then
            local name = info.name;
            if( name == nil ) then
                name =  "NAME_NOT_FOUND"
            end
            local strText = string.format("%s(...) - %s:%d", name, info.short_src, info.currentline)
            text = StringToWString( strText )
            
        -- Main lua chunk ( On Loading the file )
        else 
            local name = info.name;
            if( name == nil ) then
                name =  "NAME_NOT_FOUND"
            end
            local strText = string.format("Loading File %s:%d", name, info.short_src, info.currentline)
            text = StringToWString( strText )
        
        end
        
        numLines = numLines + 1
        traceLines[numLines] = text
                
        level = level + 1
    end
        
    -- Print the formatted stack trace to debug.
    
    DEBUG( L" ------- ")
    for index = 1, numLines do
        local line = numLines - index
        DEBUG(L""..line..L" - "..traceLines[index] )
    end
    DEBUG( L" ------- ")
end


Persönliche Werkzeuge
Anzeige

Sponsoren