Skip to content
New issue

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

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

Already on GitHub? # to your account

Memory dev: changed args or LuaMemory::LuaMemory and LuaMemory::memorize() #199

Open
wants to merge 33 commits into
base: master
Choose a base branch
from

Conversation

shewer
Copy link
Contributor

@shewer shewer commented Sep 24, 2022

shewer added 30 commits March 30, 2021 20:03
Signed-off-by: shewer <shewer@gmail.com>
Signed-off-by: shewer <shewer@gmail.com>
Signed-off-by: shewer <shewer@gmail.com>
Signed-off-by: shewer <shewer@gmail.com>
Signed-off-by: shewer <shewer@gmail.com>
Signed-off-by: shewer <shewer@gmail.com>
Signed-off-by: shewer <shewer@gmail.com>
Signed-off-by: shewer <shewer@gmail.com>
Signed-off-by: shewer <shewer@gmail.com>
Signed-off-by: shewer <shewer@gmail.com>
* add  EngineReg select_schema()  env.engine:select( string schema_id ) .next

Signed-off-by: shewer <shewer@gmail.com>

* add engine:apply_schema( Schema &)   Schema( const string &)

Signed-off-by: shewer <shewer@gmail.com>
Signed-off-by: shewer <shewer@gmail.com>
Signed-off-by: shewer <shewer@gmail.com>
Signed-off-by: Shewer Lu <shewer@gmail.com>
Signed-off-by: Shewer Lu <shewer@gmail.com>
Signed-off-by: Shewer Lu <shewer@gmail.com>
Signed-off-by: Shewer Lu <shewer@gmail.com>
@hchunhui
Copy link
Owner

hchunhui commented Oct 4, 2022

不赞同。这样又改变接口了,也没有明显的好处。

@shewer
Copy link
Contributor Author

shewer commented Oct 4, 2022

不赞同。这样又改变接口了,也没有明显的好处。

  • 初始化 不影響 ,增加argv[4] callback 且可以直接掛上 callback
  • env.mem:memorize( function(commit) callback(env.mem, commit) end ) -- env.mem 得再掛入Anonymous function 沒有意義呀 ,env.mem 等同 self,
  • 修改後 env.mem:memorize( function(mem,commit) ..... end) -- 可以 盡可能不用調用外部變數
  • 改變的是 memorize( callback) callback的 參數(commit) --> (mem, commit)

@hchunhui
Copy link
Owner

hchunhui commented Oct 4, 2022

* 改變的是 memorize( callback)   callback的 參數(commit) --> (mem, commit)

是的,就是这里要改变。另外 callback 不一定需要 env.mem,也有可能需要其他参数,既然 anonymous function 可以绑定任意参数,所以不如统一不带,由用户自己决定。

@shewer
Copy link
Contributor Author

shewer commented Oct 4, 2022

是的,就是这里要改变。另外 callback 不一定需要 env.mem,也有可能需要其他参数,既然 anonymous function 可以绑定任意参数,所以不如统一不带,由用户自己决定。

LuaMemory callback_commit ,我的理解 是 commit 時處理 commitEntry to userdb
要處理 userdb 須要 mem 及 commitEntry
當OnCommit時 Momory 會產生 entry and entry.save()
--> 呼叫 Memory::Memorize() --> LuaObj( this, entry)

callback 是外部function 須要 將 memory 自身 及 commitEntrys 傳遞 給callback
才能 由callback 處理 userdb.


callback 是 LuaMemoryze::Memorize()
把 commitEntrys update userdb

Memory::OnCommit(ctx) 取出commit candidate 轉置 commitentrys
call Memorize() 將 CommitEntrys commit to userdb

要如何自定引數?
我能想到的方式是用

local function gen_callback( args)
     return function(mem,commit) 
          ... ...
     end
end
env.mem:memorize( gen_callback( args) ) 

env.mem:memorize( wrap_func( ...) .... return function(mem,commit) .... end end)

https://github.com/rime/librime/blob/f931b5bba731a1543634023f688563e546cd5107/src/rime/gear/memory.h#L40
Memory::OnCommit()
https://github.com/rime/librime/blob/f931b5bba731a1543634023f688563e546cd5107/src/rime/gear/memory.cc#L103-L120
OnCommit(ctx) -- CommitEntry:Save() --> Memorize() this(mem) and entry_commit

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

Successfully merging this pull request may close these issues.

2 participants