From: Felix Fietkau Date: Mon, 18 Aug 2008 15:11:00 +0000 (+0200) Subject: add list support to the uci lua binding X-Git-Url: http://pilppa.com/gitweb/?a=commitdiff_plain;h=5a275e5558a70a2f3b0e88dd66117acf8cdf61f6;p=uci.git add list support to the uci lua binding --- diff --git a/lua/uci.c b/lua/uci.c index 1535f56..b3be0c9 100644 --- a/lua/uci.c +++ b/lua/uci.c @@ -88,6 +88,29 @@ done: lua_pop(L, 2); } +static void uci_push_option(lua_State *L, struct uci_option *o) +{ + struct uci_element *e; + int i = 0; + + switch(o->type) { + case UCI_TYPE_STRING: + lua_pushstring(L, o->v.string); + break; + case UCI_TYPE_LIST: + lua_newtable(L); + uci_foreach_element(&o->v.list, e) { + i++; + lua_pushstring(L, e->name); + lua_rawseti(L, -2, i); + } + break; + default: + lua_pushnil(L); + break; + } +} + static void uci_push_section(lua_State *L, struct uci_section *s) { struct uci_element *e; @@ -100,15 +123,8 @@ static void uci_push_section(lua_State *L, struct uci_section *s) uci_foreach_element(&s->options, e) { struct uci_option *o = uci_to_option(e); - switch(o->type) { - case UCI_TYPE_STRING: - lua_pushstring(L, o->v.string); - lua_setfield(L, -2, o->e.name); - break; - default: - /* nothing to do yet */ - break; - } + uci_push_option(L, o); + lua_setfield(L, -2, o->e.name); } } @@ -263,14 +279,7 @@ uci_lua_get_any(lua_State *L, bool all) break; case UCI_TYPE_OPTION: o = uci_to_option(e); - switch(o->type) { - case UCI_TYPE_STRING: - lua_pushstring(L, o->v.string); - break; - default: - /* nothing to do yet */ - break; - } + uci_push_option(L, o); break; default: err = UCI_ERR_INVAL;