Script Luar Official

-- Log with timestamp function debug_utils.log(message, level) level = level or "INFO" local timestamp = os.date("%Y-%m-%d %H:%M:%S") print(string.format("[%s] [%s] %s", timestamp, level, message)) end

-- Check if a value exists in a table (linear search) function table_utils.contains(tbl, value) for _, v in pairs(tbl) do if v == value then return true end end return false end

-- Check if value is a number within range function validate.is_in_range(val, min, max) return type(val) == "number" and val >= min and val <= max end

-- -------------------------------------------- -- 2. TABLE UTILITIES -- -------------------------------------------- local table_utils = {} script luar

-- 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

-- -------------------------------------------- -- 3. FILE I/O (safe read/write) -- -------------------------------------------- local file_utils = {}

-- ============================================ -- UTILITY SCRIPT FOR LUA (5.1+ compatible) -- Author: Generated Assistant -- Description: Reusable functions for string, table, file, and debug tasks -- ============================================ -- Log with timestamp function debug_utils

-- Check if string ends with a suffix function string_utils.ends_with(str, suffix) return #suffix == 0 or str:sub(-#suffix) == suffix end

-- -------------------------------------------- -- 1. STRING UTILITIES -- -------------------------------------------- local string_utils = {}

-- Print table recursively (for debugging) function table_utils.print_table(tbl, indent) indent = indent or 0 for k, v in pairs(tbl) do local formatting = string.rep(" ", indent) .. tostring(k) .. ": " if type(v) == "table" then print(formatting) table_utils.print_table(v, indent + 1) else print(formatting .. tostring(v)) end end end tostring(v)) end end end debug_utils

debug_utils.log("Script started") debug_utils.time_function(string_utils.trim, " test ") --]]

-- Merge table t2 into t1 (overwrites t1 keys) function table_utils.merge(t1, t2) for k, v in pairs(t2) do t1[k] = v end return t1 end

script luar