diff options
author | Steven Barth <steven@midlink.org> | 2008-06-06 20:45:33 +0000 |
---|---|---|
committer | Steven Barth <steven@midlink.org> | 2008-06-06 20:45:33 +0000 |
commit | cd0fb5e44e5cb538d93024d02a14a02c00752641 (patch) | |
tree | d6188cf6d6c9ee67b4a12261c3faee545cd446aa /libs/uci | |
parent | 8644ff1eab93d067e316eee9f4b567e1bf07ccb3 (diff) |
* Removed High-Level UCI-API due to Lua compiler bugs
Diffstat (limited to 'libs/uci')
-rw-r--r-- | libs/uci/luasrc/model/uci.lua | 102 |
1 files changed, 31 insertions, 71 deletions
diff --git a/libs/uci/luasrc/model/uci.lua b/libs/uci/luasrc/model/uci.lua index 59a9a2c27..bf7ac9315 100644 --- a/libs/uci/luasrc/model/uci.lua +++ b/libs/uci/luasrc/model/uci.lua @@ -25,92 +25,52 @@ limitations under the License. ]]-- local uci = require("uci") local util = require("luci.util") -local setmetatable = setmetatable -local rawget = rawget -local rawset = rawset -local error = error -local tostring = tostring +local setmetatable, rawget, rawset = setmetatable, rawget, rawset +local error, pairs, ipairs, tostring = error, pairs, ipairs, tostring module("luci.model.uci", function(m) setmetatable(m, {__index = uci}) end) -local configs_mt = {} -local sections_mt = {} -local options_mt = {} - savedir_default = "/tmp/.uci" confdir_default = "/etc/config" savedir_state = "/var/state" -config = {} -setmetatable(config, configs_mt) - --- Level 1 (configs) -function configs_mt.__index(self, key) - local node = rawget(self, key) - if not node then - if not uci.load(key) then - return nil - end - node = {} - node[".name"] = key - setmetatable(node, sections_mt) - rawset(self, key, node) +function delete_all(config, type, comparator) + local del = {} + + foreach(config, type, + function (section) + if not comparator or comparator(section) then + table.insert(del, section[".name"]) + end + end) + + for i, j in ipairs(del) do + uci.delete("config", j) end - return node -end -function configs_mt.__newindex() - error("invalid operation") end - --- Level 2 (sections) -function sections_mt.__index(self, key) - local node = rawget(self, key) - if not node then - node = {} - node[".conf"] = self[".name"] - node[".name"] = key - node[".type"] = uci.get(self[".name"], key) - setmetatable(node, options_mt) - rawset(self, key, node) - end - return node -end -function sections_mt.__newindex(self, key, value) - if not value then - if uci.delete(self[".name"], key) then - rawset(self, key, nil) - else - error("unable to delete section") - end - elseif key == "" then - key = uci.add(self[".name"], tostring(value)) - if key then - rawset(self, "", self[key]) - else - error("unable to create section") - end +function section(config, type, name, values) + local stat = true + if name then + stat = set(config, name, type) else - if not uci.set(self[".name"], key, value) then - error("unable to create section") - end + name = add(config, type) + stat = name and true end + + if stat and values then + stat = tset(config, name, values) + end + + return stat and name end - --- Level 3 (options) -function options_mt.__index(self, key) - return uci.get(self[".conf"], self[".name"], key) -end -function options_mt.__newindex(self, key, value) - if not value then - if not uci.delete(self[".conf"], self[".name"], key) then - error("unable to delete option") - end - else - if not uci.set(self[".conf"], self[".name"], key, tostring(value)) then - error("unable to write option") +function tset(config, section, values) + local stat = true + for k, v in pairs(values) do + if k:sub(1, 1) ~= "." then + stat = stat and set(config, section, k, v) end end end |