add get functions for savedir and confdir
[project/uci.git] / lua / uci.c
index f87ce27..3f8f3a5 100644 (file)
--- a/lua/uci.c
+++ b/lua/uci.c
@@ -296,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;
@@ -436,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;
        }
@@ -628,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;
@@ -639,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;
@@ -663,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 },
 };