summaryrefslogtreecommitdiffhomepage
path: root/libs
diff options
context:
space:
mode:
Diffstat (limited to 'libs')
-rw-r--r--libs/core/luasrc/util.lua20
-rw-r--r--libs/sys/luasrc/sys.lua6
2 files changed, 26 insertions, 0 deletions
diff --git a/libs/core/luasrc/util.lua b/libs/core/luasrc/util.lua
index 109ccab286..ea1fccbc1c 100644
--- a/libs/core/luasrc/util.lua
+++ b/libs/core/luasrc/util.lua
@@ -261,6 +261,16 @@ function trim(str)
return (str:gsub("^%s*(.-)%s*$", "%1"))
end
+--- Count the occurences of given substring in given string.
+-- @param str String to search in
+-- @param pattern String containing pattern to find
+-- @return Number of found occurences
+function cmatch(str, pat)
+ local count = 0
+ for _ in str:gmatch(pat) do count = count + 1 end
+ return count
+end
+
--- Parse certain units from the given string and return the canonical integer
-- value or 0 if the unit is unknown. Upper- or lower case is irrelevant.
-- Recognized units are:
@@ -320,6 +330,16 @@ function parse_units(ustr)
return val
end
+-- also register functions above in the central string class for convenience
+string.escape = escape
+string.pcdata = pcdata
+string.striptags = striptags
+string.split = split
+string.trim = trim
+string.cmatch = cmatch
+string.parse_units = parse_units
+
+
--- Appends numerically indexed tables or single objects to a given table.
-- @param src Target table
-- @param ... Objects to insert
diff --git a/libs/sys/luasrc/sys.lua b/libs/sys/luasrc/sys.lua
index 413aa4c11f..52ed0c36d9 100644
--- a/libs/sys/luasrc/sys.lua
+++ b/libs/sys/luasrc/sys.lua
@@ -204,6 +204,12 @@ function syslog()
return luci.util.exec("logread")
end
+--- Retrieves the output of the "dmesg" command.
+-- @return String containing the current log buffer
+function dmesg()
+ return luci.util.exec("dmesg")
+end
+
--- Generates a random id with specified length.
-- @param bytes Number of bytes for the unique id
-- @return String containing hex encoded id