From 6fb06b71095a9b79c0679bcfc60bf2956ddeb6f3 Mon Sep 17 00:00:00 2001 From: Vanic Date: Wed, 21 Jan 2026 14:13:22 +0300 Subject: [PATCH] Table: add `table.key_value_list()` --- mods/SYSTEM/Table/init.lua | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/mods/SYSTEM/Table/init.lua b/mods/SYSTEM/Table/init.lua index 9411937..61c75bb 100644 --- a/mods/SYSTEM/Table/init.lua +++ b/mods/SYSTEM/Table/init.lua @@ -1,5 +1,5 @@ -local tableCopy, tableKeyOf, pairs, ipairs, next, type, assert, ensureArgType, ensureArgNotNil - = table.copy, table.keyof, pairs, ipairs, next, type, assert, Ensure.argType, Ensure.argNotNil +local tableCopy, tableKeyOf, pairs, ipairs, next, type, assert, ensureArgType, ensureArgNotNil, toString + = table.copy, table.keyof, pairs, ipairs, next, type, assert, Ensure.argType, Ensure.argNotNil, tostring -- While extending Lua's table library, we maintain snake_case naming for standard library -- functions and arguments to match standard library conventions. The code that is not exposed @@ -359,4 +359,28 @@ function table.divide_values(t1, t2, empty_value) return a / b end return operateValues(t1, t2, empty_value or 1, operation) +end + +--- Returns a string of the format `'key1=value1,key2=value2...keyN=valueN'`. +--- @param t table +--- @param separator string? Default: `,` +--- @return string +function table.key_value_list(t, separator) + separator = separator or ',' + + local result = '' + + local size = #t + local k = 1 + for key, value in pairs(t) do + if size < k then + result = result..key..'='..toString(value)..separator + else + result = result..key..'='..toString(value) + end + + k = k + 1 + end + + return result end \ No newline at end of file