mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
fix: use opaque values for enums
This commit is contained in:
parent
90211cca55
commit
4ff9b163ab
|
@ -5,20 +5,20 @@
|
||||||
-- Add the folder this file is in to "Lua.workspace.library".
|
-- Add the folder this file is in to "Lua.workspace.library".
|
||||||
|
|
||||||
c2 = {}
|
c2 = {}
|
||||||
---@alias c2.LogLevel.Debug "c2.LogLevel.Debug"
|
---@enum c2.LogLevel
|
||||||
---@alias c2.LogLevel.Info "c2.LogLevel.Info"
|
c2.LogLevel = {
|
||||||
---@alias c2.LogLevel.Warning "c2.LogLevel.Warning"
|
Debug = {}, ---@type c2.LogLevel.Debug
|
||||||
---@alias c2.LogLevel.Critical "c2.LogLevel.Critical"
|
Info = {}, ---@type c2.LogLevel.Info
|
||||||
---@alias c2.LogLevel c2.LogLevel.Debug|c2.LogLevel.Info|c2.LogLevel.Warning|c2.LogLevel.Critical
|
Warning = {}, ---@type c2.LogLevel.Warning
|
||||||
---@type { Debug: c2.LogLevel.Debug, Info: c2.LogLevel.Info, Warning: c2.LogLevel.Warning, Critical: c2.LogLevel.Critical }
|
Critical = {}, ---@type c2.LogLevel.Critical
|
||||||
c2.LogLevel = {}
|
}
|
||||||
|
|
||||||
-- Begin src/controllers/plugins/api/EventType.hpp
|
-- Begin src/controllers/plugins/api/EventType.hpp
|
||||||
|
|
||||||
---@alias c2.EventType.CompletionRequested "c2.EventType.CompletionRequested"
|
---@enum c2.EventType
|
||||||
---@alias c2.EventType c2.EventType.CompletionRequested
|
c2.EventType = {
|
||||||
---@type { CompletionRequested: c2.EventType.CompletionRequested }
|
CompletionRequested = {}, ---@type c2.EventType.CompletionRequested
|
||||||
c2.EventType = {}
|
}
|
||||||
|
|
||||||
-- End src/controllers/plugins/api/EventType.hpp
|
-- End src/controllers/plugins/api/EventType.hpp
|
||||||
|
|
||||||
|
@ -38,19 +38,19 @@ c2.EventType = {}
|
||||||
|
|
||||||
-- Begin src/common/Channel.hpp
|
-- Begin src/common/Channel.hpp
|
||||||
|
|
||||||
---@alias c2.ChannelType.None "c2.ChannelType.None"
|
---@enum c2.ChannelType
|
||||||
---@alias c2.ChannelType.Direct "c2.ChannelType.Direct"
|
c2.ChannelType = {
|
||||||
---@alias c2.ChannelType.Twitch "c2.ChannelType.Twitch"
|
None = {}, ---@type c2.ChannelType.None
|
||||||
---@alias c2.ChannelType.TwitchWhispers "c2.ChannelType.TwitchWhispers"
|
Direct = {}, ---@type c2.ChannelType.Direct
|
||||||
---@alias c2.ChannelType.TwitchWatching "c2.ChannelType.TwitchWatching"
|
Twitch = {}, ---@type c2.ChannelType.Twitch
|
||||||
---@alias c2.ChannelType.TwitchMentions "c2.ChannelType.TwitchMentions"
|
TwitchWhispers = {}, ---@type c2.ChannelType.TwitchWhispers
|
||||||
---@alias c2.ChannelType.TwitchLive "c2.ChannelType.TwitchLive"
|
TwitchWatching = {}, ---@type c2.ChannelType.TwitchWatching
|
||||||
---@alias c2.ChannelType.TwitchAutomod "c2.ChannelType.TwitchAutomod"
|
TwitchMentions = {}, ---@type c2.ChannelType.TwitchMentions
|
||||||
---@alias c2.ChannelType.TwitchEnd "c2.ChannelType.TwitchEnd"
|
TwitchLive = {}, ---@type c2.ChannelType.TwitchLive
|
||||||
---@alias c2.ChannelType.Misc "c2.ChannelType.Misc"
|
TwitchAutomod = {}, ---@type c2.ChannelType.TwitchAutomod
|
||||||
---@alias c2.ChannelType c2.ChannelType.None|c2.ChannelType.Direct|c2.ChannelType.Twitch|c2.ChannelType.TwitchWhispers|c2.ChannelType.TwitchWatching|c2.ChannelType.TwitchMentions|c2.ChannelType.TwitchLive|c2.ChannelType.TwitchAutomod|c2.ChannelType.TwitchEnd|c2.ChannelType.Misc
|
TwitchEnd = {}, ---@type c2.ChannelType.TwitchEnd
|
||||||
---@type { None: c2.ChannelType.None, Direct: c2.ChannelType.Direct, Twitch: c2.ChannelType.Twitch, TwitchWhispers: c2.ChannelType.TwitchWhispers, TwitchWatching: c2.ChannelType.TwitchWatching, TwitchMentions: c2.ChannelType.TwitchMentions, TwitchLive: c2.ChannelType.TwitchLive, TwitchAutomod: c2.ChannelType.TwitchAutomod, TwitchEnd: c2.ChannelType.TwitchEnd, Misc: c2.ChannelType.Misc }
|
Misc = {}, ---@type c2.ChannelType.Misc
|
||||||
c2.ChannelType = {}
|
}
|
||||||
|
|
||||||
-- End src/common/Channel.hpp
|
-- End src/common/Channel.hpp
|
||||||
|
|
||||||
|
@ -250,14 +250,14 @@ function HTTPRequest.create(method, url) end
|
||||||
|
|
||||||
-- Begin src/common/network/NetworkCommon.hpp
|
-- Begin src/common/network/NetworkCommon.hpp
|
||||||
|
|
||||||
---@alias HTTPMethod.Get "HTTPMethod.Get"
|
---@enum HTTPMethod
|
||||||
---@alias HTTPMethod.Post "HTTPMethod.Post"
|
HTTPMethod = {
|
||||||
---@alias HTTPMethod.Put "HTTPMethod.Put"
|
Get = {}, ---@type HTTPMethod.Get
|
||||||
---@alias HTTPMethod.Delete "HTTPMethod.Delete"
|
Post = {}, ---@type HTTPMethod.Post
|
||||||
---@alias HTTPMethod.Patch "HTTPMethod.Patch"
|
Put = {}, ---@type HTTPMethod.Put
|
||||||
---@alias HTTPMethod HTTPMethod.Get|HTTPMethod.Post|HTTPMethod.Put|HTTPMethod.Delete|HTTPMethod.Patch
|
Delete = {}, ---@type HTTPMethod.Delete
|
||||||
---@type { Get: HTTPMethod.Get, Post: HTTPMethod.Post, Put: HTTPMethod.Put, Delete: HTTPMethod.Delete, Patch: HTTPMethod.Patch }
|
Patch = {}, ---@type HTTPMethod.Patch
|
||||||
HTTPMethod = {}
|
}
|
||||||
|
|
||||||
-- End src/common/network/NetworkCommon.hpp
|
-- End src/common/network/NetworkCommon.hpp
|
||||||
|
|
||||||
|
|
|
@ -242,25 +242,19 @@ def read_file(path: Path, out: TextIOWrapper):
|
||||||
)
|
)
|
||||||
name = header[0].split(" ", 1)[1]
|
name = header[0].split(" ", 1)[1]
|
||||||
printmsg(path, reader.line_no(), f"enum {name}")
|
printmsg(path, reader.line_no(), f"enum {name}")
|
||||||
variants = reader.read_enum_variants()
|
|
||||||
|
|
||||||
vtypes = []
|
|
||||||
for variant in variants:
|
|
||||||
vtype = f'{name}.{variant}'
|
|
||||||
vtypes.append(vtype)
|
|
||||||
out.write(f'---@alias {vtype} "{vtype}"\n')
|
|
||||||
|
|
||||||
out.write(f"---@alias {name} {'|'.join(vtypes)}\n")
|
|
||||||
if header_comment:
|
if header_comment:
|
||||||
out.write(f"--- {header_comment}\n")
|
out.write(f"--- {header_comment}\n")
|
||||||
out.write("---@type { ")
|
out.write(f"---@enum {name}\n")
|
||||||
|
out.write(f"{name} = {{\n")
|
||||||
out.write(
|
out.write(
|
||||||
", ".join(
|
"\n".join(
|
||||||
[f"{variant}: {typ}" for variant, typ in zip(variants,vtypes)]
|
[
|
||||||
|
f" {variant} = {{}}, ---@type {name}.{variant}"
|
||||||
|
for variant in reader.read_enum_variants()
|
||||||
|
]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
out.write(" }\n")
|
out.write("\n}\n\n")
|
||||||
out.write(f"{name} = {{}}\n\n")
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# class
|
# class
|
||||||
|
|
Loading…
Reference in a new issue