From 2a25193941a2fe57bc93530785c5fbc0a04606bc Mon Sep 17 00:00:00 2001 From: boatbomber Date: Tue, 27 Sep 2022 01:59:48 -0400 Subject: [PATCH] Add CreateApiContext and more caller info --- plugin/src/App/init.lua | 2 +- plugin/src/HeadlessAPI.lua | 64 ++++++++++++++++++++++++++++++++++---- 2 files changed, 59 insertions(+), 7 deletions(-) diff --git a/plugin/src/App/init.lua b/plugin/src/App/init.lua index 9d7fae3f..42ce97d5 100644 --- a/plugin/src/App/init.lua +++ b/plugin/src/App/init.lua @@ -49,7 +49,7 @@ function App:init() self.host, self.setHost = Roact.createBinding(priorHost or "") self.port, self.setPort = Roact.createBinding(priorPort or "") - self.headlessAPI, self.readOnlyHeadlessAPI = HeadlessAPI.new(self, Config, Settings) + self.headlessAPI, self.readOnlyHeadlessAPI = HeadlessAPI.new(self) -- selene: allow(global_usage) _G.Rojo = self.readOnlyHeadlessAPI -- Expose headless to other plugins and command bar diff --git a/plugin/src/HeadlessAPI.lua b/plugin/src/HeadlessAPI.lua index 5c0c0ec0..caa2d232 100644 --- a/plugin/src/HeadlessAPI.lua +++ b/plugin/src/HeadlessAPI.lua @@ -1,13 +1,20 @@ +local Parent = script:FindFirstAncestor("Rojo") +local Plugin = Parent.Plugin + +local Config = require(Plugin.Config) +local Settings = require(Plugin.Settings) +local ApiContext = require(Plugin.ApiContext) + local API = {} -function API.new(app, config, settings) +function API.new(app) local Rojo = {} Rojo.Connected = if app.serveSession then app.serveSession:getStatus() == "Connected" else false Rojo.Address = nil Rojo.ProjectName = nil - Rojo.Version = table.clone(config.version) - Rojo.ProtocolVersion = config.protocolVersion + Rojo.Version = table.clone(Config.version) + Rojo.ProtocolVersion = Config.protocolVersion Rojo._notifRateLimit = {} @@ -15,6 +22,28 @@ function API.new(app, config, settings) print("Rojo:Test called by", Rojo:_getCaller(), "with args", ...) end + function Rojo:_getCallerFull() + local traceback = string.split(debug.traceback(), "\n") + local topLevel = traceback[#traceback - 1] + + local debugPlugin = string.match(topLevel, "^(PluginDebugService%.user_.-)%.") + if debugPlugin then + return debugPlugin + end + + local localPlugin = string.match(topLevel, "^(user_.-)%.") + if localPlugin then + return localPlugin + end + + local cloudPlugin = string.match(topLevel, "(cloud_%d-%..-)%.") + if cloudPlugin then + return cloudPlugin + end + + return "RobloxStudio.CommandBar" + end + function Rojo:_getCaller() local traceback = string.split(debug.traceback(), "\n") local topLevel = traceback[#traceback - 1] @@ -34,7 +63,26 @@ function API.new(app, config, settings) return cloudPlugin end - return "Command Bar" + return "CommandBar" + end + + function Rojo:_getCallerType() + local traceback = string.split(debug.traceback(), "\n") + local topLevel = traceback[#traceback - 1] + + if string.find(topLevel, "^PluginDebugService%.user_") then + return "Debug" + end + + if string.find(topLevel, "^user_") then + return "Local" + end + + if string.find(topLevel, "cloud_%d+%.") then + return "Cloud" + end + + return "CommandBar" end function Rojo:ConnectAsync(host: string?, port: number?) @@ -46,11 +94,11 @@ function API.new(app, config, settings) end function Rojo:GetSetting(setting: string): any - return settings:get(setting) + return Settings:get(setting) end function Rojo:SetSetting(setting: string, value: any) - return settings:set(setting, value) + return Settings:set(setting, value) end function Rojo:Notify(msg: string, timeout: number?) @@ -75,6 +123,10 @@ function API.new(app, config, settings) return app:getHostAndPort() end + function Rojo:CreateApiContext(baseUrl: string) + return ApiContext.new(baseUrl) + end + local ReadOnly = setmetatable({}, { __index = function(_, key) if string.find(key, "^_") then