Skip to content

Commit e42e351

Browse files
committed
build with old librime
1 parent 5819dca commit e42e351

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

src/types.cc

+20-10
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ using namespace rime;
3131
namespace {
3232

3333
template<typename> using void_t = void;
34+
template<typename T1, typename T2> using fst_t = T1;
3435

3536
template<typename T, typename = void>
3637
struct COMPAT {
@@ -50,6 +51,14 @@ struct COMPAT {
5051
static string get_sync_dir() {
5152
return string(rime_get_api()->get_sync_dir());
5253
}
54+
55+
static bool Config_load_from_file(fst_t<Config, T> &t, const string &f) {
56+
return t.LoadFromFile(f);
57+
}
58+
59+
static bool Config_save_to_file(fst_t<Config, T> &t, const string &f) {
60+
return t.SaveToFile(f);
61+
}
5362
};
5463

5564
template<typename T>
@@ -73,6 +82,14 @@ struct COMPAT<T, void_t<decltype(std::declval<T>().user_data_dir.string())>> {
7382
T &deployer = Service::instance().deployer();
7483
return deployer.sync_dir.string();
7584
}
85+
86+
bool Config_load_from_file(fst_t<Config, T> &t, const string &f) {
87+
return t.LoadFromFile(path(f));
88+
}
89+
90+
bool Config_save_to_file(fst_t<Config, T> &t, const string &f) {
91+
return t.SaveToFile(path(f));
92+
}
7693
};
7794

7895
//--- wrappers for Segment
@@ -1217,7 +1234,7 @@ namespace ConfigReg {
12171234
int raw_make(lua_State *L) {
12181235
an<T> config = New<T>();
12191236
if (auto cstr = lua_tostring(L, 1)) {
1220-
config->LoadFromFile(path(cstr));
1237+
COMPAT<Deployer>::Config_load_from_file(config, cstr);
12211238
}
12221239
LuaType<an<T>>::pushdata(L, config);
12231240
return 1;
@@ -1281,13 +1298,6 @@ namespace ConfigReg {
12811298
return t.SetItem(path, value);
12821299
}
12831300

1284-
bool load_from_file(T &t, const string &f) {
1285-
return t.LoadFromFile(path(f));
1286-
}
1287-
bool save_to_file(T &t, const string &f) {
1288-
return t.SaveToFile(path(f));
1289-
}
1290-
12911301
static const luaL_Reg funcs[] = {
12921302
{ "Config", (raw_make)},
12931303
{ NULL, NULL },
@@ -1296,8 +1306,8 @@ namespace ConfigReg {
12961306
static const luaL_Reg methods[] = {
12971307
//bool LoadFromStream(std::istream& stream);
12981308
//bool SaveToStream(std::ostream& stream);
1299-
{ "load_from_file", WRAP(load_from_file) },
1300-
{ "save_to_file", WRAP(save_to_file) },
1309+
{ "load_from_file", WRAP(COMPAT<Deployer>::Config_load_from_file) },
1310+
{ "save_to_file", WRAP(COMPAT<Deployer>::Config_save_to_file) },
13011311

13021312
{ "is_null", WRAPMEM(T::IsNull) },
13031313
{ "is_value", WRAPMEM(T::IsValue) },

0 commit comments

Comments
 (0)