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.
75 @param value String value containing the data to escape
76 @return String value containing the escaped data
80 Decode an URL-encoded string - optionally decoding the "+" sign to space.
84 @param str Input string in x-www-urlencoded format
85 @param decode_plus Decode "+" signs to spaces if true (optional)
86 @return The decoded string
91 URL-encode given string.
95 @param str String to encode
96 @return String containing the encoded data
101 Strip HTML tags from given string.
105 @param value String containing the HTML text
106 @return String with HTML tags stripped of
110 Safely quote value for use in shell commands.
114 @param value String containing the value to quote
115 @return Single-quote enclosed string with embedded quotes escaped
119 Splits given string on a defined separator sequence and return a table
120 containing the resulting substrings.
122 The optional max parameter specifies the number of bytes to process,
123 regardless of the actual length of the given string. The optional last
124 parameter, regex, specifies whether the separator sequence is
125 nterpreted as regular expression.
129 @param str String value containing the data to split up
130 @param pat String with separator pattern (optional, defaults to "\n")
131 @param max Maximum times to split (optional)
132 @param regex Boolean indicating whether to interpret the separator
133 -- pattern as regular expression (optional, default is false)
134 @return Table containing the resulting substrings
138 Remove leading and trailing whitespace from given string value.
142 @param str String value containing whitespace padded data
143 @return String value with leading and trailing space removed
147 Count the occurrences of given substring in given string.
151 @param str String to search in
152 @param pattern String containing pattern to find
153 @return Number of found occurrences
157 Return a matching iterator for the given value.
159 The iterator will return one token per invocation, the tokens are separated by
160 whitespace. If the input value is a table, it is transformed into a string first.
161 A nil value will result in a valid interator which aborts with the first invocation.
165 @param val The value to scan (table, string or nil)
166 @return Iterator which returns one token per call
170 Parse certain units from the given string and return the canonical integer
171 value or 0 if the unit is unknown.
173 Upper- or lower case is irrelevant.
174 Recognized units are:
176 -- o "y" - one year (60*60*24*366)
177 o "m" - one month (60*60*24*31)
178 o "w" - one week (60*60*24*7)
179 o "d" - one day (60*60*24)
180 o "h" - one hour (60*60)
181 o "min" - one minute (60)
182 o "kb" - one kilobyte (1024)
183 o "mb" - one megabyte (1024*1024)
184 o "gb" - one gigabyte (1024*1024*1024)
185 o "kib" - one si kilobyte (1000)
186 o "mib" - one si megabyte (1000*1000)
187 o "gib" - one si gigabyte (1000*1000*1000)
191 @param ustr String containing a numerical value with trailing unit
192 @return Number containing the canonical value
196 Appends numerically indexed tables or single objects to a given table.
200 @param src Target table
201 @param ... Objects to insert
206 Combines two or more numerically indexed tables and single objects into one table.
210 @param tbl1 Table value to combine
211 @param tbl2 Table value to combine
212 @param ... More tables to combine
213 @return Table value containing all values of given tables
217 Checks whether the given table contains the given value.
221 @param table Table value
222 @param value Value to search within the given table
223 @return Number indicating the first index at which the given value occurs
224 -- within table or false.
228 Update values in given table with the values from the second given table.
230 Both table are - in fact - merged together.
234 @param t Table which should be updated
235 @param updates Table containing the values to update
240 Retrieve all keys of given associative table.
244 @param t Table to extract keys from
245 @return Sorted table containing the keys
249 Clones the given object and return it's copy.
253 @param object Table value to clone
254 @param deep Boolean indicating whether to do recursive cloning
255 @return Cloned table value
259 Create a dynamic table which automatically creates subtables.
263 @return Dynamic Table
267 Recursively serialize given data to lua code, suitable for restoring
272 @param val Value containing the data to serialize
273 @return String value containing the serialized code
279 Restore data previously serialized with serialize_data().
283 @param str String containing the data to restore
284 @return Value containing the restored data structure
290 Return the current runtime bytecode of the given data. The byte code
291 will be stripped before it is returned.
295 @param val Value to return as bytecode
296 @return String value containing the bytecode of the given data
300 Strips unnescessary lua bytecode from given string.
302 Information like line numbers and debugging numbers will be discarded.
303 Original version by Peter Cawley (http://lua-users.org/lists/lua-l/2008-02/msg01158.html)
307 @param code String value containing the original lua byte code
308 @return String value containing the stripped lua byte code
312 Return a key, value iterator which returns the values sorted according to
313 the provided callback function.
317 @param t The table to iterate
318 @param f A callback function to decide the order of elements
319 @return Function value containing the corresponding iterator
323 Return a key, value iterator for the given table.
325 The table pairs are sorted by key.
329 @param t The table to iterate
330 @return Function value containing the corresponding iterator
334 Return a key, value iterator for the given table.
336 The table pairs are sorted by value.
340 @param t The table to iterate
341 @return Function value containing the corresponding iterator
345 Test whether the current system is operating in big endian mode.
349 @return Boolean value indicating whether system is big endian
353 Execute given commandline and gather stdout.
357 @param command String containing command to execute
358 @return String containing the command's stdout
362 Return a line-buffered iterator over the output of given command.
366 @param command String containing the command to execute
375 @param object String containing the ubus object to call
376 @param method String containing the ubus method to call
377 @param values Table containing the values to pass
378 @return Table containin the ubus result
382 Convert data structure to JSON
386 @param data The data to serialize
387 @param writer A function to write a chunk of JSON data (optional)
388 @return String containing the JSON if called without write callback
392 Returns the absolute path to LuCI base directory.
396 @return String containing the directory path
400 This is a coroutine-safe drop-in replacement for Lua's "xpcall"-function
404 @param f Lua function to be called protected
405 @param err Custom error handler
406 @param ... Parameters passed to the function
407 @return A boolean whether the function call succeeded and the return
408 -- values of either the function or the error handler
412 This is a coroutine-safe drop-in replacement for Lua's "pcall"-function
416 @param f Lua function to be called protected
417 @param ... Parameters passed to the function
418 @return A boolean whether the function call succeeded and the returns
419 -- values of the function or the error object