mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
Make Lua CommandContext use a ChannelRef (#5184)
This commit is contained in:
parent
cd0387b064
commit
4a4f62dc4a
|
@ -30,7 +30,7 @@
|
||||||
- Minor: Added icons for newer versions of macOS. (#5148)
|
- Minor: Added icons for newer versions of macOS. (#5148)
|
||||||
- Minor: Added the `--incognito/--no-incognito` options to the `/openurl` command, allowing you to override the "Open links in incognito/private mode" setting. (#5149)
|
- Minor: Added the `--incognito/--no-incognito` options to the `/openurl` command, allowing you to override the "Open links in incognito/private mode" setting. (#5149)
|
||||||
- Minor: Added support for the `{input.text}` placeholder in the **Split** -> **Run a command** hotkey. (#5130)
|
- Minor: Added support for the `{input.text}` placeholder in the **Split** -> **Run a command** hotkey. (#5130)
|
||||||
- Minor: Add a new Channel API for experimental plugins feature. (#5141)
|
- Minor: Add a new Channel API for experimental plugins feature. (#5141, #5184)
|
||||||
- Minor: Added the ability to change the top-most status of a window regardless of the _Always on top_ setting (right click the notebook). (#5135)
|
- Minor: Added the ability to change the top-most status of a window regardless of the _Always on top_ setting (right click the notebook). (#5135)
|
||||||
- Minor: Live streams that are marked as reruns now mark a tab as yellow instead of red. (#5176)
|
- Minor: Live streams that are marked as reruns now mark a tab as yellow instead of red. (#5176)
|
||||||
- Minor: Updated to Emoji v15.1. Google emojis are now used as the fallback instead of Twitter emojis. (#5182)
|
- Minor: Updated to Emoji v15.1. Google emojis are now used as the fallback instead of Twitter emojis. (#5182)
|
||||||
|
|
|
@ -24,7 +24,7 @@ c2.LogLevel = {}
|
||||||
c2.EventType = {}
|
c2.EventType = {}
|
||||||
---@class CommandContext
|
---@class CommandContext
|
||||||
---@field words string[] The words typed when executing the command. For example `/foo bar baz` will result in `{"/foo", "bar", "baz"}`.
|
---@field words string[] The words typed when executing the command. For example `/foo bar baz` will result in `{"/foo", "bar", "baz"}`.
|
||||||
---@field channel_name string The name of the channel the command was executed in.
|
---@field channel Channel The channel the command was executed in.
|
||||||
|
|
||||||
---@class CompletionList
|
---@class CompletionList
|
||||||
---@field values string[] The completions
|
---@field values string[] The completions
|
||||||
|
|
|
@ -35,7 +35,7 @@ enum class EventType {
|
||||||
/**
|
/**
|
||||||
* @lua@class CommandContext
|
* @lua@class CommandContext
|
||||||
* @lua@field words string[] The words typed when executing the command. For example `/foo bar baz` will result in `{"/foo", "bar", "baz"}`.
|
* @lua@field words string[] The words typed when executing the command. For example `/foo bar baz` will result in `{"/foo", "bar", "baz"}`.
|
||||||
* @lua@field channel_name string The name of the channel the command was executed in.
|
* @lua@field channel Channel The channel the command was executed in.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
# include "common/Channel.hpp"
|
# include "common/Channel.hpp"
|
||||||
# include "common/QLogging.hpp"
|
# include "common/QLogging.hpp"
|
||||||
# include "controllers/commands/CommandContext.hpp"
|
# include "controllers/commands/CommandContext.hpp"
|
||||||
|
# include "controllers/plugins/api/ChannelRef.hpp"
|
||||||
# include "controllers/plugins/LuaAPI.hpp"
|
# include "controllers/plugins/LuaAPI.hpp"
|
||||||
|
|
||||||
# include <lauxlib.h>
|
# include <lauxlib.h>
|
||||||
|
@ -120,8 +121,9 @@ StackIdx push(lua_State *L, const CommandContext &ctx)
|
||||||
|
|
||||||
push(L, ctx.words);
|
push(L, ctx.words);
|
||||||
lua_setfield(L, outIdx, "words");
|
lua_setfield(L, outIdx, "words");
|
||||||
push(L, ctx.channel->getName());
|
|
||||||
lua_setfield(L, outIdx, "channel_name");
|
push(L, ctx.channel);
|
||||||
|
lua_setfield(L, outIdx, "channel");
|
||||||
|
|
||||||
return outIdx;
|
return outIdx;
|
||||||
}
|
}
|
||||||
|
|
|
@ -297,16 +297,7 @@ int ChannelRef::get_by_name(lua_State *L)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
auto chn = getApp()->twitch->getChannelOrEmpty(name);
|
auto chn = getApp()->twitch->getChannelOrEmpty(name);
|
||||||
if (chn->isEmpty())
|
lua::push(L, chn);
|
||||||
{
|
|
||||||
lua_pushnil(L);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
// pushes onto stack
|
|
||||||
WeakPtrUserData<UserData::Type::Channel, Channel>::create(
|
|
||||||
L, chn->weak_from_this());
|
|
||||||
luaL_getmetatable(L, "c2.Channel");
|
|
||||||
lua_setmetatable(L, -2);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -330,16 +321,8 @@ int ChannelRef::get_by_twitch_id(lua_State *L)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
auto chn = getApp()->twitch->getChannelOrEmptyByID(id);
|
auto chn = getApp()->twitch->getChannelOrEmptyByID(id);
|
||||||
if (chn->isEmpty())
|
|
||||||
{
|
lua::push(L, chn);
|
||||||
lua_pushnil(L);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
// pushes onto stack
|
|
||||||
WeakPtrUserData<UserData::Type::Channel, Channel>::create(
|
|
||||||
L, chn->weak_from_this());
|
|
||||||
luaL_getmetatable(L, "c2.Channel");
|
|
||||||
lua_setmetatable(L, -2);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -390,5 +373,21 @@ StackIdx push(lua_State *L, const api::LuaStreamStatus &status)
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StackIdx push(lua_State *L, ChannelPtr chn)
|
||||||
|
{
|
||||||
|
using namespace chatterino::lua::api;
|
||||||
|
|
||||||
|
if (chn->isEmpty())
|
||||||
|
{
|
||||||
|
lua_pushnil(L);
|
||||||
|
return lua_gettop(L);
|
||||||
|
}
|
||||||
|
WeakPtrUserData<UserData::Type::Channel, Channel>::create(
|
||||||
|
L, chn->weak_from_this());
|
||||||
|
luaL_getmetatable(L, "c2.Channel");
|
||||||
|
lua_setmetatable(L, -2);
|
||||||
|
return lua_gettop(L);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace chatterino::lua
|
} // namespace chatterino::lua
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -271,5 +271,6 @@ struct LuaStreamStatus {
|
||||||
namespace chatterino::lua {
|
namespace chatterino::lua {
|
||||||
StackIdx push(lua_State *L, const api::LuaRoomModes &modes);
|
StackIdx push(lua_State *L, const api::LuaRoomModes &modes);
|
||||||
StackIdx push(lua_State *L, const api::LuaStreamStatus &status);
|
StackIdx push(lua_State *L, const api::LuaStreamStatus &status);
|
||||||
|
StackIdx push(lua_State *L, ChannelPtr chn);
|
||||||
} // namespace chatterino::lua
|
} // namespace chatterino::lua
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue