-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path_.lua
103 lines (87 loc) · 2.37 KB
/
_.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
-- function: all base functions
-- author: [email protected]
function _dump(t, _Key)
for k, v in pairs(t) do
-- if type(v) == "table" then
-- -- print("table")
-- -- dumpt(v)
-- else
-- print(k, v)
-- end
print(k, v)
end
end
function string:split(_Src, sep)
if type(_Src) ~= "string" then
return nil
end
local t = {}
sep = sep or " "
for str in string.gmatch(_Src, "([^"..sep.."]+)") do
assert(type(str) == "string")
table.insert(t, str)
end
return t
end
function memcpy(_Dst, _Src, _Key, _F, _E)
_F = _F or false
_E = _E or false
-- explict key table
if type(_Key) == "table" and next(_Src) ~= nil then
for k, v in ipairs(_Key) do
-- print(k, v, _Dst[v], _Src[k], _Src[v])
if _Src[k] ~= nil and type(_Src[k]) == type(_Dst[v]) then
-- assign dst with src
if type(_Src[k]) == "table" then
_Dst[v] = _Dst[v] == (getmetatable(_Dst))[v] and {} or _Dst[v]
memcpy(_Dst[v], _Src[k], _Dst[v][_key], _F, _E)
else
_Dst[v] = _Src[k]
-- print(_Dst[v])
end
elseif (_Src[v] ~= nil and _F) then
-- fill dst with src
if type(_Src[v]) == "table" then
_Dst[v] = _Dst[v] == (getmetatable(_Dst))[v] and {} or _Dst[v]
-- print(v, _Dst[v])
memcpy(_Dst[v], _Src[v], _Src[v][_key], _F, _E)
else
_Dst[v] = _Src[v]
-- print(_Dst[v])
end
else
if _E then print("assigned error", v, _Dst[v], _Src[k]) end
end
end
return
end
-- array table
if _Src[1] then
if (_Dst[1] and _Dst[#_Src]) then
-- assign dst with src
for k, v in ipairs(_Dst) do
-- print(_Src[k], _Dst[k])
if _Src[k] ~= nil and type(_Src[k]) == type(_Dst[k]) then
if type(_Src[k]) == "table" then
memcpy(_Dst[k], _Src[k], _Dst[k][_key], _F, _E)
else
_Dst[k] = _Src[k]
-- print(k, _Dst[k])
end
else
if _E then print("assigned error", k, _Dst[k], _Src[k]) end
end
end
elseif _F then
-- fill dst with src
for k, v in ipairs(_Src) do
if type(_Src[k]) == "table" then
memcpy(_Dst[k], _Src[k], _Src[k][_key], _F, _E)
else
_Dst[k] = _Src[k]
end
end
end
return
end
end