Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 16 additions & 0 deletions config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -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 <fcitx-utils/library.h>
#else
#include <cstddef>
#endif

namespace fcitx {
#ifdef USE_DLOPEN
using LibraryPtr = fcitx::Library*;
#else
using LibraryPtr = std::nullptr_t;
#endif

}

#endif // _FCITX5_LUA_CONFIG_H_
4 changes: 2 additions & 2 deletions src/addonloader/luaaddon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
*
*/
#include "luaaddon.h"
#include "config.h"
#include "luaaddonstate.h"
#include "luahelper.h"
#include <exception>
#include <fcitx-config/rawconfig.h>
#include <fcitx-utils/library.h>
#include <fcitx/addoninfo.h>
#include <fcitx/inputcontext.h>
#include <memory>
Expand All @@ -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<LuaAddonState>(
Expand Down
7 changes: 4 additions & 3 deletions src/addonloader/luaaddon.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <fcitx-config/rawconfig.h>
#include <fcitx-utils/library.h>
#include <fcitx/addoninfo.h>
#include <fcitx/addoninstance.h>
#include <fcitx/addonmanager.h>
Expand All @@ -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;

Expand All @@ -39,7 +40,7 @@ class LuaAddon : public AddonInstance {
const std::string library_;

std::unique_ptr<LuaAddonState> state_;
Library *luaLibrary_;
LibraryPtr luaLibrary_;
};

} // namespace fcitx
Expand Down
6 changes: 2 additions & 4 deletions src/addonloader/luaaddonloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
*
*/
#include "luaaddonloader.h"
#include "config.h"
#include "luaaddon.h"
#include "luahelper.h"
#include "luastate.h"
#include <exception>
#include <fcitx-utils/library.h>
#include <fcitx/addoninfo.h>
#include <fcitx/addoninstance.h>
#include <fcitx/addonmanager.h>
Expand Down Expand Up @@ -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,
Expand All @@ -65,7 +63,7 @@ AddonInstance *LuaAddonLoader::load(const AddonInfo &info,
if (info.category() == AddonCategory::Module) {
try {
auto addon =
std::make_unique<LuaAddon>(luaLibrary_.get(), info, manager);
std::make_unique<LuaAddon>(luaLibrary(), info, manager);
return addon.release();
} catch (const std::exception &e) {
FCITX_LUA_ERROR() << "Loading lua addon " << info.uniqueName()
Expand Down
13 changes: 11 additions & 2 deletions src/addonloader/luaaddonloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@
#ifndef _FCITX5_LUA_ADDONLOADER_LUAADDONLOADER_H_
#define _FCITX5_LUA_ADDONLOADER_LUAADDONLOADER_H_

#include <fcitx-utils/library.h>
#include "config.h"
#include <fcitx/addonfactory.h>
#include <fcitx/addoninfo.h>
#include <fcitx/addoninstance.h>
#include <fcitx/addonloader.h>
#include <memory>
#include <string>

#ifdef USE_DLOPEN
#include <memory>
#endif

namespace fcitx {

class LuaAddonLoader : public AddonLoader {
Expand All @@ -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<Library> luaLibrary_;
#else
LibraryPtr luaLibrary() const { return nullptr; }
#endif
};

class LuaAddonLoaderAddon : public AddonInstance {
Expand Down
3 changes: 1 addition & 2 deletions src/addonloader/luaaddonstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include <cstdint>
#include <fcitx-config/rawconfig.h>
#include <fcitx-utils/handlertable.h>
#include <fcitx-utils/library.h>
#include <fcitx-utils/standardpaths.h>
#include <fcitx-utils/stringutils.h>
#include <fcitx-utils/trackableobject.h>
Expand Down Expand Up @@ -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<LuaState>(luaLibrary)) {
Expand Down
4 changes: 2 additions & 2 deletions src/addonloader/luaaddonstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <exception>
#include <fcitx-config/rawconfig.h>
#include <fcitx-utils/handlertable.h>
#include <fcitx-utils/library.h>
#include <fcitx-utils/macros.h>
#include <fcitx-utils/signals.h>
#include <fcitx-utils/stringutils.h>
Expand Down Expand Up @@ -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(); }
Expand Down
3 changes: 1 addition & 2 deletions src/addonloader/luastate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "luastate.h"
#include "config.h"
#include "luahelper.h"
#include <fcitx-utils/library.h>
#include <stdexcept>

#ifdef USE_DLOPEN
Expand All @@ -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) \
Expand Down
6 changes: 3 additions & 3 deletions src/addonloader/luastate.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#ifndef _FCITX5_LUA_ADDONLOADER_LUASTATE_H_
#define _FCITX5_LUA_ADDONLOADER_LUASTATE_H_

#include "config.h"
#include "luastate_details.h"
#include <fcitx-utils/library.h>
#include <functional>
#include <lua.hpp> // IWYU pragma: export
#include <memory>
Expand All @@ -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"
Expand All @@ -29,7 +29,7 @@ struct LuaState {
}

private:
Library *luaLibrary_;
LibraryPtr luaLibrary_ [[maybe_unused]];

#define FOREACH_LUA_FUNCTION DECLARE_LUA_FUNCTION_PTR
#include "luafunc.h"
Expand Down
Loading