-- Check if table is non-empty function validate.non_empty_table(tbl) return type(tbl) == "table" and next(tbl) ~= nil end
-- -------------------------------------------- -- 5. DEBUGGING / TIMING -- -------------------------------------------- local debug_utils = {}
local my_table = {a=1, b={c=2}} local copy = table_utils.deep_copy(my_table) script luar
-- -------------------------------------------- -- 2. TABLE UTILITIES -- -------------------------------------------- local table_utils = {}
-- -------------------------------------------- -- 4. DATA VALIDATION -- -------------------------------------------- local validate = {} -- Check if table is non-empty function validate
-- Check if string matches a pattern (regex-lite) function validate.matches_pattern(str, pattern) return string.match(str, pattern) ~= nil end
debug_utils.log("Script started") debug_utils.time_function(string_utils.trim, " test ") --]] pattern) return string.match(str
file_utils.write_file("test.txt", "Lua rocks!") print(file_utils.read_file("test.txt"))
-- Read entire file as string (returns nil + error on failure) function file_utils.read_file(filename) local f, err = io.open(filename, "r") if not f then return nil, err end local content = f:read("*all") f:close() return content end
-- Split string by delimiter (returns table) function string_utils.split(str, delimiter) local result = {} local pattern = string.format("([^%s]+)", delimiter) for match in str:gmatch(pattern) do table.insert(result, match) end return result 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