Skip to content

Commit

Permalink
register the root parser as a parser without adding it to the array
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
CogentRedTester committed Oct 13, 2022
1 parent 500e42e commit ca49e81
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions file-browser.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit ca49e81

Please sign in to comment.