53
53
--- @return type | string
54
54
local function typename (x )
55
55
local mt = getmetatable (x )
56
- if mt and mt .__type then
57
- return mt .__type
56
+ if mt and mt .__name then
57
+ return mt .__name
58
58
else
59
59
return type (x )
60
60
end
@@ -138,7 +138,7 @@ export.generator_metatable = setmetatable({}, {
138
138
end
139
139
140
140
return setmetatable (node , {
141
- __type = " XML.Node" ,
141
+ __name = " XML.Node" ,
142
142
143
143
__tostring = export .node_to_string ,
144
144
@@ -193,6 +193,11 @@ end)
193
193
--- @return XML.Node
194
194
function export .generate_node (ctx ) return ctx (export .generator_metatable ) end
195
195
196
+ --- @generic T
197
+ --- @param func fun ( ... : T ): XML.Node
198
+ --- @return fun ( ... : T ): XML.Node
199
+ function export .declare_generator (func ) return setfenv (func , table ) end
200
+
196
201
--- @param ctx fun ( html : XML.GeneratorTable ): table
197
202
--- @return string
198
203
function export .generate (ctx ) return tostring (export .generate_node (ctx )) end
@@ -203,16 +208,17 @@ function export.generate(ctx) return tostring(export.generate_node(ctx)) end
203
208
function export .html_table (tbl )
204
209
return export .generate_node (function (xml )
205
210
return xml .table {
206
- function ()
211
+ function ()
207
212
local function getval (v )
208
- if type (v ) ~= " table" or ( getmetatable (v ) or {}).__tostring then
213
+ if typename (v ) ~= " table" and ( typename ( v ) ~= " XML.Node " and ( getmetatable (v ) or {}).__tostring ~= nil ) then
209
214
return tostring (v )
210
215
end
216
+
211
217
return export .html_table (v )
212
218
end
213
219
214
220
for i , v in ipairs (tbl ) do
215
- coroutine.yield (
221
+ coroutine.yield (
216
222
xml .tr {
217
223
xml .td (tostring (i )),
218
224
xml .td (getval (v )),
@@ -223,7 +229,7 @@ function export.html_table(tbl)
223
229
end
224
230
225
231
for k , v in pairs (tbl ) do
226
- coroutine.yield (
232
+ coroutine.yield (
227
233
xml .tr {
228
234
xml .td (tostring (k )),
229
235
xml .td (getval (v )),
0 commit comments