summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2017-12-31 11:30:32 +0100
committerJo-Philipp Wich <jo@mein.io>2018-01-01 16:55:25 +0100
commit141b64ef84f43c954e665865b1bbf216fbf7c05f (patch)
tree5206336f87c9a45369b339ec3e76ba38cd695066
parent1e17f24644663c3f875c4248c135667f287900d8 (diff)
downloaduci-lede-17.01.tar.gz
lua: additionally return name when looking up sectionslede-17.01
Return the resolved name in addition to the type when looking up sections through `get()` - for example a `cursor:get("firewall", "@rule[0]")` will now return two values in the form ("rule", "cfg0a92bd") instead of only the type name. This is mainly useful to resolve extended section names without having to reimplement the section count logic in Lua code. Signed-off-by: Jo-Philipp Wich <jo@mein.io> (cherry picked from commit 5beb95da3dbec6db11a6bdfaab7807ee2daf41e6)
-rw-r--r--lua/uci.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/lua/uci.c b/lua/uci.c
index 54892b1..f2a5549 100644
--- a/lua/uci.c
+++ b/lua/uci.c
@@ -375,6 +375,7 @@ uci_lua_get_any(lua_State *L, bool all)
struct uci_element *e = NULL;
struct uci_ptr ptr;
int offset = 0;
+ int nret = 1;
char *s = NULL;
int err = UCI_ERR_NOTFOUND;
@@ -400,10 +401,14 @@ uci_lua_get_any(lua_State *L, bool all)
uci_push_package(L, ptr.p);
break;
case UCI_TYPE_SECTION:
- if (all)
+ if (all) {
uci_push_section(L, ptr.s, -1);
- else
+ }
+ else {
lua_pushstring(L, ptr.s->type);
+ lua_pushstring(L, ptr.s->e.name);
+ nret++;
+ }
break;
case UCI_TYPE_OPTION:
uci_push_option(L, ptr.o);
@@ -415,7 +420,7 @@ uci_lua_get_any(lua_State *L, bool all)
if (s)
free(s);
if (!err)
- return 1;
+ return nret;
error:
if (s)