Skip to content

Commit

Permalink
build with old librime
Browse files Browse the repository at this point in the history
  • Loading branch information
hchunhui committed Oct 27, 2024
1 parent 5819dca commit e42e351
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions src/types.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ using namespace rime;
namespace {

template<typename> using void_t = void;
template<typename T1, typename T2> using fst_t = T1;

template<typename T, typename = void>
struct COMPAT {
Expand All @@ -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<Config, T> &t, const string &f) {
return t.LoadFromFile(f);
}

static bool Config_save_to_file(fst_t<Config, T> &t, const string &f) {
return t.SaveToFile(f);
}
};

template<typename T>
Expand All @@ -73,6 +82,14 @@ struct COMPAT<T, void_t<decltype(std::declval<T>().user_data_dir.string())>> {
T &deployer = Service::instance().deployer();
return deployer.sync_dir.string();
}

bool Config_load_from_file(fst_t<Config, T> &t, const string &f) {
return t.LoadFromFile(path(f));
}

bool Config_save_to_file(fst_t<Config, T> &t, const string &f) {
return t.SaveToFile(path(f));
}
};

//--- wrappers for Segment
Expand Down Expand Up @@ -1217,7 +1234,7 @@ namespace ConfigReg {
int raw_make(lua_State *L) {
an<T> config = New<T>();
if (auto cstr = lua_tostring(L, 1)) {
config->LoadFromFile(path(cstr));
COMPAT<Deployer>::Config_load_from_file(config, cstr);
}
LuaType<an<T>>::pushdata(L, config);
return 1;
Expand Down Expand Up @@ -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 },
Expand All @@ -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<Deployer>::Config_load_from_file) },
{ "save_to_file", WRAP(COMPAT<Deployer>::Config_save_to_file) },

{ "is_null", WRAPMEM(T::IsNull) },
{ "is_value", WRAPMEM(T::IsValue) },
Expand Down

0 comments on commit e42e351

Please sign in to comment.