From 1348c09785e3f5faa07a90f1fd4d5bed9eb4ed10 Mon Sep 17 00:00:00 2001 From: Chunhui He Date: Sun, 27 Oct 2024 02:46:35 +0000 Subject: [PATCH] build with old librime --- src/types.cc | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/types.cc b/src/types.cc index 14e115a..0853b6e 100644 --- a/src/types.cc +++ b/src/types.cc @@ -31,6 +31,7 @@ using namespace rime; namespace { template using void_t = void; +template using fst_t = T1; template struct COMPAT { @@ -50,6 +51,14 @@ struct COMPAT { static string get_sync_dir() { return string(rime_get_api()->get_sync_dir()); } + + static bool Config_load_from_file(fst_t &t, const string &f) { + return t.LoadFromFile(f); + } + + static bool Config_save_to_file(fst_t &t, const string &f) { + return t.SaveToFile(f); + } }; template @@ -73,6 +82,14 @@ struct COMPAT().user_data_dir.string())>> { T &deployer = Service::instance().deployer(); return deployer.sync_dir.string(); } + + static bool Config_load_from_file(fst_t &t, const string &f) { + return t.LoadFromFile(path(f)); + } + + static bool Config_save_to_file(fst_t &t, const string &f) { + return t.SaveToFile(path(f)); + } }; //--- wrappers for Segment @@ -1217,7 +1234,7 @@ namespace ConfigReg { int raw_make(lua_State *L) { an config = New(); if (auto cstr = lua_tostring(L, 1)) { - config->LoadFromFile(path(cstr)); + COMPAT::Config_load_from_file(config, cstr); } LuaType>::pushdata(L, config); return 1; @@ -1281,13 +1298,6 @@ namespace ConfigReg { return t.SetItem(path, value); } - bool load_from_file(T &t, const string &f) { - return t.LoadFromFile(path(f)); - } - bool save_to_file(T &t, const string &f) { - return t.SaveToFile(path(f)); - } - static const luaL_Reg funcs[] = { { "Config", (raw_make)}, { NULL, NULL }, @@ -1296,8 +1306,8 @@ namespace ConfigReg { static const luaL_Reg methods[] = { //bool LoadFromStream(std::istream& stream); //bool SaveToStream(std::ostream& stream); - { "load_from_file", WRAP(load_from_file) }, - { "save_to_file", WRAP(save_to_file) }, + { "load_from_file", WRAP(COMPAT::Config_load_from_file) }, + { "save_to_file", WRAP(COMPAT::Config_save_to_file) }, { "is_null", WRAPMEM(T::IsNull) }, { "is_value", WRAPMEM(T::IsValue) },