+--- Get the given option from the first section with the given type.
+-- @param config UCI config
+-- @param type UCI section type
+-- @param option UCI option (optional)
+-- @param default Default value (optional)
+-- @return UCI value
+function Cursor.get_first(self, conf, stype, opt, def)
+ local rv = def
+
+ self:foreach(conf, stype,
+ function(s)
+ local val = not opt and s['.name'] or s[opt]
+
+ if type(def) == "number" then
+ val = tonumber(val)
+ elseif type(def) == "boolean" then
+ val = (val == "1" or val == "true" or val == "enabled")
+ end
+
+ if val ~= nil then
+ rv = val
+ return false
+ end
+ end)
+
+ return rv
+end
+