Add a new completion API for experimental plugins feature. (#5000)

Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
Mm2PL
2023-12-10 14:41:05 +01:00
committed by GitHub
parent e4258160cd
commit fd4cac2c2c
13 changed files with 448 additions and 16 deletions
+32
View File
@@ -94,6 +94,37 @@ int c2_register_command(lua_State *L)
return 1;
}
int c2_register_callback(lua_State *L)
{
auto *pl = getApp()->plugins->getPluginByStatePtr(L);
if (pl == nullptr)
{
luaL_error(L, "internal error: no plugin");
return 0;
}
EventType evtType{};
if (!lua::peek(L, &evtType, 1))
{
luaL_error(L, "cannot get event name (1st arg of register_callback, "
"expected a string)");
return 0;
}
if (lua_isnoneornil(L, 2))
{
luaL_error(L, "missing argument for register_callback: function "
"\"pointer\"");
return 0;
}
auto callbackSavedName = QString("c2cb-%1").arg(
magic_enum::enum_name<EventType>(evtType).data());
lua_setfield(L, LUA_REGISTRYINDEX, callbackSavedName.toStdString().c_str());
lua_pop(L, 2);
return 0;
}
int c2_send_msg(lua_State *L)
{
QString text;
@@ -167,6 +198,7 @@ int c2_system_msg(lua_State *L)
lua::push(L, false);
return 1;
}
const auto chn = getApp()->twitch->getChannelOrEmpty(channel);
if (chn->isEmpty())
{