librime-lua
librime-lua copied to clipboard
能否支持只包含 init=function(env) 的 Lua组件
return {
init=function(env)
env.engine.context.commit_notifier:connect(
function(ctx)
local lct=ctx:get_commit_text()
if isPureChinese(lct) then
record(lct)
end
end)
end,
func=function()end
}
这个 Lua 会在汉字上屏后调用 record 函数,记录上屏内容,因此不需要 func 部分,但目前的 Lua组件 中 func 的值必须是函数。
lua_gears static void raw_init
...
if (lua_type(L, -1) != LUA_TFUNCTION) {
LOG(ERROR) << "Lua Compoment of initialize error:("
<< " module: "<< t.klass
<< " name_space: " << t.name_space
<< " func type: " << luaL_typename(L, -1)
<< " ): " << "func type error expect function ";
}
...
报错的似乎是这串代码,能否让他在 func 值为 nil 时跳过而非报错
使用 notifier:connect() 一定要在 fini(env) 中,加入 notifier:disconnect() 解構
func 是 processor segmentor translator filter 的主體,主要應用 改 c++ , lua ; 覺得 lua 容易些
目前我的解决办法是在engine/processors末尾调用一个func部分永远返回kNoop的lua_processor
基本符合预期
return
{
init=function(env)
...
end,
func=function()
return 2;
end,
fini=function()
...
end,
};