very WIP, doesn't detect duplicates properly.. everything else seems fine?

This commit is contained in:
2026-09-16 16:03:14 -06:00
parent 977920df61
commit 470901d9b9
5 changed files with 201 additions and 42 deletions
+75
View File
@@ -0,0 +1,75 @@
local stored_messages = {}
local display_levels = {}
local enable_logging = true
local message_limit = math.huge
-- USAGE:
-- -- set arbitrary log levels to be printed immediately
-- log{ info = true, warning = true, ducksauce = true, }
-- -- send anything (except nil) to a log level
-- log("bacom", true, "text", 5, function() end, {})
-- -- print all messages saved at a particular log level
-- log("error")
-- -- toggle ALL logging on and off with a boolean
-- log(false) -- this deletes all stored messages
-- -- set a maximum number of stored messages per log level
-- log(50) -- warning: reaching large limits makes logging expensive
-- -- do anything to the stored messages (this example deletes them all)
-- log(function(messages) return {} end)
return function(options, ...)
local options_type = type(options)
if (options_type == "string") and enable_logging then
if not stored_messages[options] then stored_messages[options] = {} end
local message_table = stored_messages[options]
-- turn log message into text
local tab = {...}
for i = 1, #tab do
tab[i] = tostring(tab[i])
end
local current_message = table.concat(tab, "\t")
if #current_message == 0 then
-- print all stored_messages of specified level
for i = 1, #message_table do
print(message_table[i])
end
else
-- store message (and print if in display_levels)
message_table[#message_table + 1] = current_message
if #message_table > message_limit then table.remove(message_table, 1) end
if display_levels[options] then print(current_message) end
end
-- set display_levels
elseif options_type == "table" then
for k,v in pairs(options) do
display_levels[k] = v
end
elseif options_type == "number" then
message_limit = options
for k,v in pairs(stored_messages) do
while #v > message_limit do
table.remove(v, 1)
end
end
-- turn all logging off and delete stored messages; or turn it on
elseif options_type == "boolean" then
if options then
enable_logging = true
else
enable_logging = false
stored_messages = {}
end
-- arbitrary access :D
elseif options_type == "function" then
local result = options(stored_messages)
if type(result) == "table" then stored_messages = result end
end
end
+1
View File
@@ -40,6 +40,7 @@ timing.mark = function(label)
if #timing > 1 then
timing.display(#timing)
end
print("", "", label)
end
timing.estimate = function(current_position, total_operations)
+13 -3
View File
@@ -221,7 +221,7 @@ utility.list = function(path, func)
local run = function(fn)
for line in output:gmatch("[^\r\n]+") do -- thanks to https://stackoverflow.com/a/32847589
if not (line == "." or line == "..") then
if not ((line == ".") or (line == "..")) then
fn(line)
end
end
@@ -239,7 +239,8 @@ utility.ls = function(...)
return utility.list(...)
end
utility.tree = function(path, options, fn)
local tree
tree = function(path, options, fn)
if type(options) == "function" then
fn = options
options = {}
@@ -258,7 +259,16 @@ utility.tree = function(path, options, fn)
fn(path_name)
else
utility.tree(path .. utility.path_separator .. path_name, options, fn)
tree(path .. utility.path_separator .. path_name, options, fn)
end
end)
end
utility.tree = function(path, options, fn)
tree(path, options, function(path_name)
if path_name:find(path) == 1 then
fn(path_name)
else
fn(path .. utility.path_separator .. path_name)
end
end)
end