add .anonymous attribute for uci sections in lua
[project/uci.git] / lua / uci.c
index 6e86e9a..f87ce27 100644 (file)
--- a/lua/uci.c
+++ b/lua/uci.c
@@ -105,7 +105,7 @@ done:
 static int
 lookup_args(lua_State *L, struct uci_ptr *ptr, char **buf)
 {
-       char *s;
+       char *s = NULL;
        int n;
 
        n = lua_gettop(L);
@@ -119,6 +119,7 @@ lookup_args(lua_State *L, struct uci_ptr *ptr, char **buf)
                goto error;
 
        switch (n) {
+       case 4:
        case 3:
                ptr->option = luaL_checkstring(L, 3);
                /* fall through */
@@ -133,6 +134,7 @@ lookup_args(lua_State *L, struct uci_ptr *ptr, char **buf)
                        goto error;
                break;
        default:
+               luaL_error(L, "invalid argument count");
                goto error;
        }
 
@@ -173,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);
@@ -281,7 +285,7 @@ uci_lua_get_any(lua_State *L, bool all)
 {
        struct uci_element *e = NULL;
        struct uci_ptr ptr;
-       char *s;
+       char *s = NULL;
        int err = UCI_ERR_NOTFOUND;
 
        if (lookup_args(L, &ptr, &s))