Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

能否支持只包含 init=function(env) 的 Lua组件 #268

Open
hoofcushion opened this issue Sep 5, 2023 · 3 comments
Open

能否支持只包含 init=function(env) 的 Lua组件 #268

hoofcushion opened this issue Sep 5, 2023 · 3 comments

Comments

@hoofcushion
Copy link

hoofcushion commented Sep 5, 2023

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 的值必须是函数。

@hoofcushion
Copy link
Author

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 时跳过而非报错

@shewer
Copy link
Contributor

shewer commented Sep 5, 2023

使用 notifier:connect() 一定要在 fini(env) 中,加入 notifier:disconnect() 解構

func 是 processor segmentor translator filter 的主體,主要應用
改 c++ , lua ; 覺得 lua 容易些

@hoofcushion
Copy link
Author

目前我的解决办法是在engine/processors末尾调用一个func部分永远返回kNooplua_processor
基本符合预期

return
{
 init=function(env)
  ...
 end,
 func=function()
  return 2;
 end,
 fini=function()
  ...
 end,
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants