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

tie the lifetime of the lua state to components #353

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ksqsf
Copy link
Contributor

@ksqsf ksqsf commented Jun 12, 2024

Currently, the lifetime of the lua state is not destroyed even all sessions are dead. This is because the Lua state is tied to the registration, not the real live components.

This creates a rather weird problem, that the Lua state will not be destroyed when all sessions are destroyed with rime_api->cleanup_all_sessions. A known problem is that this can affect the usability of synchronization, if the lua script author forgets to set lua Components to nil and/or call collectgarbage manually.

This PR defers the creation of the lua state until a lua gear is actually created. Then, the ownership of the created lua state is shared globally, and the lua state will be destroyed when no one is referring to the lua state. Finally, if it is requested again, a new lua state will be created.

This is probably a breaking change for some users.

@hchunhui
Copy link
Owner

原先的考虑是 lua script 可能会保存一些全局状态,比如启动以来打了几个字,最近的候选是哪些等,所以做成了这种不与组件绑定的形式。

这个 PR 吸引人的地方是可以比较明显地降低 script 的编写难度,但需要评估一下影响。我对 rime session 的不是很了解,不太清楚是否会经常性地重建,导致 lua 状态丢失。

@hchunhui
Copy link
Owner

另外 Component 只能用 gc 来销毁,我认为应该类似 #335 (comment) 这里也提供一个手动释放的方法。

@ksqsf
Copy link
Contributor Author

ksqsf commented Jun 14, 2024

按目前的写法,sync 和 deploy 的时候一定会重建状态。自然使用时 session 全部消失似乎可能性很低,不过切到别的输入法的时候应该就没了。

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

Successfully merging this pull request may close these issues.

2 participants