add get functions for savedir and confdir
[project/uci.git] / lua / uci.c
index e833b86..3f8f3a5 100644 (file)
--- a/lua/uci.c
+++ b/lua/uci.c
@@ -175,6 +175,8 @@ static void uci_push_section(lua_State *L, struct uci_section *s)
        struct uci_element *e;
 
        lua_newtable(L);
+       lua_pushboolean(L, s->anonymous);
+       lua_setfield(L, -2, ".anonymous");
        lua_pushstring(L, s->type);
        lua_setfield(L, -2, ".type");
        lua_pushstring(L, s->e.name);
@@ -294,6 +296,10 @@ uci_lua_get_any(lua_State *L, bool all)
                err = UCI_ERR_INVAL;
                goto error;
        }
+       if (!(ptr.flags & UCI_LOOKUP_COMPLETE)) {
+               err = UCI_ERR_NOTFOUND;
+               goto error;
+       }
 
        err = UCI_OK;
        e = ptr.last;
@@ -434,7 +440,7 @@ uci_lua_set(lua_State *L)
        if (err)
                goto error;
 
-       if ((ptr.s == NULL) || (ptr.value == NULL)) {
+       if (((ptr.s == NULL) && (ptr.option != NULL)) || (ptr.value == NULL)) {
                err = UCI_ERR_INVAL;
                goto error;
        }
@@ -626,6 +632,13 @@ done:
 }
 
 static int
+uci_lua_get_confdir(lua_State *L)
+{
+       lua_pushstring(L, ctx->confdir);
+       return 1;
+}
+
+static int
 uci_lua_set_confdir(lua_State *L)
 {
        int ret;
@@ -637,6 +650,13 @@ uci_lua_set_confdir(lua_State *L)
 }
 
 static int
+uci_lua_get_savedir(lua_State *L)
+{
+       lua_pushstring(L, ctx->savedir);
+       return 1;
+}
+
+static int
 uci_lua_set_savedir(lua_State *L)
 {
        int ret;
@@ -661,7 +681,9 @@ static const luaL_Reg uci[] = {
        { "revert", uci_lua_revert },
        { "changes", uci_lua_changes },
        { "foreach", uci_lua_foreach },
+       { "get_confdir", uci_lua_get_confdir },
        { "set_confdir", uci_lua_set_confdir },
+       { "get_savedir", uci_lua_get_savedir },
        { "set_savedir", uci_lua_set_savedir },
        { NULL, NULL },
 };