Rime Lua
How To Use This Skill
Use this skill for Rime Lua implementation and debugging. Keep this file as the decision checklist; load full-reference for function signatures, detailed examples, and object usage. Load librime.lua only when exact API members or type details are needed.
| User Need | Component |
|---|---|
| Intercept, consume, or rewrite key events | lua_processor |
| Add tags or custom segmentation | lua_segmentor |
| Generate candidates from input | lua_translator |
| Modify, reorder, annotate, or remove existing candidates | lua_filter |
Component Shape
Lua modules can return either a function or a lifecycle table:
local M = {}
function M.init(env)
env.config = env.engine.schema.config
end
function M.func(...)
-- component logic
end
function M.fini(env)
if env.conn then env.conn:disconnect() end
end
return M
Rules:
- Put instance state on
env, not in module globals. - Use
env.name_spacefor per-instance YAML namespaces. - Disconnect notifiers, databases, and memories in
fini. - Translator and filter components output with
yield(cand), not return values.
Return Values And Output
| Component | Main Function | Output |
|---|---|---|
processor |
func(key_event, env) |
0 rejected, 1 accepted, 2 noop |
segmentor |
func(segmentation, env) |
boolean continue/stop |
translator |
func(input, segment, env) |
one or more yield(Candidate(...)) |
filter |
func(input, env) |
iterate upstream and yield kept/changed candidates |
For exact signatures and examples, load full-reference.
Schema Reference Forms
Lua component references are configured in schema.yaml:
engine:
translators:
- lua_translator@func_name
- lua_translator@*module_name
- lua_translator@*module_name@namespace
If the issue is component wiring rather than Lua code, use rime-gears.
Debug Checklist
Before changing code, check:
- The Lua file is under the Rime user data directory:
rime.luaorlua/<module>.lua. - The YAML reference exactly matches the global function or module path.
- The module returns the expected function/table.
- Candidate start/end positions use
segment.startandsegment._end. - Filters use
ShadowCandidatewhen changing text/comment on wrapped or read-only candidates. - Logs show whether the Lua file loaded or raised an error.