-- Simple execution timer (prints elapsed time) function debug_utils.time_function(func, ...) local start = os.clock() local results = {func(...)} local elapsed = os.clock() - start print(string.format("Execution time: %.4f seconds", elapsed)) return table.unpack(results) end
-- Deep copy a table (handles nested tables) function table_utils.deep_copy(orig) local copy if type(orig) == "table" then copy = {} for k, v in pairs(orig) do copy[table_utils.deep_copy(k)] = table_utils.deep_copy(v) end setmetatable(copy, table_utils.deep_copy(getmetatable(orig))) else copy = orig end return copy end script luar
-- Check if string matches a pattern (regex-lite) function validate.matches_pattern(str, pattern) return string.match(str, pattern) ~= nil end -- Simple execution timer (prints elapsed time) function
-- -------------------------------------------- -- 4. DATA VALIDATION -- -------------------------------------------- local validate = {} pattern) return string.match(str
-- Check if table is non-empty function validate.non_empty_table(tbl) return type(tbl) == "table" and next(tbl) ~= nil end
-- Write string to file (overwrites) function file_utils.write_file(filename, content) local f, err = io.open(filename, "w") if not f then return false, err end f:write(content) f:close() return true end