Tag: Debug
Mostrando todas as entradas e posts com a tag "Debug"
Entradas do Diário
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()