Script — Luar

-- Append string to file function file_utils.append_file(filename, content) local f, err = io.open(filename, "a") if not f then return false, err end f:write(content) f:close() return true end

-- -------------------------------------------- -- 4. DATA VALIDATION -- -------------------------------------------- local validate = {}

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

-- -------------------------------------------- -- 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 -- Append string to file function file_utils

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

-- 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 tostring(k)

-- 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 string starts with a prefix function string_utils.starts_with(str, prefix) return str:sub(1, #prefix) == prefix end

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