diff --git a/src/script_translator.cc b/src/script_translator.cc index 10ff48a..1144d24 100644 --- a/src/script_translator.cc +++ b/src/script_translator.cc @@ -22,7 +22,7 @@ using namespace rime; class LScriptTranslator : public ScriptTranslator { public: - LScriptTranslator(const Ticket& ticket, Lua* lua); + LScriptTranslator(const Ticket& ticket, Lua* lua); virtual bool Memorize(const CommitEntry& commit_entry); bool memorize(const CommitEntry& commit_entry); bool update_entry(const DictEntry& index, @@ -32,15 +32,14 @@ class LScriptTranslator : public ScriptTranslator { ACCESS_(memorize_callback, an); // ScriptTranslator member - ACCESS_(spelling_hints, int); // ok - ACCESS_(always_show_comments, bool); // ok - ACCESS_(max_homophones, int); // ok - GET_(enable_correction, bool); // ok + ACCESS_(spelling_hints, int); // ok + ACCESS_(always_show_comments, bool); // ok + ACCESS_(max_homophones, int); // ok + GET_(enable_correction, bool); // ok void set_enable_correction(bool); // TranslatorOptions void set_contextual_suggestions(bool); SET_(delimiters, string&); - protected: Lua* lua_; @@ -64,14 +63,15 @@ bool LScriptTranslator::Memorize(const CommitEntry& commit_entry) { return r.get(); } - bool LScriptTranslator::memorize(const CommitEntry& commit_entry) { return ScriptTranslator::Memorize(commit_entry); } LScriptTranslator::LScriptTranslator(const Ticket& ticket, Lua* lua) - : lua_(lua), ScriptTranslator(ticket), schema_id_(ticket.schema->schema_id()){ - memorize_callback_ = lua_->getglobal("___"); + : lua_(lua), + ScriptTranslator(ticket), + schema_id_(ticket.schema->schema_id()) { + memorize_callback_ = lua_->getglobal("___"); } void LScriptTranslator::set_enable_correction(bool enable) { @@ -81,7 +81,7 @@ void LScriptTranslator::set_enable_correction(bool enable) { if (auto* corrector = Corrector::Require("corrector")) { Schema schema = Schema(schema_id_); - Ticket ticket( &schema, name_space_); + Ticket ticket(&schema, name_space_); corrector_.reset(corrector->Create(ticket)); } } @@ -93,17 +93,15 @@ void LScriptTranslator::set_contextual_suggestions(bool enable) { poet_.reset(new Poet(language(), config, Poet::LeftAssociateCompare)); } - bool LScriptTranslator::update_entry(const DictEntry& entry, - int commits, - const string& new_entory_prefix) { + int commits, + const string& new_entory_prefix) { if (user_dict_ && user_dict_->loaded()) return user_dict_->UpdateEntry(entry, commits, new_entory_prefix); return false; } - namespace ScriptTranslatorReg { using T = LScriptTranslator; @@ -125,10 +123,10 @@ static const luaL_Reg vars_get[] = { Get_WMEM(memorize_callback), // an callback // ScriptTranslator member - Get_WMEM(max_homophones), // int - Get_WMEM(spelling_hints), // int - Get_WMEM(always_show_comments), // bool - Get_WMEM(enable_correction), // bool + Get_WMEM(max_homophones), // int + Get_WMEM(spelling_hints), // int + Get_WMEM(always_show_comments), // bool + Get_WMEM(enable_correction), // bool // TranslatorOptions Get_WMEM(delimiters), // string& Get_WMEM(tag), // string @@ -143,10 +141,10 @@ static const luaL_Reg vars_set[] = { Set_WMEM(memorize_callback), // an callback // ScriptTranslator member - Set_WMEM(max_homophones), // int - Set_WMEM(spelling_hints), // int - Set_WMEM(always_show_comments), // bool - Set_WMEM(enable_correction), // bool + Set_WMEM(max_homophones), // int + Set_WMEM(spelling_hints), // int + Set_WMEM(always_show_comments), // bool + Set_WMEM(enable_correction), // bool // TranslatorOptions Set_WMEM(delimiters), // string& Set_WMEM(tag), // string @@ -160,9 +158,8 @@ static const luaL_Reg vars_set[] = { void reg_Component(lua_State* L) { lua_getglobal(L, "Component"); if (lua_type(L, -1) != LUA_TTABLE) { - LOG(ERROR) << "table of _G[\"Component\"] not found."; - } - else { + LOG(ERROR) << "table of _G[\"Component\"] not found."; + } else { int index = lua_absindex(L, -1); lua_pushcfunction(L, raw_make_translator); lua_setfield(L, index, "ScriptTranslator"); @@ -170,7 +167,7 @@ void reg_Component(lua_State* L) { lua_pop(L, 1); } -} // namespace StriptTranslatorReg +} // namespace ScriptTranslatorReg } // namespace void LUAWRAPPER_LOCAL script_translator_init(lua_State* L) { diff --git a/src/table_translator.cc b/src/table_translator.cc index 6dea6e7..c19e3d1 100644 --- a/src/table_translator.cc +++ b/src/table_translator.cc @@ -7,7 +7,6 @@ #include - namespace { using namespace rime; @@ -29,13 +28,11 @@ class LTableTranslator : public TableTranslator { // GET_(enable_encoder, bool); // ok void set_enable_encoder(bool); // bool - // + // GET_(enable_sentence, bool); void set_enable_sentence(bool); - // ACCESS_(enable_sentence, bool);//ok GET_(sentence_over_completion, bool); void set_sentence_over_completion(bool); - // ACCESS_(sentence_over_completion, bool); void set_contextual_suggestions(bool); ACCESS_(encode_commit_history, bool); @@ -47,7 +44,7 @@ class LTableTranslator : public TableTranslator { protected: Lua* lua_; - an memorize_callback_ = {}; + an memorize_callback_; bool disable_userdict_ = false; string schema_id_; }; @@ -82,9 +79,10 @@ bool LTableTranslator::memorize(const CommitEntry& commit_entry) { } LTableTranslator::LTableTranslator(const Ticket& ticket, Lua* lua) - : lua_(lua), TableTranslator(ticket), schema_id_(ticket.schema->schema_id()){ - - memorize_callback_ = lua_->getglobal("___"); + : lua_(lua), + TableTranslator(ticket), + schema_id_(ticket.schema->schema_id()) { + memorize_callback_ = lua_->getglobal("___"); bool disable_userdict; Config* config = ticket.schema->config(); config->GetBool(name_space_ + "/disable_userdict", &disable_userdict); @@ -97,7 +95,7 @@ void LTableTranslator::set_enable_encoder(bool enable_encoder) { return; encoder_.reset(new UnityTableEncoder(user_dict_.get())); Schema schema = Schema(schema_id_); - Ticket ticket( &schema, name_space_); + Ticket ticket(&schema, name_space_); encoder_->Load(ticket); } @@ -202,9 +200,8 @@ static const luaL_Reg vars_set[] = { void reg_Component(lua_State* L) { lua_getglobal(L, "Component"); if (lua_type(L, -1) != LUA_TTABLE) { - LOG(ERROR) << "table of _G[\"Component\"] not found."; - } - else { + LOG(ERROR) << "table of _G[\"Component\"] not found."; + } else { int index = lua_absindex(L, -1); lua_pushcfunction(L, raw_make_translator); lua_setfield(L, index, "TableTranslator");