@@ -50,6 +50,10 @@ struct COMPAT {
50
50
static string get_sync_dir () {
51
51
return string (rime_get_api ()->get_sync_dir ());
52
52
}
53
+
54
+ static string to_path (const std::string &file) {
55
+ return file;
56
+ }
53
57
};
54
58
55
59
template <typename T>
@@ -73,6 +77,10 @@ struct COMPAT<T, void_t<decltype(std::declval<T>().user_data_dir.string())>> {
73
77
T &deployer = Service::instance ().deployer ();
74
78
return deployer.sync_dir .string ();
75
79
}
80
+
81
+ static path to_path (const std::string &file) {
82
+ return path (file);
83
+ }
76
84
};
77
85
78
86
// --- wrappers for Segment
@@ -1214,6 +1222,15 @@ namespace ProjectionReg{
1214
1222
namespace ConfigReg {
1215
1223
using T = Config;
1216
1224
1225
+ int raw_make (lua_State *L) {
1226
+ an<T> config = New<T>();
1227
+ if (auto cstr = lua_tostring (L, 1 )) {
1228
+ config->LoadFromFile (COMPAT<Deployer>::to_path (cstr));
1229
+ }
1230
+ LuaType<an<T>>::pushdata (L, config);
1231
+ return 1 ;
1232
+ }
1233
+
1217
1234
optional<bool > get_bool (T &t, const string &path) {
1218
1235
bool v;
1219
1236
if (t.GetBool (path, &v))
@@ -1272,15 +1289,23 @@ namespace ConfigReg {
1272
1289
return t.SetItem (path, value);
1273
1290
}
1274
1291
1292
+ bool load_from_file (T &t, const string &f) {
1293
+ return t.LoadFromFile (COMPAT<Deployer>::to_path (f));
1294
+ }
1295
+ bool save_to_file (T &t, const string &f) {
1296
+ return t.SaveToFile (COMPAT<Deployer>::to_path (f));
1297
+ }
1298
+
1275
1299
static const luaL_Reg funcs[] = {
1300
+ { " Config" , (raw_make)},
1276
1301
{ NULL , NULL },
1277
1302
};
1278
1303
1279
1304
static const luaL_Reg methods[] = {
1280
1305
// bool LoadFromStream(std::istream& stream);
1281
1306
// bool SaveToStream(std::ostream& stream);
1282
- { " load_from_file" , WRAPMEM (T::LoadFromFile ) },
1283
- { " save_to_file" , WRAPMEM (T::SaveToFile ) },
1307
+ { " load_from_file" , WRAP (load_from_file ) },
1308
+ { " save_to_file" , WRAP (save_to_file ) },
1284
1309
1285
1310
{ " is_null" , WRAPMEM (T::IsNull) },
1286
1311
{ " is_value" , WRAPMEM (T::IsValue) },
0 commit comments