-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Debug.ttslua
executable file
·58 lines (45 loc) · 1.87 KB
/
Debug.ttslua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
require('ge_tts.License')
local ChatCommands = require('ge_tts.ChatCommands')
---@class tts__Debug
local Debug = {}
local globalTable = (--[[---@type table<string, any>]] _G)
--- Iterates through loaded (require'd) modules and exposes all modules matching modulePattern as global variables. The
--- global variable for a module will be the module's name with variablePrefix substituted for modulePattern and periods
--- replaced by double underscores.
---@overload fun(): void
---@param modulePattern? nil | string @Default '^ge_tts%.'
---@param variablePrefix? nil | string @Default ''
function Debug.createGlobals(modulePattern, variablePrefix)
Wait.frames(function()
modulePattern = modulePattern or '^ge_tts%.'
variablePrefix = variablePrefix or ''
-- First directory is the "scripts", which we don't want.
for packageName, package in pairs(_LOADED) do
if packageName:find(--[[---@not nil]] modulePattern) then
local identifier = packageName:gsub(--[[---@not nil]] modulePattern, --[[---@not nil]] variablePrefix):gsub('[/%.]', '__')
globalTable[identifier] = package
end
end
print('Initialized Debug globals with "' .. variablePrefix .. '" prefix.')
end, 1)
end
---@param value string
---@param player tts__Player
local onChatCommand = function(value, player)
if player.host then
---@type string[]
local components = {}
for component in --[[---@type fun(): string]] string.gmatch(value, "([^ ]+)") do
table.insert(components, component)
end
if #components == 0 then
return
end
local subcommand = components[1]
if subcommand == 'globals' then
Debug.createGlobals(components[2], components[3])
end
end
end
ChatCommands.addCommand('debug', onChatCommand)
return Debug