summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2010-10-28 17:26:48 +0000
committerJo-Philipp Wich <jow@openwrt.org>2010-10-28 17:26:48 +0000
commit21de97b23523aa365c929ce72a0fbeee7ba7b333 (patch)
tree8cc1f39c8fe1743d173d3db0274c84025794c617
parent28b5b2b6378ef683b1aa5d6e033d7fae2b184df5 (diff)
libs/core: implement substate() in uci model for creating bound state cursors
-rw-r--r--libs/core/luasrc/model/uci.lua26
1 files changed, 26 insertions, 0 deletions
diff --git a/libs/core/luasrc/model/uci.lua b/libs/core/luasrc/model/uci.lua
index 66bd0a026..46b0db8d8 100644
--- a/libs/core/luasrc/model/uci.lua
+++ b/libs/core/luasrc/model/uci.lua
@@ -227,6 +227,32 @@ function Cursor._affected(self, configlist)
return reloadlist
end
+--- Create a sub-state of this cursor. The sub-state is tied to the parent
+-- curser, means it the parent unloads or loads configs, the sub state will
+-- do so as well.
+-- @return UCI state cursor tied to the parent cursor
+function Cursor.substate(self)
+ Cursor._substates = Cursor._substates or { }
+ Cursor._substates[self] = Cursor._substates[self] or cursor_state()
+ return Cursor._substates[self]
+end
+
+local _load = Cursor.load
+function Cursor.load(self, ...)
+ if Cursor._substates and Cursor._substates[self] then
+ _load(Cursor._substates[self], ...)
+ end
+ return _load(self, ...)
+end
+
+local _unload = Cursor.unload
+function Cursor.unload(self, ...)
+ if Cursor._substates and Cursor._substates[self] then
+ _unload(Cursor._substates[self], ...)
+ end
+ return _unload(self, ...)
+end
+
--- Add an anonymous section.
-- @class function