mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Add VERY basic lua scripting capabilities
This commit is contained in:
parent
bfa899c45e
commit
d1c9dfc865
12 changed files with 123 additions and 2 deletions
3
.gitmodules
vendored
3
.gitmodules
vendored
|
@ -38,3 +38,6 @@
|
|||
[submodule "lib/miniaudio"]
|
||||
path = lib/miniaudio
|
||||
url = https://github.com/mackron/miniaudio.git
|
||||
[submodule "lib/lua"]
|
||||
path = lib/lua
|
||||
url = https://github.com/lua/lua
|
||||
|
|
|
@ -148,6 +148,30 @@ else()
|
|||
add_subdirectory("${CMAKE_SOURCE_DIR}/lib/settings" EXCLUDE_FROM_ALL)
|
||||
endif()
|
||||
|
||||
#find_package(Lua REQUIRED)
|
||||
add_custom_target(
|
||||
Lua ALL
|
||||
COMMAND make
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/lib/lua
|
||||
)
|
||||
#include(ExternalProject)
|
||||
#
|
||||
#ExternalProject_Add(lua
|
||||
# URL "https://www.lua.org/ftp/lua-5.4.4.tar.gz"
|
||||
# CONFIGURE_COMMAND ""
|
||||
# BUILD_COMMAND make generic
|
||||
# BUILD_ALWAYS true
|
||||
# BUILD_IN_SOURCE true
|
||||
# INSTALL_COMMAND ""
|
||||
# SOURCE_DIR "${CMAKE_SOURCE_DIR}/lib/lua"
|
||||
#)
|
||||
#add_library(liblua
|
||||
# STATIC
|
||||
# IMPORTED
|
||||
#)
|
||||
#ExternalProject_Get_property(lua SOURCE_DIR)
|
||||
#message("liblua will be found at \'${SOURCE_DIR}/src\'")
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
|
|
1
lib/lua
Submodule
1
lib/lua
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit d69789da1ccfa4db7c241de6b471d6b729f1561e
|
|
@ -10,6 +10,7 @@
|
|||
#include "controllers/hotkeys/HotkeyController.hpp"
|
||||
#include "controllers/ignores/IgnoreController.hpp"
|
||||
#include "controllers/notifications/NotificationController.hpp"
|
||||
#include "controllers/plugins/PluginController.hpp"
|
||||
#include "controllers/sound/SoundController.hpp"
|
||||
#include "controllers/userdata/UserDataController.hpp"
|
||||
#include "debug/AssertInGuiThread.hpp"
|
||||
|
@ -52,7 +53,6 @@
|
|||
#include <atomic>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
static std::atomic<bool> isAppInitialized{false};
|
||||
|
||||
Application *Application::instance = nullptr;
|
||||
|
@ -85,6 +85,7 @@ Application::Application(Settings &_settings, Paths &_paths)
|
|||
, seventvBadges(&this->emplace<SeventvBadges>())
|
||||
, userData(&this->emplace<UserDataController>())
|
||||
, sound(&this->emplace<SoundController>())
|
||||
, plugins(&this->emplace<PluginController>())
|
||||
, logging(&this->emplace<Logging>())
|
||||
{
|
||||
this->instance = this;
|
||||
|
@ -143,7 +144,8 @@ void Application::initialize(Settings &settings, Paths &paths)
|
|||
if (auto channel = split->getChannel(); !channel->isEmpty())
|
||||
{
|
||||
channel->addMessage(makeSystemMessage(
|
||||
"Chatterino unexpectedly crashed and restarted. "
|
||||
"Chatterino unexpectedly crashed and "
|
||||
"restarted. "
|
||||
"You can disable automatic restarts in the "
|
||||
"settings."));
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ class HotkeyController;
|
|||
class IUserDataController;
|
||||
class UserDataController;
|
||||
class SoundController;
|
||||
class PluginController;
|
||||
|
||||
class Theme;
|
||||
class WindowManager;
|
||||
|
@ -95,6 +96,8 @@ public:
|
|||
UserDataController *const userData{};
|
||||
SoundController *const sound{};
|
||||
|
||||
PluginController *const plugins{};
|
||||
|
||||
/*[[deprecated]]*/ Logging *const logging{};
|
||||
|
||||
Theme *getThemes() override
|
||||
|
|
|
@ -136,6 +136,9 @@ set(SOURCE_FILES
|
|||
controllers/pings/MutedChannelModel.cpp
|
||||
controllers/pings/MutedChannelModel.hpp
|
||||
|
||||
controllers/plugins/PluginController.hpp
|
||||
controllers/plugins/PluginController.cpp
|
||||
|
||||
controllers/userdata/UserDataController.cpp
|
||||
controllers/userdata/UserDataController.hpp
|
||||
controllers/userdata/UserData.hpp
|
||||
|
@ -597,6 +600,7 @@ if (CHATTERINO_GENERATE_COVERAGE)
|
|||
)
|
||||
endif ()
|
||||
|
||||
add_dependencies(${LIBRARY_PROJECT} Lua)
|
||||
target_link_libraries(${LIBRARY_PROJECT}
|
||||
PUBLIC
|
||||
Qt${MAJOR_QT_VERSION}::Core
|
||||
|
@ -615,7 +619,9 @@ target_link_libraries(${LIBRARY_PROJECT}
|
|||
RapidJSON::RapidJSON
|
||||
LRUCache
|
||||
MagicEnum
|
||||
"${CMAKE_SOURCE_DIR}/lib/lua/liblua.a"
|
||||
)
|
||||
|
||||
if (BUILD_WITH_QTKEYCHAIN)
|
||||
target_link_libraries(${LIBRARY_PROJECT}
|
||||
PUBLIC
|
||||
|
|
|
@ -24,6 +24,7 @@ Q_LOGGING_CATEGORY(chatterinoIrc, "chatterino.irc", logThreshold);
|
|||
Q_LOGGING_CATEGORY(chatterinoIvr, "chatterino.ivr", logThreshold);
|
||||
Q_LOGGING_CATEGORY(chatterinoLiveupdates, "chatterino.liveupdates",
|
||||
logThreshold);
|
||||
Q_LOGGING_CATEGORY(chatterinoLua, "chatterino.lua", logThreshold);
|
||||
Q_LOGGING_CATEGORY(chatterinoMain, "chatterino.main", logThreshold);
|
||||
Q_LOGGING_CATEGORY(chatterinoMessage, "chatterino.message", logThreshold);
|
||||
Q_LOGGING_CATEGORY(chatterinoNativeMessage, "chatterino.nativemessage",
|
||||
|
|
|
@ -19,6 +19,7 @@ Q_DECLARE_LOGGING_CATEGORY(chatterinoImage);
|
|||
Q_DECLARE_LOGGING_CATEGORY(chatterinoIrc);
|
||||
Q_DECLARE_LOGGING_CATEGORY(chatterinoIvr);
|
||||
Q_DECLARE_LOGGING_CATEGORY(chatterinoLiveupdates);
|
||||
Q_DECLARE_LOGGING_CATEGORY(chatterinoLua);
|
||||
Q_DECLARE_LOGGING_CATEGORY(chatterinoMain);
|
||||
Q_DECLARE_LOGGING_CATEGORY(chatterinoMessage);
|
||||
Q_DECLARE_LOGGING_CATEGORY(chatterinoNativeMessage);
|
||||
|
|
55
src/controllers/plugins/PluginController.cpp
Normal file
55
src/controllers/plugins/PluginController.cpp
Normal file
|
@ -0,0 +1,55 @@
|
|||
#include "PluginController.hpp"
|
||||
|
||||
#include "common/QLogging.hpp"
|
||||
|
||||
#include <QApplication>
|
||||
|
||||
extern "C" {
|
||||
#include <lauxlib.h>
|
||||
#include <lua.h>
|
||||
#include <lualib.h>
|
||||
#include <qfileinfo.h>
|
||||
}
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
void PluginController::initialize(Settings &settings, Paths &paths)
|
||||
{
|
||||
(void)(settings);
|
||||
|
||||
auto dir = QDir(paths.pluginsDirectory);
|
||||
qCDebug(chatterinoLua) << "loading plugins from " << dir;
|
||||
for (const auto &info : dir.entryInfoList())
|
||||
{
|
||||
if (info.isDir())
|
||||
{
|
||||
// look for index.lua
|
||||
auto pluginDir = QDir(info.absoluteFilePath());
|
||||
auto index = QFileInfo(pluginDir.filePath("index.lua"));
|
||||
qCDebug(chatterinoLua)
|
||||
<< "trying" << info << "," << index << "at" << pluginDir;
|
||||
if (!index.exists())
|
||||
{
|
||||
qCDebug(chatterinoLua)
|
||||
<< "Missing index.lua in plugin directory" << pluginDir;
|
||||
continue;
|
||||
}
|
||||
qCDebug(chatterinoLua) << "found index.lua, running it!";
|
||||
|
||||
this->load(index, pluginDir);
|
||||
}
|
||||
}
|
||||
// QApplication::exit();
|
||||
}
|
||||
|
||||
void PluginController::load(QFileInfo index, QDir pluginDir)
|
||||
{
|
||||
qCDebug(chatterinoLua) << "Running lua file" << index;
|
||||
lua_State *l = luaL_newstate();
|
||||
luaL_openlibs(l);
|
||||
|
||||
luaL_dofile(l, index.absoluteFilePath().toStdString().c_str());
|
||||
lua_close(l);
|
||||
}
|
||||
|
||||
}; // namespace chatterino
|
21
src/controllers/plugins/PluginController.hpp
Normal file
21
src/controllers/plugins/PluginController.hpp
Normal file
|
@ -0,0 +1,21 @@
|
|||
#pragma once
|
||||
|
||||
#include "common/Singleton.hpp"
|
||||
#include "singletons/Paths.hpp"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class PluginController : public Singleton
|
||||
{
|
||||
public:
|
||||
void initialize(Settings &settings, Paths &paths) override;
|
||||
void save() override{};
|
||||
|
||||
private:
|
||||
void load(QFileInfo index, QDir pluginDir);
|
||||
};
|
||||
|
||||
}; // namespace chatterino
|
|
@ -141,6 +141,7 @@ void Paths::initSubDirectories()
|
|||
this->messageLogDirectory = makePath("Logs");
|
||||
this->miscDirectory = makePath("Misc");
|
||||
this->twitchProfileAvatars = makePath("ProfileAvatars");
|
||||
this->pluginsDirectory = makePath("Plugins");
|
||||
//QDir().mkdir(this->twitchProfileAvatars + "/twitch");
|
||||
}
|
||||
|
||||
|
|
|
@ -31,6 +31,9 @@ public:
|
|||
// Profile avatars for Twitch <appDataDirectory>/cache/twitch
|
||||
QString twitchProfileAvatars;
|
||||
|
||||
// Plugin files live here. <appDataDirectory>/Plugins
|
||||
QString pluginsDirectory;
|
||||
|
||||
bool createFolder(const QString &folderPath);
|
||||
bool isPortable();
|
||||
|
||||
|
|
Loading…
Reference in a new issue