From 3232be5d642dd8dc4e718a3c534a8e413ce0f49b Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Thu, 1 May 2008 13:38:15 +0200 Subject: [PATCH 1/1] add 2 and 3 argument versions of uci.get() --- lua/uci.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/lua/uci.c b/lua/uci.c index 397a36d..00cfc0e 100644 --- a/lua/uci.c +++ b/lua/uci.c @@ -182,19 +182,29 @@ uci_lua_get_any(lua_State *L, bool all) { struct uci_element *e = NULL; struct uci_package *p = NULL; - char *package = NULL; - char *section = NULL; - char *option = NULL; + const char *package = NULL; + const char *section = NULL; + const char *option = NULL; char *s; int err = UCI_ERR_MEM; + int n; + + n = lua_gettop(L); luaL_checkstring(L, 1); - s = strdup(lua_tostring(L, -1)); + s = strdup(lua_tostring(L, 1)); if (!s) goto error; - if ((err = uci_parse_tuple(ctx, s, &package, §ion, &option, NULL))) - goto error; + if (n > 1) { + package = luaL_checkstring(L, 1); + section = luaL_checkstring(L, 2); + if (n > 2) + option = luaL_checkstring(L, 3); + } else { + if ((err = uci_parse_tuple(ctx, s, (char **) &package, (char **) §ion, (char **) &option, NULL))) + goto error; + } if (!all && (section == NULL)) { err = UCI_ERR_INVAL; -- 2.11.0