Tag: Debug

Mostrando todas as entradas e posts com a tag "Debug"

Entradas do Diário

The most effective debugging tool

The most effective debugging tool

The most effective debugging tool is still careful thought, coupled with judiciously placed print statements.

  • Brian W. Kernighan, in the paper Unix for Beginners (1979)

The most effective debugging tool is still careful thought, coupled with judiciously placed print statements.


Listar variáveis

Listar variáveis

Tecnica para fazer “debug de pobre” em Lua, listando variáveis globais e locais.

-- List all global variables
for name, value in pairs(_G) do
    local repr = tostring(value)
    print(string.format("%s = %s", name, repr))
end
-- List all local variables in the current function
-- This will only work if the code is run in a function context
local function list_locals()
    local i = 1
    while true do
        local var_name, var_value = debug.getlocal(2, i)
        if not var_name then break end
        print(string.format("%s = %s", var_name, tostring(var_value)))
        i = i + 1
    end
end

-- Example
local function demo()
    local a = 10
    local b = "hello"
    list_locals()  -- This will list local variables a and b
end

demo()

Tecnica para fazer "debug de pobre" em Lua, listando variáveis globais e locais.