From 01c38b022d0b4a2fd56667dd274579343c3ef770 Mon Sep 17 00:00:00 2001 From: Wouter Scherphof Date: Tue, 19 Mar 2013 22:32:24 +0100 Subject: [PATCH] __call = select --- ElementNode.lua | 5 ++++- test.lua | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/ElementNode.lua b/ElementNode.lua index 5d92d4b..9b23b36 100644 --- a/ElementNode.lua +++ b/ElementNode.lua @@ -89,7 +89,7 @@ function ElementNode:close(closestart, closeend) end end -function ElementNode:select(s) +local function select(self, s) if not s or type(s) ~= "string" then return {} end local subjects = Set:new({self}) local resultset @@ -116,4 +116,7 @@ function ElementNode:select(s) return resultset:tolist() end +function ElementNode:select(s) return select(self, s) end +ElementNode.mt.__call = select + return ElementNode \ No newline at end of file diff --git a/test.lua b/test.lua index ec2366e..7774288 100644 --- a/test.lua +++ b/test.lua @@ -51,7 +51,7 @@ select("ul > *") select("body [class]") select("body > [class]") -local sel, chapters = root:select("ol.chapters > li"), {} +local sel, chapters = root("ol.chapters > li"), {} for i,v in ipairs(sel) do table.insert(chapters, v:getcontent()) end @@ -60,10 +60,10 @@ for i,v in ipairs(chapters) do print(i, v) end -local sel, contacts = root:select("ul.contacts > li"), {} +local sel, contacts = root("ul.contacts > li"), {} for i,v in ipairs(sel) do local c = {} - for fi,fv in ipairs(v:select("span[class]")) do + for fi,fv in ipairs(v("span[class]")) do c[fv.classes[1]] = fv:getcontent() end contacts[v.id] = c