-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtx.lua
executable file
·36 lines (31 loc) · 898 Bytes
/
tx.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env lua
-- Copyright © 2025 Mark Summerfield. All rights reserved.
local tx = {}
local function clone(orig, copies_) -- call with ONE table only!
copies_ = copies_ or {}
local orig_type = type(orig)
local copy
if orig_type == "table" then
if copies_[orig] then
copy = copies_[orig]
else
copy = {}
copies_[orig] = copy
for orig_key, orig_value in next, orig, nil do
copy[clone(orig_key, copies_)] = clone(orig_value, copies_)
end
setmetatable(copy, clone(getmetatable(orig), copies_))
end
else -- number, string, boolean, etc
copy = orig
end
return copy
end
function tx.clone(tbl) return clone(tbl) end
function tx.merge(tbl1, tbl2)
for key, value in pairs(tbl2) do
tbl1[key] = value
end
return tbl1
end
return tx