From ca49e81e030e6488ad62533e7e14125f6dd7d565 Mon Sep 17 00:00:00 2001 From: CogentRedTester Date: Thu, 13 Oct 2022 21:21:03 +1030 Subject: [PATCH] register the root parser as a parser without adding it to the array This means things like the parser API and a unique ID are now provided to the root parser. I've mostly done this to avoid confusing duplicates from addons that may have named themselves root. --- file-browser.lua | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/file-browser.lua b/file-browser.lua index 4e0f529..d6221df 100644 --- a/file-browser.lua +++ b/file-browser.lua @@ -589,8 +589,8 @@ end -------------------------------------------------------------------------------------------------------- --parser object for the root ---this object is not added to the parsers table so that scripts cannot get access to ---the root table, which is returned directly by parse() +--not inserted to the parser list as it has special behaviour +--it does get get added to parsers under it's ID to prevent confusing duplicates local root_parser = { name = "root", priority = math.huge, @@ -1960,6 +1960,8 @@ local function setup_parser(parser, file) if parser.priority == nil then parser.priority = 0 end if type(parser.priority) ~= "number" then return msg.error("parser", parser:get_id(), "needs a numeric priority") end + --the root parser has special behaviour, so it should not be in the list of parsers + if parser == root_parser then return end table.insert(parsers, parser) end @@ -2050,6 +2052,7 @@ end setup_root() setup_parser(file_parser, "file-browser.lua") +setup_parser(root_parser, 'file-browser.lua') if o.addons then --all of the API functions need to be defined before this point for the addons to be able to access them safely setup_addons()