Skip to content

Commit

Permalink
CommitEntry add update(commit) update(entry, commit, prefix_str)
Browse files Browse the repository at this point in the history
Signed-off-by: shewer <shewer@gmail.com>
  • Loading branch information
shewer committed Oct 29, 2023
1 parent 7c297e4 commit c37dc77
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
11 changes: 10 additions & 1 deletion sample/lua/expand_translator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,20 @@ local function memoryCallback(memory, commit)
return true
end

local function memoryCallback1(commit)
for i, dictentry in ipairs(commit:get()) do
commits:update_entry(dictentry, 1, "")
end
--commits:update(1) --
end


local function init(env)
env.mem = Memory(env.engine,env.engine.schema) -- ns= "translator"
-- env.mem = Memory(env.engine,env.engine.schema, env.name_space )
-- env.mem = Memory(env.engine,Schema("cangjie5") ) -- ns= "translator-
env.mem:memorize(function(commit) memoryCallback(env.mem, commit) end)
--env.mem:memorize(function(commit) memoryCallback(env.mem, commit) end)
env.mem:memorize(memoryCallback1)
-- or use
-- schema = Schema("cangjie5") -- schema_id
-- env.mem = Memory(env.engine, schema, "translator")
Expand Down
39 changes: 35 additions & 4 deletions src/types.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@
#include <boost/regex.hpp>

#include "lib/lua_export_type.h"
#include "optional.h"
#include "lib/luatype_boost_optional.h"

#define ENABLE_TYPES_EXT

using namespace rime;
using boost::optional;

namespace {

Expand Down Expand Up @@ -1356,17 +1357,42 @@ namespace LogReg {
}
namespace CommitEntryReg {
using T = CommitEntry;
using D = DictEntry;

vector<const rime::DictEntry*> get(const T& ce) {
return ce.elements;
}
bool update_entry(const T &t, const D& entry, int commit, const string& prefix_str) {
if (!t.memory)
return false;
auto user_dict = t.memory->user_dict();
if (!user_dict || !user_dict->loaded())
return false;

return user_dict->UpdateEntry(entry, commit, prefix_str);
}

bool update(const T& t, int commit) {
if (!t.memory)
return false;
auto user_dict = t.memory->user_dict();
if (!user_dict || !user_dict->loaded())
return false;

for (const DictEntry* e : t.elements) {
user_dict->UpdateEntry(*e, commit);
}
return true;
}

static const luaL_Reg funcs[] = {
{ NULL, NULL },
};

static const luaL_Reg methods[] = {
{"get",WRAP(get)},
{"update_entry",WRAP(update_entry)},
{"update",WRAP(update)},
{ NULL, NULL },
};

Expand All @@ -1380,12 +1406,17 @@ namespace CommitEntryReg {
}
namespace DictEntryReg {
using T = DictEntry;
an<T> make() {
return an<T>(new T());

int raw_make(lua_State* L) {
an<T> t = (lua_gettop(L)>0)
? New<T>(LuaType<const T&>::todata(L,1)) : New<T>();

LuaType<an<T>>::pushdata(L, t);
return 1;
}

static const luaL_Reg funcs[] = {
{"DictEntry",WRAP(make)},
{"DictEntry",raw_make},
{ NULL, NULL },
};

Expand Down

0 comments on commit c37dc77

Please sign in to comment.