2025-01-19 14:16:42 +01:00
|
|
|
|
|
|
|
local may_print_errors = false
|
|
|
|
local errors_buffer = {}
|
|
|
|
|
|
|
|
local logger = {
|
|
|
|
print = function( str )
|
2025-01-19 14:19:49 +01:00
|
|
|
print( str or "" )
|
2025-01-19 14:16:42 +01:00
|
|
|
end,
|
|
|
|
printerr = function( str)
|
2025-01-19 14:19:49 +01:00
|
|
|
str = str or ""
|
2025-01-19 14:16:42 +01:00
|
|
|
if str:sub(#str,#str) ~= "\n" then
|
|
|
|
str = str .. "\n"
|
|
|
|
end
|
|
|
|
|
|
|
|
if not may_print_errors then
|
|
|
|
table.insert(errors_buffer, str)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
io.stderr:write(str)
|
|
|
|
end,
|
|
|
|
enable_printing_errors = function()
|
|
|
|
may_print_errors = true
|
|
|
|
|
|
|
|
for _, err in ipairs(errors_buffer) do
|
|
|
|
io.stderr:write(err)
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return logger
|