You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-- all versions ", ..." can be removed to save tokens if you never use tostr(number,true)
76
76
local_tostr=tostr
77
-
-- this version respects __tostring and prints array values in order without keys
78
-
localfunctiontostr(n, ...)
77
+
78
+
-- this version respects __tostring
79
+
localfunctiontostr_tostring(n, ...)
80
+
iftype(n) =="table" then
81
+
localm=getmetatable(n)
82
+
ifmandm.__tostringthen
83
+
returnm.__tostring(n, ...)
84
+
end
85
+
end
86
+
return_tostr(n, ...)
87
+
end
88
+
89
+
-- this version prints tables recursively with all keys in unpredictable order
90
+
localfunctiontostr_tables(t, ...)
91
+
iftype(n) =="table" then
92
+
locals="{"
93
+
fork, vinpairs(t) do
94
+
s=s.. (s=="{" and'' or",") ..tostr(k, ...) .."=" ..tostr(v, ...) -- mishandles reserved words that require ["key"]
95
+
end
96
+
returns
97
+
end
98
+
return_tostr(t, ...)
99
+
end
100
+
101
+
-- this version prints tables recursively with array values in order without keys then remaining table keys in unpredictable order
102
+
localfunctiontostr_arrays_tables(n, ...)
103
+
iftype(n) =="table" then
104
+
localf, s= {}, "{" -- "[table:{" would avoid ambiguity with literal strings that look like tables
105
+
fori=1, #ndo
106
+
s=s.. (i==1and'' or",") ..tostr(n[i])
107
+
f[i] =true
108
+
end
109
+
fork, vinpairs(n) do
110
+
ifnotf[k] then
111
+
s=s.. (s=="{" and'' or",") ..tostr(k) .."=" ..tostr(v) -- mishandles reserved words that require ["key"]
112
+
end
113
+
end
114
+
returns.."}" -- .. "]" to match less ambiguous alternative above
115
+
end
116
+
return_tostr(n, ...)
117
+
end
118
+
119
+
-- this version respects __tostring and prints tables recursively with array values in order without keys then remaining table keys in unpredictable order
120
+
localfunctiontostr_tostring_arrays_tables(n, ...)
79
121
iftype(n) =="table" then
80
122
localm=getmetatable(n)
81
123
ifmandm.__tostringthen
82
124
returnm.__tostring(n, ...)
83
125
else
84
-
localf, s= {}, "{" -- "[table:{" avoids ambiguity with literal strings that look like tables
126
+
localf, s= {}, "{" -- "[table:{" would avoid ambiguity with literal strings that look like tables
85
127
fori=1, #ndo
86
128
s=s.. (i==1and'' or",") ..tostr(n[i])
87
129
f[i] =true
@@ -96,17 +138,6 @@ local function tostr(n, ...)
96
138
end
97
139
return_tostr(n, ...)
98
140
end
99
-
-- this version prints all keys, in unpredictable order
100
-
localfunctiontostr(t, ...)
101
-
iftype(n) =="table" then
102
-
locals="{"
103
-
fork, vinpairs(t) do
104
-
s=s.. (s=="{" and'' or",") ..tostr(k, ...) .."=" ..tostr(v, ...) -- mishandles reserved words that require ["key"]
0 commit comments