Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed config:load_from_file() & config:save_tofile , add Config() #365

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions src/types.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1214,6 +1214,15 @@ namespace ProjectionReg{
namespace ConfigReg {
using T = Config;

int raw_make(lua_State *L) {
an<T> config = New<T>();
if (auto cstr = lua_tostring(L, 1)) {
config->LoadFromFile(path(cstr));
}
LuaType<an<T>>::pushdata(L, config);
return 1;
}

optional<bool> get_bool(T &t, const string &path) {
bool v;
if (t.GetBool(path, &v))
Expand Down Expand Up @@ -1272,15 +1281,23 @@ 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 },
};

static const luaL_Reg methods[] = {
//bool LoadFromStream(std::istream& stream);
//bool SaveToStream(std::ostream& stream);
{ "load_from_file", WRAPMEM(T::LoadFromFile) },
{ "save_to_file", WRAPMEM(T::SaveToFile) },
{ "load_from_file", WRAP(load_from_file) },
{ "save_to_file", WRAP(save_to_file) },

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