mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-22 13:21:38 +00:00
Add CreateApiContext and more caller info
This commit is contained in:
parent
f3de0c35ef
commit
2a25193941
2 changed files with 59 additions and 7 deletions
|
|
@ -49,7 +49,7 @@ function App:init()
|
||||||
self.host, self.setHost = Roact.createBinding(priorHost or "")
|
self.host, self.setHost = Roact.createBinding(priorHost or "")
|
||||||
self.port, self.setPort = Roact.createBinding(priorPort 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)
|
-- selene: allow(global_usage)
|
||||||
_G.Rojo = self.readOnlyHeadlessAPI -- Expose headless to other plugins and command bar
|
_G.Rojo = self.readOnlyHeadlessAPI -- Expose headless to other plugins and command bar
|
||||||
|
|
|
||||||
|
|
@ -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 = {}
|
local API = {}
|
||||||
|
|
||||||
function API.new(app, config, settings)
|
function API.new(app)
|
||||||
local Rojo = {}
|
local Rojo = {}
|
||||||
|
|
||||||
Rojo.Connected = if app.serveSession then app.serveSession:getStatus() == "Connected" else false
|
Rojo.Connected = if app.serveSession then app.serveSession:getStatus() == "Connected" else false
|
||||||
Rojo.Address = nil
|
Rojo.Address = nil
|
||||||
Rojo.ProjectName = nil
|
Rojo.ProjectName = nil
|
||||||
Rojo.Version = table.clone(config.version)
|
Rojo.Version = table.clone(Config.version)
|
||||||
Rojo.ProtocolVersion = config.protocolVersion
|
Rojo.ProtocolVersion = Config.protocolVersion
|
||||||
|
|
||||||
Rojo._notifRateLimit = {}
|
Rojo._notifRateLimit = {}
|
||||||
|
|
||||||
|
|
@ -15,6 +22,28 @@ function API.new(app, config, settings)
|
||||||
print("Rojo:Test called by", Rojo:_getCaller(), "with args", ...)
|
print("Rojo:Test called by", Rojo:_getCaller(), "with args", ...)
|
||||||
end
|
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()
|
function Rojo:_getCaller()
|
||||||
local traceback = string.split(debug.traceback(), "\n")
|
local traceback = string.split(debug.traceback(), "\n")
|
||||||
local topLevel = traceback[#traceback - 1]
|
local topLevel = traceback[#traceback - 1]
|
||||||
|
|
@ -37,6 +66,25 @@ function API.new(app, config, settings)
|
||||||
return "CommandBar"
|
return "CommandBar"
|
||||||
end
|
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?)
|
function Rojo:ConnectAsync(host: string?, port: number?)
|
||||||
app:startSession(host, port)
|
app:startSession(host, port)
|
||||||
end
|
end
|
||||||
|
|
@ -46,11 +94,11 @@ function API.new(app, config, settings)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Rojo:GetSetting(setting: string): any
|
function Rojo:GetSetting(setting: string): any
|
||||||
return settings:get(setting)
|
return Settings:get(setting)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Rojo:SetSetting(setting: string, value: any)
|
function Rojo:SetSetting(setting: string, value: any)
|
||||||
return settings:set(setting, value)
|
return Settings:set(setting, value)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Rojo:Notify(msg: string, timeout: number?)
|
function Rojo:Notify(msg: string, timeout: number?)
|
||||||
|
|
@ -75,6 +123,10 @@ function API.new(app, config, settings)
|
||||||
return app:getHostAndPort()
|
return app:getHostAndPort()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Rojo:CreateApiContext(baseUrl: string)
|
||||||
|
return ApiContext.new(baseUrl)
|
||||||
|
end
|
||||||
|
|
||||||
local ReadOnly = setmetatable({}, {
|
local ReadOnly = setmetatable({}, {
|
||||||
__index = function(_, key)
|
__index = function(_, key)
|
||||||
if string.find(key, "^_") then
|
if string.find(key, "^_") then
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue