@@ -179,27 +179,27 @@ end
179179-- stored in this field for future use (cache).
180180-- @tparam array opts.keys array of field names. The order must be the same as the
181181-- order of the wildcards in `topic`
182- -- @return [1] `fields` table : the array part will have the values of the wildcards, in
182+ -- @treturn [1] table `fields`: the array part will have the values of the wildcards, in
183183-- the order they appeared. The hash part, will have the field names provided
184184-- in `opts.keys`, with the values of the corresponding wildcard. If a `#`
185185-- wildcard was used, that one will be the last in the table.
186- -- @return [1] `varargs` table: will only be returned if the wildcard topic contained the
187- -- `#` wildcard. The returned table is an array, with all segments that were
188- -- matched by the `#` wildcard.
189- -- @return [2] false+err on error, eg. topic didn't match or pattern was invalid.
186+ -- @treturn [1] `varargs`: The returned table is an array, with all segments that were
187+ -- matched by the `#` wildcard (empty if there was no `#` wildcard).
188+ -- @ treturn [2] boolean `false` if there was no match
189+ -- @return [3] ` false` +err on error, eg. pattern was invalid.
190190-- @usage
191191-- local opts = {
192192-- topic = "homes/+/+/#",
193193-- keys = { "homeid", "roomid", "varargs"},
194194-- }
195- -- local fields, varargs = topic_match("homes/myhome/living/mainlights/brightness", opts)
195+ -- local fields, varargst = topic_match("homes/myhome/living/mainlights/brightness", opts)
196196--
197197-- print(fields[1], fields.homeid) -- "myhome myhome"
198198-- print(fields[2], fields.roomid) -- "living living"
199199-- print(fields[3], fields.varargs) -- "mainlights/brightness mainlights/brightness"
200200--
201- -- print(varargs [1]) -- "mainlights"
202- -- print(varargs [2]) -- "brightness"
201+ -- print(varargst [1]) -- "mainlights"
202+ -- print(varargst [2]) -- "brightness"
203203function mqtt .topic_match (topic , opts )
204204 if type (topic ) ~= " string" then
205205 return false , " expected topic to be a string"
@@ -223,7 +223,7 @@ function mqtt.topic_match(topic, opts)
223223 end
224224 local values = { topic :match (pattern ) }
225225 if values [1 ] == nil then
226- return false , " topic does not match wildcard pattern "
226+ return false
227227 end
228228 local keys = opts .keys
229229 if keys ~= nil then
@@ -240,7 +240,7 @@ function mqtt.topic_match(topic, opts)
240240 end
241241 if not pattern :find (" %(%.[%-%+]%)%$$" ) then -- pattern for "#" as last char
242242 -- we're done
243- return values
243+ return values , {}
244244 end
245245 -- we have a '#' wildcard
246246 local vararg = values [# values ]
0 commit comments