hchunhui / librime-lua

Extending RIME with Lua scripts
BSD 3-Clause "New" or "Revised" License
304 stars 43 forks source link

使用 ConcreteEngine::ApplySchema 重載 schema 是否可行 #82

Open shewer opened 3 years ago

shewer commented 3 years ago

在 librime src/engine.cc 有三個function https://github.com/rime/librime/blob/6031ef34735d9bf43aef76cf15a025c5e43c436a/src/rime/engine.cc#L29

virtual void ApplySchema(Schema* schema); // reload schema void InitializeComponents(); // reload compnents void InitializeOptions(); //reload switchs

https://github.com/rime/librime/blob/master/src/rime/engine.cc#L270

增加 ApplySchema(schema *) api 會重新載入
在 lua 修改 schema 後 再執行 重載 是否可動態修改schema 環境

shewer commented 3 years ago

在 librime src/engine.cc 有三個function https://github.com/rime/librime/blob/6031ef34735d9bf43aef76cf15a025c5e43c436a/src/rime/engine.cc#L29

virtual void ApplySchema(Schema* schema); // reload schema void InitializeComponents(); // reload compnents void InitializeOptions(); //reload switchs

https://github.com/rime/librime/blob/master/src/rime/engine.cc#L270

增加 ApplySchema(schema *) api 會重新載入 在 lua 修改 schema 後 再執行 重載 是否可動態修改schema 環境

我在 types.cc EngineReg 增加 { "apply_schema",WRAPMEM(T::ApplySchema) },
井在 lua script 但是 得到 error log : bad argument#1 該如何 取得 schema* schema ???

local config= env.engine.schema.config
local ps=config:get_int("menu/page_size")
config:set_int("menu/page_size", 5)
env.engine.apply_schema( env.engine.schema )
-- error.log  : bad argument #1 to 'apply_schema' (struct LuaType<class rime::Engine &> expected)
shewer commented 3 years ago

在 librime src/engine.cc 有三個function https://github.com/rime/librime/blob/6031ef34735d9bf43aef76cf15a025c5e43c436a/src/rime/engine.cc#L29 virtual void ApplySchema(Schema schema); // reload schema void InitializeComponents(); // reload compnents void InitializeOptions(); //reload switchs 在 https://github.com/rime/librime/blob/master/src/rime/engine.cc#L270 增加 ApplySchema(schema ) api 會重新載入 在 lua 修改 schema 後 再執行 重載 是否可動態修改schema 環境

我在 types.cc EngineReg 增加 { "apply_schema",WRAPMEM(T::ApplySchema) }, 井在 lua script 但是 得到 error log : bad argument#1 該如何 取得 schema* schema ???

local config= env.engine.schema.config
local ps=config:get_int("menu/page_size")
config:set_int("menu/page_size", 5)
env.engine.apply_schema( env.engine.schema ) 

-- error.log  : bad argument #1 to 'apply_schema' (struct LuaType<class rime::Engine &> expected)
-- 改成    engine:apply_schema  -- 當掉了
env.engine:apply_schema(env.engine.schema)  
--E1224 16:27:23.853719 17576 user_dictionary.cc:448] Error translating syllable_id '162803'.