projects
/
project
/
uci.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
28d2cc2
)
lua: allow uci.set() to create/update a list value
author
Felix Fietkau
<nbd@openwrt.org>
Tue, 19 Aug 2008 20:22:18 +0000
(22:22 +0200)
committer
Felix Fietkau
<nbd@openwrt.org>
Tue, 19 Aug 2008 20:22:18 +0000
(22:22 +0200)
lua/uci.c
patch
|
blob
|
history
diff --git
a/lua/uci.c
b/lua/uci.c
index
b3be0c9
..
1c67742
100644
(file)
--- a/
lua/uci.c
+++ b/
lua/uci.c
@@
-401,7
+401,8
@@
uci_lua_set(lua_State *L)
const char *value = NULL;
const char *s;
int err = UCI_ERR_MEM;
const char *value = NULL;
const char *s;
int err = UCI_ERR_MEM;
- int nargs;
+ int i, nargs;
+ bool istable = false;
nargs = lua_gettop(L);
nargs = lua_gettop(L);
@@
-424,7
+425,16
@@
uci_lua_set(lua_State *L)
/* Format: uci.set("p", "s", "v") */
package = s;
section = luaL_checkstring(L, 2);
/* Format: uci.set("p", "s", "v") */
package = s;
section = luaL_checkstring(L, 2);
- value = luaL_checkstring(L, nargs);
+ if (lua_istable(L, nargs)) {
+ if (lua_objlen(L, nargs) < 1)
+ luaL_error(L, "Cannot set an uci option to an empty table value");
+ lua_rawgeti(L, nargs, 1);
+ value = luaL_checkstring(L, -1);
+ lua_pop(L, 1);
+ istable = true;
+ } else {
+ value = luaL_checkstring(L, nargs);
+ }
break;
default:
err = UCI_ERR_INVAL;
break;
default:
err = UCI_ERR_INVAL;
@@
-442,6
+452,16
@@
uci_lua_set(lua_State *L)
goto error;
}
err = uci_set(ctx, p, section, option, value, NULL);
goto error;
}
err = uci_set(ctx, p, section, option, value, NULL);
+ if (istable) {
+ for (i = 2; i <= lua_objlen(L, nargs); i++) {
+ lua_rawgeti(L, nargs, i);
+ value = luaL_checkstring(L, -1);
+ err = uci_add_list(ctx, p, section, option, value, NULL);
+ lua_pop(L, 1);
+ if (err)
+ goto error;
+ }
+ }
error:
if (err)
error:
if (err)