From 5e7ed934dba350d5db22ced5d0c233c065b177e9 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Mon, 14 Nov 2011 13:33:25 +0000 Subject: [PATCH] uci: expose add_list changes in lua api (backport of ef5f4ae3252cb067db9d73afca3f5f72c72126d0 and 7289b2d69aaffa9299b47aaaa0da1e9969ace6c1) SVN-Revision: 29113 --- .../150-lua_expose_add_list_changes.patch | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 package/uci/patches/150-lua_expose_add_list_changes.patch diff --git a/package/uci/patches/150-lua_expose_add_list_changes.patch b/package/uci/patches/150-lua_expose_add_list_changes.patch new file mode 100644 index 0000000000..9cd32d3512 --- /dev/null +++ b/package/uci/patches/150-lua_expose_add_list_changes.patch @@ -0,0 +1,55 @@ +--- a/lua/uci.c ++++ b/lua/uci.c +@@ -691,6 +691,7 @@ uci_lua_add_change(lua_State *L, struct + { + struct uci_history *h; + const char *name; ++ const char *value; + + h = uci_to_history(e); + if (!h->section) +@@ -704,12 +705,38 @@ uci_lua_add_change(lua_State *L, struct + lua_setfield(L, -3, h->section); + } + +- name = (h->e.name ? h->e.name : ".type"); +- if (h->value) +- lua_pushstring(L, h->value); +- else +- lua_pushstring(L, ""); +- lua_setfield(L, -2, name); ++ name = h->e.name; ++ value = h->value ? h->value : ""; ++ ++ if (name) { ++ lua_getfield(L, -1, name); ++ ++ /* there seems to be no value yet */ ++ if (lua_isnil(L, -1)) { ++ /* this delta is a list add operation, initialize table */ ++ if (h->cmd == UCI_CMD_LIST_ADD) { ++ lua_newtable(L); ++ lua_pushstring(L, value); ++ lua_rawseti(L, -2, 1); ++ lua_setfield(L, -3, name); ++ } else { ++ lua_pushstring(L, value); ++ lua_setfield(L, -3, name); ++ } ++ ++ /* a table is on the top of the stack so this is a subsequent, ++ * list_add, append this value to table */ ++ } else if (lua_istable(L, -1)) { ++ lua_pushstring(L, value); ++ lua_rawseti(L, -2, lua_objlen(L, -2) + 1); ++ } ++ ++ lua_pop(L, 1); ++ } else { ++ lua_pushstring(L, value); ++ lua_setfield(L, -2, ".type"); ++ } ++ + lua_pop(L, 1); + } + -- 2.30.2