diff --git a/CMakeLists.txt b/CMakeLists.txt index 353d592..92a3424 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -90,7 +90,7 @@ endif() configure_file(config.h.in config.h) include_directories(${CMAKE_CURRENT_BINARY_DIR}) -add_definitions(-DFCITX_GETTEXT_DOMAIN=\"fcitx5-lua\") +add_definitions("-DFCITX_GETTEXT_DOMAIN=\"fcitx5-lua\"") fcitx5_add_i18n_definition() add_subdirectory(src) diff --git a/config.h.in b/config.h.in index 791e342..64e843e 100644 --- a/config.h.in +++ b/config.h.in @@ -7,7 +7,23 @@ #ifndef _FCITX5_LUA_CONFIG_H_ #define _FCITX5_LUA_CONFIG_H_ + #cmakedefine LUA_LIBRARY_PATH "@LUA_LIBRARY_PATH@" #cmakedefine USE_DLOPEN +#ifdef USE_DLOPEN +#include +#else +#include +#endif + +namespace fcitx { +#ifdef USE_DLOPEN +using LibraryPtr = fcitx::Library*; +#else +using LibraryPtr = std::nullptr_t; +#endif + +} + #endif // _FCITX5_LUA_CONFIG_H_ diff --git a/src/addonloader/luaaddon.cpp b/src/addonloader/luaaddon.cpp index 75d6744..11e1754 100644 --- a/src/addonloader/luaaddon.cpp +++ b/src/addonloader/luaaddon.cpp @@ -5,11 +5,11 @@ * */ #include "luaaddon.h" +#include "config.h" #include "luaaddonstate.h" #include "luahelper.h" #include #include -#include #include #include #include @@ -18,7 +18,7 @@ namespace fcitx { -LuaAddon::LuaAddon(Library *luaLibrary, const AddonInfo &info, +LuaAddon::LuaAddon(LibraryPtr luaLibrary, const AddonInfo &info, AddonManager *manager) : instance_(manager->instance()), name_(info.uniqueName()), library_(info.library()), state_(std::make_unique( diff --git a/src/addonloader/luaaddon.h b/src/addonloader/luaaddon.h index a0b236a..8be7478 100644 --- a/src/addonloader/luaaddon.h +++ b/src/addonloader/luaaddon.h @@ -7,11 +7,11 @@ #ifndef _FCITX5_LUA_ADDONLOADER_LUAADDON_H_ #define _FCITX5_LUA_ADDONLOADER_LUAADDON_H_ +#include "config.h" #include "luaaddon_public.h" #include "luaaddonstate.h" #include "luahelper.h" #include -#include #include #include #include @@ -25,7 +25,8 @@ class AddonManager; class LuaAddon : public AddonInstance { public: - LuaAddon(Library *luaLibrary, const AddonInfo &info, AddonManager *manager); + LuaAddon(LibraryPtr luaLibrary, const AddonInfo &info, + AddonManager *manager); void reloadConfig() override; @@ -39,7 +40,7 @@ class LuaAddon : public AddonInstance { const std::string library_; std::unique_ptr state_; - Library *luaLibrary_; + LibraryPtr luaLibrary_; }; } // namespace fcitx diff --git a/src/addonloader/luaaddonloader.cpp b/src/addonloader/luaaddonloader.cpp index 24db63a..b837246 100644 --- a/src/addonloader/luaaddonloader.cpp +++ b/src/addonloader/luaaddonloader.cpp @@ -5,12 +5,10 @@ * */ #include "luaaddonloader.h" -#include "config.h" #include "luaaddon.h" #include "luahelper.h" #include "luastate.h" #include -#include #include #include #include @@ -52,7 +50,7 @@ LuaAddonLoader::LuaAddonLoader() { } // Create test state to ensure the function can be resolved. - LuaState testState(luaLibrary_.get()); + LuaState testState(luaLibrary()); } AddonInstance *LuaAddonLoader::load(const AddonInfo &info, @@ -65,7 +63,7 @@ AddonInstance *LuaAddonLoader::load(const AddonInfo &info, if (info.category() == AddonCategory::Module) { try { auto addon = - std::make_unique(luaLibrary_.get(), info, manager); + std::make_unique(luaLibrary(), info, manager); return addon.release(); } catch (const std::exception &e) { FCITX_LUA_ERROR() << "Loading lua addon " << info.uniqueName() diff --git a/src/addonloader/luaaddonloader.h b/src/addonloader/luaaddonloader.h index e4b521a..ec8213a 100644 --- a/src/addonloader/luaaddonloader.h +++ b/src/addonloader/luaaddonloader.h @@ -7,14 +7,17 @@ #ifndef _FCITX5_LUA_ADDONLOADER_LUAADDONLOADER_H_ #define _FCITX5_LUA_ADDONLOADER_LUAADDONLOADER_H_ -#include +#include "config.h" #include #include #include #include -#include #include +#ifdef USE_DLOPEN +#include +#endif + namespace fcitx { class LuaAddonLoader : public AddonLoader { @@ -23,8 +26,14 @@ class LuaAddonLoader : public AddonLoader { std::string type() const override { return "Lua"; } AddonInstance *load(const AddonInfo &info, AddonManager *manager) override; +#ifdef USE_DLOPEN + LibraryPtr luaLibrary() const { return luaLibrary_.get(); } + private: std::unique_ptr luaLibrary_; +#else + LibraryPtr luaLibrary() const { return nullptr; } +#endif }; class LuaAddonLoaderAddon : public AddonInstance { diff --git a/src/addonloader/luaaddonstate.cpp b/src/addonloader/luaaddonstate.cpp index 525ad0f..0485bab 100644 --- a/src/addonloader/luaaddonstate.cpp +++ b/src/addonloader/luaaddonstate.cpp @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include @@ -122,7 +121,7 @@ void luaToRawConfig(LuaState *state, RawConfig &config) { } // namespace -LuaAddonState::LuaAddonState(Library *luaLibrary, const std::string &name, +LuaAddonState::LuaAddonState(LibraryPtr luaLibrary, const std::string &name, const std::string &library, AddonManager *manager) : instance_(manager->instance()), state_(std::make_unique(luaLibrary)) { diff --git a/src/addonloader/luaaddonstate.h b/src/addonloader/luaaddonstate.h index 94139cc..60085cc 100644 --- a/src/addonloader/luaaddonstate.h +++ b/src/addonloader/luaaddonstate.h @@ -7,12 +7,12 @@ #ifndef _FCITX5_LUA_ADDONLOADER_LUAADDONSTATE_H_ #define _FCITX5_LUA_ADDONLOADER_LUAADDONSTATE_H_ +#include "config.h" #include "luahelper.h" #include "luastate.h" #include #include #include -#include #include #include #include @@ -97,7 +97,7 @@ class Converter { class LuaAddonState { public: - LuaAddonState(Library *luaLibrary, const std::string &name, + LuaAddonState(LibraryPtr luaLibrary, const std::string &name, const std::string &library, AddonManager *manager); operator LuaState *() { return state_.get(); } diff --git a/src/addonloader/luastate.cpp b/src/addonloader/luastate.cpp index f56279f..71b8278 100644 --- a/src/addonloader/luastate.cpp +++ b/src/addonloader/luastate.cpp @@ -7,7 +7,6 @@ #include "luastate.h" #include "config.h" #include "luahelper.h" -#include #include #ifdef USE_DLOPEN @@ -19,7 +18,7 @@ #define FILL_LUA_API(FUNCTION) FUNCTION##_ = GET_LUA_API(FUNCTION) namespace fcitx { -LuaState::LuaState(Library *library) +LuaState::LuaState(LibraryPtr library) : luaLibrary_(library), state_(nullptr, _fcitx_lua_close) { // Resolve all required lua function first. #define FOREACH_LUA_FUNCTION(NAME) \ diff --git a/src/addonloader/luastate.h b/src/addonloader/luastate.h index 68ab988..ff37705 100644 --- a/src/addonloader/luastate.h +++ b/src/addonloader/luastate.h @@ -7,8 +7,8 @@ #ifndef _FCITX5_LUA_ADDONLOADER_LUASTATE_H_ #define _FCITX5_LUA_ADDONLOADER_LUASTATE_H_ +#include "config.h" #include "luastate_details.h" -#include #include #include // IWYU pragma: export #include @@ -17,7 +17,7 @@ namespace fcitx { struct LuaState { public: - LuaState(Library *library); + LuaState(LibraryPtr library); #define FOREACH_LUA_FUNCTION DEFINE_LUA_API_FUNCTION #include "luafunc.h" @@ -29,7 +29,7 @@ struct LuaState { } private: - Library *luaLibrary_; + LibraryPtr luaLibrary_ [[maybe_unused]]; #define FOREACH_LUA_FUNCTION DECLARE_LUA_FUNCTION_PTR #include "luafunc.h"