From baa3655ca33fdf55cccdc1b40648e261527d1d4e Mon Sep 17 00:00:00 2001 From: yaw-man Date: Wed, 18 Aug 2021 01:12:29 -0300 Subject: [PATCH] Fix sample.lua iteration sample.lua did not iterate over the output of :select() correctly. It had been written assuming the keys were attributes, when in fact the keys are numbers, and the values are attributes. This caused an error when running the sample script. --- doc/sample.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/sample.lua b/doc/sample.lua index 24a2471..a67a79d 100644 --- a/doc/sample.lua +++ b/doc/sample.lua @@ -25,7 +25,7 @@ p(root) print("\nchapters") local sel, chapters = root("ol.chapters > li"), {} -for e in pairs(sel) do +for _, e in ipairs(sel) do table.insert(chapters, e:getcontent()) end -- print @@ -35,7 +35,7 @@ end print("\ncontacts") local sel, contacts = root("ul.contacts span[class]"), {} -for e in pairs(sel) do +for _, e in ipairs(sel) do local id = e.parent.parent.id -- li > a > span contacts[id] = contacts[id] or {} contacts[id][e.classes[1]] = e:getcontent() @@ -50,7 +50,7 @@ end print("\nmicrodata") local sel, scopes = root("[itemprop]"), {} -for prop in pairs(sel) do +for _, prop in ipairs(sel) do if prop.attributes["itemscope"] then goto nextprop end local descendantscopes, scope = {}, prop while true do