Make Lua CommandContext use a ChannelRef (#5184)

This commit is contained in:
Mm2PL
2024-02-18 20:55:00 +01:00
committed by GitHub
parent cd0387b064
commit 4a4f62dc4a
6 changed files with 27 additions and 25 deletions
+19 -20
View File
@@ -297,16 +297,7 @@ int ChannelRef::get_by_name(lua_State *L)
return 1;
}
auto chn = getApp()->twitch->getChannelOrEmpty(name);
if (chn->isEmpty())
{
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);
lua::push(L, chn);
return 1;
}
@@ -330,16 +321,8 @@ int ChannelRef::get_by_twitch_id(lua_State *L)
return 1;
}
auto chn = getApp()->twitch->getChannelOrEmptyByID(id);
if (chn->isEmpty())
{
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);
lua::push(L, chn);
return 1;
}
@@ -390,5 +373,21 @@ StackIdx push(lua_State *L, const api::LuaStreamStatus &status)
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
#endif
@@ -271,5 +271,6 @@ struct LuaStreamStatus {
namespace chatterino::lua {
StackIdx push(lua_State *L, const api::LuaRoomModes &modes);
StackIdx push(lua_State *L, const api::LuaStreamStatus &status);
StackIdx push(lua_State *L, ChannelPtr chn);
} // namespace chatterino::lua
#endif