From 07e6752229401430b63feafa9396e1ca9f65e7f2 Mon Sep 17 00:00:00 2001 From: Matt Wagner Date: Wed, 29 Sep 2021 11:19:27 -0700 Subject: [PATCH] Add a startup event and args utility function --- src/scripts/setup/setup.lua | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/scripts/setup/setup.lua b/src/scripts/setup/setup.lua index e8e4c46..f210d16 100644 --- a/src/scripts/setup/setup.lua +++ b/src/scripts/setup/setup.lua @@ -34,6 +34,8 @@ local function setup() for _, func in ipairs(lotj.setup.gmcpEventHandlerFuncs) do func() end + + raiseEvent("lotjUiLoaded") end local function teardown() @@ -71,3 +73,23 @@ lotj.setup.registerEventHandler("sysProtocolEnabled", function(_, protocol) sendGMCP("Core.Supports.Set", "[\"Ship 1\"]") end end) + +function splitargs(args) + local retval = {} + local spat, epat, buf, quoted = [=[^(['"])]=], [=[(['"])$]=] + for str in args:gmatch("%S+") do + local squoted = str:match(spat) + local equoted = str:match(epat) + local escaped = str:match([=[(\*)['"]$]=]) + if squoted and not quoted and not equoted then + buf, quoted = str, squoted + elseif buf and equoted == quoted and #escaped % 2 == 0 then + str, buf, quoted = buf .. ' ' .. str, nil, nil + elseif buf then + buf = buf .. ' ' .. str + end + if not buf then table.insert(retval, (str:gsub(spat,""):gsub(epat,""))) end + end + if buf then error("Missing matching quote for "..buf) end + return retval +end