2 LuCI utility functions.
7 Create a Class object (Python-style object model).
9 The class object can be instantiated by calling itself.
10 Any class functions or shared parameters can be attached to this object.
11 Attaching a table to the class object makes this table shared between
12 all instances of this class. For object parameters use the __init__ function.
13 Classes can inherit member functions and values from a base class.
14 Class can be instantiated by calling them. All parameters will be passed
15 to the __init__ function of this class - if such a function exists.
16 The __init__ function must be used to set any object parameters that are not shared
17 with other objects of this class. Any return values will be ignored.
21 @param base The base class to inherit from (optional)
22 @return A class object
28 Test whether the given object is an instance of the given class.
32 @param object Object instance
33 @param class Class object to test against
34 @return Boolean indicating whether the object is an instance
40 Create a new or get an already existing thread local store associated with
41 the current active coroutine.
43 A thread local store is private a table object
44 whose values can't be accessed from outside of the running coroutine.
48 @return Table value representing the corresponding thread local store
52 Write given object to stderr.
56 @param obj Value to write to stderr
57 @return Boolean indicating whether the write operation was successful
61 Recursively dumps a table to stdout, useful for testing and debugging.
65 @param t Table value to dump
66 @param maxdepth Maximum depth
71 Create valid XML PCDATA from given string.
73 This is just a compatibility wrapper for luci.xml.padata()
77 @param value String value containing the data to escape
78 @return String value containing the escaped data
83 Decode an URL-encoded string - optionally decoding the "+" sign to space.
87 @param str Input string in x-www-urlencoded format
88 @param decode_plus Decode "+" signs to spaces if true (optional)
89 @return The decoded string
94 URL-encode given string.
98 @param str String to encode
99 @return String containing the encoded data
104 Strip HTML tags from given string.
106 This is just a compatibility wrapper for luci.xml.striptags()
110 @param value String containing the HTML text
111 @return String with HTML tags stripped of
112 @see luci.xml.striptags
116 Safely quote value for use in shell commands.
120 @param value String containing the value to quote
121 @return Single-quote enclosed string with embedded quotes escaped
125 Splits given string on a defined separator sequence and return a table
126 containing the resulting substrings.
128 The optional max parameter specifies the number of bytes to process,
129 regardless of the actual length of the given string. The optional last
130 parameter, regex, specifies whether the separator sequence is
131 nterpreted as regular expression.
135 @param str String value containing the data to split up
136 @param pat String with separator pattern (optional, defaults to "\n")
137 @param max Maximum times to split (optional)
138 @param regex Boolean indicating whether to interpret the separator
139 -- pattern as regular expression (optional, default is false)
140 @return Table containing the resulting substrings
144 Remove leading and trailing whitespace from given string value.
148 @param str String value containing whitespace padded data
149 @return String value with leading and trailing space removed
153 Count the occurrences of given substring in given string.
157 @param str String to search in
158 @param pattern String containing pattern to find
159 @return Number of found occurrences
163 Return a matching iterator for the given value.
165 The iterator will return one token per invocation, the tokens are separated by
166 whitespace. If the input value is a table, it is transformed into a string first.
167 A nil value will result in a valid iterator which aborts with the first invocation.
171 @param val The value to scan (table, string or nil)
172 @return Iterator which returns one token per call
176 Parse certain units from the given string and return the canonical integer
177 value or 0 if the unit is unknown.
179 Upper- or lower case is irrelevant.
180 Recognized units are:
182 -- o "y" - one year (60*60*24*366)
183 o "m" - one month (60*60*24*31)
184 o "w" - one week (60*60*24*7)
185 o "d" - one day (60*60*24)
186 o "h" - one hour (60*60)
187 o "min" - one minute (60)
188 o "kb" - one kilobyte (1024)
189 o "mb" - one megabyte (1024*1024)
190 o "gb" - one gigabyte (1024*1024*1024)
191 o "kib" - one si kilobyte (1000)
192 o "mib" - one si megabyte (1000*1000)
193 o "gib" - one si gigabyte (1000*1000*1000)
197 @param ustr String containing a numerical value with trailing unit
198 @return Number containing the canonical value
202 Appends numerically indexed tables or single objects to a given table.
206 @param src Target table
207 @param ... Objects to insert
212 Combines two or more numerically indexed tables and single objects into one table.
216 @param tbl1 Table value to combine
217 @param tbl2 Table value to combine
218 @param ... More tables to combine
219 @return Table value containing all values of given tables
223 Checks whether the given table contains the given value.
227 @param table Table value
228 @param value Value to search within the given table
229 @return Number indicating the first index at which the given value occurs
230 -- within table or false.
234 Update values in given table with the values from the second given table.
236 Both table are - in fact - merged together.
240 @param t Table which should be updated
241 @param updates Table containing the values to update
246 Retrieve all keys of given associative table.
250 @param t Table to extract keys from
251 @return Sorted table containing the keys
255 Clones the given object and return it's copy.
259 @param object Table value to clone
260 @param deep Boolean indicating whether to do recursive cloning
261 @return Cloned table value
265 Recursively serialize given data to lua code, suitable for restoring
270 @param val Value containing the data to serialize
271 @return String value containing the serialized code
277 Restore data previously serialized with serialize_data().
281 @param str String containing the data to restore
282 @return Value containing the restored data structure
288 Return the current runtime bytecode of the given data. The byte code
289 will be stripped before it is returned.
293 @param val Value to return as bytecode
294 @return String value containing the bytecode of the given data
298 Strips unnecessary lua bytecode from given string.
300 Information like line numbers and debugging numbers will be discarded.
301 Original version by Peter Cawley (http://lua-users.org/lists/lua-l/2008-02/msg01158.html)
305 @param code String value containing the original lua byte code
306 @return String value containing the stripped lua byte code
310 Return a key, value iterator which returns the values sorted according to
311 the provided callback function.
315 @param t The table to iterate
316 @param f A callback function to decide the order of elements
317 @return Function value containing the corresponding iterator
321 Return a key, value iterator for the given table.
323 The table pairs are sorted by key.
327 @param t The table to iterate
328 @return Function value containing the corresponding iterator
332 Return a key, value iterator for the given table.
334 The table pairs are sorted by value.
338 @param t The table to iterate
339 @return Function value containing the corresponding iterator
343 Test whether the current system is operating in big endian mode.
347 @return Boolean value indicating whether system is big endian
351 Execute given commandline and gather stdout.
355 @param command String containing command to execute
356 @return String containing the command's stdout
360 Return a line-buffered iterator over the output of given command.
364 @param command String containing the command to execute
373 @param object String containing the ubus object to call
374 @param method String containing the ubus method to call
375 @param values Table containing the values to pass
376 @return Table containin the ubus result
380 Convert data structure to JSON
384 @param data The data to serialize
385 @param writer A function to write a chunk of JSON data (optional)
386 @return String containing the JSON if called without write callback
390 Returns the absolute path to LuCI base directory.
394 @return String containing the directory path
398 This is a coroutine-safe drop-in replacement for Lua's "xpcall"-function
402 @param f Lua function to be called protected
403 @param err Custom error handler
404 @param ... Parameters passed to the function
405 @return A boolean whether the function call succeeded and the return
406 -- values of either the function or the error handler
410 This is a coroutine-safe drop-in replacement for Lua's "pcall"-function
414 @param f Lua function to be called protected
415 @param ... Parameters passed to the function
416 @return A boolean whether the function call succeeded and the returns
417 -- values of the function or the error object