Lua
Fcitx can be easily extended with lua.
API documentation is available on Github.
Make Fcitx load lua script
Single file lua script with imeapi support
Sometimes, you may have a simple lua script that you want to use. If that's the case, you can simple put it under ~/.local/share/fcitx5/lua/imeapi/extensions/[name].lua
. IME API will just load it upon start up.
In addition to the standard fcitx module, there is also "ime" module available if you load it this way. The API follows the Google Pinyin's lua API that was once available on Windows. If you have some scripts that was designed at that time, you may simple drop the script in without modification.
Stand alone lua addon
You may also create an standard lua addon like any other Fcitx addon. You will still need a file under XDG_DATA/fcitx5/addon/[addon name].conf
.
[Addon] Name[da]=Lua IME-API Name[fr]=API IME Lua Name[ja]=Lua IME API Name[ko]=Lua IME API Name[ru]=Lua IME API Name[zh_CN]=Lua IME API Name[zh_TW]=Lua 輸入法 API Name=Lua IME API Comment[da]=Understøttelse af Lua IME-API Comment[fr]=Prise en charge de l'API IME Lua Comment[ja]=Lua IME API サポート Comment[ko]=Lua IME API 지원 Comment[ru]=Поддержка Lua IME API Comment[zh_CN]=Lua IME API 支持 Comment[zh_TW]=Lua 輸入法 API 支援 Comment=Lua IME API support Category=Module Version=5.0.12 Type=Lua OnDemand=False Configurable=False Library=imeapi.lua [Addon/Dependencies] 0=luaaddonloader
At this point, only Category=Module
is supported. And unlike the regular shared library addon, the Library
field should be the entry file, which is placed under XDG_DATA/fcitx5/lua/[addon name]/[file name].lua
.
And the addon dependency is required to contain luaaddonloader
.
Use Fcitx Lua API
Simply use require("fcitx")
to load fcitx module.
There are many API that allows you to register a callback function. In most case, the callback function needs to be global and is passed with function name as string, not as a function variable.