From: Dirk Feytons Date: Thu, 29 Sep 2016 15:39:56 +0000 (+0200) Subject: uci/lua: add list_configs() function X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=7daf94275cce4c9dd74fe4eb846b0f4d40486f1d;p=oweals%2Fuci.git uci/lua: add list_configs() function Returns an array with all the available configs. Signed-off-by: Dirk Feytons --- diff --git a/lua/uci.c b/lua/uci.c index 47d59c8..ddb9c5c 100644 --- a/lua/uci.c +++ b/lua/uci.c @@ -910,6 +910,26 @@ uci_lua_set_savedir(lua_State *L) return uci_push_status(L, ctx, false); } +static int +uci_lua_list_configs(lua_State *L) +{ + struct uci_context *ctx; + char **configs = NULL; + char **ptr; + int i = 1; + + ctx = find_context(L, NULL); + if ((uci_list_configs(ctx, &configs) != UCI_OK) || !configs) + return uci_push_status(L, ctx, false); + lua_newtable(L); + for (ptr = configs; *ptr; ptr++) { + lua_pushstring(L, *ptr); + lua_rawseti(L, -2, i++); + } + free(configs); + return 1; +} + static int uci_lua_gc(lua_State *L) { @@ -971,6 +991,7 @@ static const luaL_Reg uci[] = { { "set_confdir", uci_lua_set_confdir }, { "get_savedir", uci_lua_get_savedir }, { "set_savedir", uci_lua_set_savedir }, + { "list_configs", uci_lua_list_configs }, { NULL, NULL }, };