@@ -31,6 +31,7 @@ using namespace rime;
31
31
namespace {
32
32
33
33
template <typename > using void_t = void ;
34
+ template <typename T1, typename T2> using fst_t = T1;
34
35
35
36
template <typename T, typename = void >
36
37
struct COMPAT {
@@ -50,6 +51,14 @@ struct COMPAT {
50
51
static string get_sync_dir () {
51
52
return string (rime_get_api ()->get_sync_dir ());
52
53
}
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
+ }
53
62
};
54
63
55
64
template <typename T>
@@ -73,6 +82,14 @@ struct COMPAT<T, void_t<decltype(std::declval<T>().user_data_dir.string())>> {
73
82
T &deployer = Service::instance ().deployer ();
74
83
return deployer.sync_dir .string ();
75
84
}
85
+
86
+ static bool Config_load_from_file (fst_t <Config, T> &t, const string &f) {
87
+ return t.LoadFromFile (path (f));
88
+ }
89
+
90
+ static bool Config_save_to_file (fst_t <Config, T> &t, const string &f) {
91
+ return t.SaveToFile (path (f));
92
+ }
76
93
};
77
94
78
95
// --- wrappers for Segment
@@ -1217,7 +1234,7 @@ namespace ConfigReg {
1217
1234
int raw_make (lua_State *L) {
1218
1235
an<T> config = New<T>();
1219
1236
if (auto cstr = lua_tostring (L, 1 )) {
1220
- config-> LoadFromFile ( path ( cstr) );
1237
+ COMPAT<Deployer>:: Config_load_from_file (config, cstr);
1221
1238
}
1222
1239
LuaType<an<T>>::pushdata (L, config);
1223
1240
return 1 ;
@@ -1281,13 +1298,6 @@ namespace ConfigReg {
1281
1298
return t.SetItem (path, value);
1282
1299
}
1283
1300
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
-
1291
1301
static const luaL_Reg funcs[] = {
1292
1302
{ " Config" , (raw_make)},
1293
1303
{ NULL , NULL },
@@ -1296,8 +1306,8 @@ namespace ConfigReg {
1296
1306
static const luaL_Reg methods[] = {
1297
1307
// bool LoadFromStream(std::istream& stream);
1298
1308
// 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 ) },
1301
1311
1302
1312
{ " is_null" , WRAPMEM (T::IsNull) },
1303
1313
{ " is_value" , WRAPMEM (T::IsValue) },
0 commit comments