From: Felix Fietkau Date: Sun, 18 Jan 2009 02:03:32 +0000 (+0100) Subject: add uci.rename() X-Git-Url: http://pilppa.com/gitweb/?a=commitdiff_plain;h=9d0c6014304f1dd2f1f7a57e2039520b0f330250;p=uci.git add uci.rename() --- diff --git a/lua/uci.c b/lua/uci.c index bdac3f6..67e9418 100644 --- a/lua/uci.c +++ b/lua/uci.c @@ -425,6 +425,56 @@ error: return uci_push_status(L, ctx, false); } +static int +uci_lua_rename(lua_State *L) +{ + struct uci_context *ctx; + struct uci_ptr ptr; + int err = UCI_ERR_MEM; + char *s = NULL; + int nargs, offset = 0; + + ctx = find_context(L, &offset); + nargs = lua_gettop(L); + if (lookup_args(L, ctx, offset, &ptr, &s)) + goto error; + + switch(nargs - offset) { + case 1: + /* Format: uci.set("p.s.o=v") or uci.set("p.s=v") */ + break; + case 4: + /* Format: uci.set("p", "s", "o", "v") */ + ptr.value = luaL_checkstring(L, nargs); + break; + case 3: + /* Format: uci.set("p", "s", "v") */ + ptr.value = ptr.option; + ptr.option = NULL; + break; + default: + err = UCI_ERR_INVAL; + goto error; + } + + err = uci_lookup_ptr(ctx, &ptr, NULL, false); + if (err) + goto error; + + if (((ptr.s == NULL) && (ptr.option != NULL)) || (ptr.value == NULL)) { + err = UCI_ERR_INVAL; + goto error; + } + + err = uci_rename(ctx, &ptr); + if (err) + goto error; + +error: + return uci_push_status(L, ctx, false); +} + + static int uci_lua_set(lua_State *L) { @@ -762,6 +812,7 @@ static const luaL_Reg uci[] = { { "get_all", uci_lua_get_all }, { "add", uci_lua_add }, { "set", uci_lua_set }, + { "rename", uci_lua_rename }, { "save", uci_lua_save }, { "delete", uci_lua_delete }, { "commit", uci_lua_commit },