1 <!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Strict//EN"
2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
5 <title>Reference
</title>
6 <link rel=
"stylesheet" href=
"../luadoc.css" type=
"text/css" />
7 <!--meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/-->
14 <div id=
"product_logo"></div>
15 <div id=
"product_name"><big><b></b></big></div>
16 <div id=
"product_description"></div>
17 </div> <!-- id="product" -->
27 <li><a href=
"../index.html">Index
</a></li>
38 <a href=
"../modules/luci.dispatcher.html">luci.dispatcher
</a>
42 <a href=
"../modules/luci.http.html">luci.http
</a>
46 <a href=
"../modules/luci.http.conditionals.html">luci.http.conditionals
</a>
50 <a href=
"../modules/luci.http.date.html">luci.http.date
</a>
54 <a href=
"../modules/luci.http.mime.html">luci.http.mime
</a>
58 <a href=
"../modules/luci.i18n.html">luci.i18n
</a>
62 <a href=
"../modules/luci.ip.html">luci.ip
</a>
66 <a href=
"../modules/luci.ip.cidr.html">luci.ip.cidr
</a>
70 <a href=
"../modules/luci.json.html">luci.json
</a>
74 <a href=
"../modules/luci.jsonc.html">luci.jsonc
</a>
78 <a href=
"../modules/luci.jsonc.parser.html">luci.jsonc.parser
</a>
82 <a href=
"../modules/luci.model.ipkg.html">luci.model.ipkg
</a>
86 <a href=
"../modules/luci.model.uci.html">luci.model.uci
</a>
90 <a href=
"../modules/luci.rpcc.html">luci.rpcc
</a>
94 <a href=
"../modules/luci.rpcc.ruci.html">luci.rpcc.ruci
</a>
98 <a href=
"../modules/luci.sys.html">luci.sys
</a>
102 <a href=
"../modules/luci.sys.init.html">luci.sys.init
</a>
106 <a href=
"../modules/luci.sys.iptparser.html">luci.sys.iptparser
</a>
110 <a href=
"../modules/luci.sys.net.html">luci.sys.net
</a>
114 <a href=
"../modules/luci.sys.process.html">luci.sys.process
</a>
118 <a href=
"../modules/luci.sys.user.html">luci.sys.user
</a>
122 <a href=
"../modules/luci.sys.wifi.html">luci.sys.wifi
</a>
125 <li><strong>luci.util
</strong></li>
128 <a href=
"../modules/luci.xml.html">luci.xml
</a>
132 <a href=
"../modules/nixio.html">nixio
</a>
136 <a href=
"../modules/nixio.CHANGELOG.html">nixio.CHANGELOG
</a>
140 <a href=
"../modules/nixio.CryptoHash.html">nixio.CryptoHash
</a>
144 <a href=
"../modules/nixio.File.html">nixio.File
</a>
148 <a href=
"../modules/nixio.README.html">nixio.README
</a>
152 <a href=
"../modules/nixio.Socket.html">nixio.Socket
</a>
156 <a href=
"../modules/nixio.TLSContext.html">nixio.TLSContext
</a>
160 <a href=
"../modules/nixio.TLSSocket.html">nixio.TLSSocket
</a>
164 <a href=
"../modules/nixio.UnifiedIO.html">nixio.UnifiedIO
</a>
168 <a href=
"../modules/nixio.bin.html">nixio.bin
</a>
172 <a href=
"../modules/nixio.bit.html">nixio.bit
</a>
176 <a href=
"../modules/nixio.crypto.html">nixio.crypto
</a>
180 <a href=
"../modules/nixio.fs.html">nixio.fs
</a>
195 </div><!-- id="navigation" -->
199 <h1>Class
<code>luci.util
</code></h1>
210 <table class=
"function_list">
213 <td class=
"name" nowrap
><a href=
"#append">append
</a> (src, ...)
</td>
216 Appends numerically indexed tables or single objects to a given table.
</td>
220 <td class=
"name" nowrap
><a href=
"#bigendian">bigendian
</a> ()
</td>
223 Test whether the current system is operating in big endian mode.
</td>
227 <td class=
"name" nowrap
><a href=
"#class">class
</a> (base)
</td>
230 Create a Class object (Python-style object model).
</td>
234 <td class=
"name" nowrap
><a href=
"#clone">clone
</a> (object, deep)
</td>
237 Clones the given object and return it's copy.
</td>
241 <td class=
"name" nowrap
><a href=
"#cmatch">cmatch
</a> (str, pattern)
</td>
244 Count the occurrences of given substring in given string.
</td>
248 <td class=
"name" nowrap
><a href=
"#combine">combine
</a> (tbl1, tbl2, ...)
</td>
251 Combines two or more numerically indexed tables and single objects into one table.
</td>
255 <td class=
"name" nowrap
><a href=
"#contains">contains
</a> (table, value)
</td>
258 Checks whether the given table contains the given value.
</td>
262 <td class=
"name" nowrap
><a href=
"#copcall">copcall
</a> (f, ...)
</td>
265 This is a coroutine-safe drop-in replacement for Lua's
"pcall"-function
270 <td class=
"name" nowrap
><a href=
"#coxpcall">coxpcall
</a> (f, err, ...)
</td>
273 This is a coroutine-safe drop-in replacement for Lua's
"xpcall"-function
278 <td class=
"name" nowrap
><a href=
"#dumptable">dumptable
</a> (t, maxdepth)
</td>
281 Recursively dumps a table to stdout, useful for testing and debugging.
</td>
285 <td class=
"name" nowrap
><a href=
"#exec">exec
</a> (command)
</td>
288 Execute given commandline and gather stdout.
</td>
292 <td class=
"name" nowrap
><a href=
"#execi">execi
</a> (command)
</td>
295 Return a line-buffered iterator over the output of given command.
</td>
299 <td class=
"name" nowrap
><a href=
"#get_bytecode">get_bytecode
</a> (val)
</td>
302 Return the current runtime bytecode of the given data.
</td>
306 <td class=
"name" nowrap
><a href=
"#imatch">imatch
</a> (val)
</td>
309 Return a matching iterator for the given value.
</td>
313 <td class=
"name" nowrap
><a href=
"#instanceof">instanceof
</a> (object, class)
</td>
316 Test whether the given object is an instance of the given class.
</td>
320 <td class=
"name" nowrap
><a href=
"#keys">keys
</a> (t)
</td>
323 Retrieve all keys of given associative table.
</td>
327 <td class=
"name" nowrap
><a href=
"#kspairs">kspairs
</a> (t)
</td>
330 Return a key, value iterator for the given table.
</td>
334 <td class=
"name" nowrap
><a href=
"#libpath">libpath
</a> ()
</td>
337 Returns the absolute path to LuCI base directory.
</td>
341 <td class=
"name" nowrap
><a href=
"#parse_units">parse_units
</a> (ustr)
</td>
344 Parse certain units from the given string and return the canonical integer
345 value or
0 if the unit is unknown.
</td>
349 <td class=
"name" nowrap
><a href=
"luci.xml.html#pcdata">pcdata
</a> (value)
</td>
352 Create valid XML PCDATA from given string.
353 This is a wrapper for
<a href=
"luci.xml.html#pcdata">luci.xml.pcdata()
</a>.
</td>
357 <td class=
"name" nowrap
><a href=
"#perror">perror
</a> (obj)
</td>
360 Write given object to stderr.
</td>
364 <td class=
"name" nowrap
><a href=
"#restore_data">restore_data
</a> (str)
</td>
367 Restore data previously serialized with serialize_data().
</td>
371 <td class=
"name" nowrap
><a href=
"#serialize_data">serialize_data
</a> (val)
</td>
374 Recursively serialize given data to lua code, suitable for restoring
375 with loadstring().
</td>
379 <td class=
"name" nowrap
><a href=
"#serialize_json">serialize_json
</a> (data, writer)
</td>
382 Convert data structure to JSON
387 <td class=
"name" nowrap
><a href=
"#shellquote">shellquote
</a> (value)
</td>
390 Safely quote value for use in shell commands.
</td>
394 <td class=
"name" nowrap
><a href=
"#spairs">spairs
</a> (t, f)
</td>
397 Return a key, value iterator which returns the values sorted according to
398 the provided callback function.
</td>
402 <td class=
"name" nowrap
><a href=
"#split">split
</a> (str, pat, max, regex)
</td>
405 Splits given string on a defined separator sequence and return a table
406 containing the resulting substrings.
</td>
410 <td class=
"name" nowrap
><a href=
"#strip_bytecode">strip_bytecode
</a> (code)
</td>
413 Strips unnecessary lua bytecode from given string.
</td>
417 <td class=
"name" nowrap
><a href=
"luci.xml.html#striptags">striptags
</a> (value)
</td>
420 Strip HTML tags from given string.
421 This is a wrapper for
<a href=
"luci.xml.html#striptags">luci.xml.striptags()
</a>.
</td>
425 <td class=
"name" nowrap
><a href=
"#threadlocal">threadlocal
</a> ()
</td>
428 Create a new or get an already existing thread local store associated with
429 the current active coroutine.
</td>
433 <td class=
"name" nowrap
><a href=
"#trim">trim
</a> (str)
</td>
436 Remove leading and trailing whitespace from given string value.
</td>
440 <td class=
"name" nowrap
><a href=
"#ubus">ubus
</a> (object, method, values)
</td>
443 Issue an ubus call.
</td>
447 <td class=
"name" nowrap
><a href=
"#update">update
</a> (t, updates)
</td>
450 Update values in given table with the values from the second given table.
</td>
454 <td class=
"name" nowrap
><a href=
"#urldecode">urldecode
</a> (str, decode_plus)
</td>
457 Decode an URL-encoded string - optionally decoding the
"+" sign to space.
</td>
461 <td class=
"name" nowrap
><a href=
"#urlencode">urlencode
</a> (str)
</td>
464 URL-encode given string.
</td>
468 <td class=
"name" nowrap
><a href=
"#vspairs">vspairs
</a> (t)
</td>
471 Return a key, value iterator for the given table.
</td>
485 <h2><a name=
"functions"></a>Functions
</h2>
486 <dl class=
"function">
490 <dt><a name=
"append"></a><strong>append
</strong> (src, ...)
</dt>
494 Appends numerically indexed tables or single objects to a given table.
506 ...: Objects to insert
516 <h3>Return value:
</h3>
526 <dt><a name=
"bigendian"></a><strong>bigendian
</strong> ()
</dt>
530 Test whether the current system is operating in big endian mode.
539 <h3>Return value:
</h3>
540 Boolean value indicating whether system is big endian
549 <dt><a name=
"class"></a><strong>class
</strong> (base)
</dt>
553 Create a Class object (Python-style object model).
555 The class object can be instantiated by calling itself.
556 Any class functions or shared parameters can be attached to this object.
557 Attaching a table to the class object makes this table shared between
558 all instances of this class. For object parameters use the __init__ function.
559 Classes can inherit member functions and values from a base class.
560 Class can be instantiated by calling them. All parameters will be passed
561 to the __init__ function of this class - if such a function exists.
562 The __init__ function must be used to set any object parameters that are not shared
563 with other objects of this class. Any return values will be ignored.
571 base: The base class to inherit from (optional)
581 <h3>Return value:
</h3>
589 <li><a href=
"#instanceof">
593 <li><a href=
"#clone">
604 <dt><a name=
"clone"></a><strong>clone
</strong> (object, deep)
</dt>
608 Clones the given object and return it's copy.
616 object: Table value to clone
620 deep: Boolean indicating whether to do recursive cloning
630 <h3>Return value:
</h3>
640 <dt><a name=
"cmatch"></a><strong>cmatch
</strong> (str, pattern)
</dt>
644 Count the occurrences of given substring in given string.
652 str: String to search in
656 pattern: String containing pattern to find
666 <h3>Return value:
</h3>
667 Number of found occurrences
676 <dt><a name=
"combine"></a><strong>combine
</strong> (tbl1, tbl2, ...)
</dt>
680 Combines two or more numerically indexed tables and single objects into one table.
688 tbl1: Table value to combine
692 tbl2: Table value to combine
696 ...: More tables to combine
706 <h3>Return value:
</h3>
707 Table value containing all values of given tables
716 <dt><a name=
"contains"></a><strong>contains
</strong> (table, value)
</dt>
720 Checks whether the given table contains the given value.
732 value: Value to search within the given table
742 <h3>Return value:
</h3>
743 Number indicating the first index at which the given value occurs
744 within table or false.
753 <dt><a name=
"copcall"></a><strong>copcall
</strong> (f, ...)
</dt>
757 This is a coroutine-safe drop-in replacement for Lua's
"pcall"-function
765 f: Lua function to be called protected
769 ...: Parameters passed to the function
779 <h3>Return value:
</h3>
780 A boolean whether the function call succeeded and the returns
781 values of the function or the error object
790 <dt><a name=
"coxpcall"></a><strong>coxpcall
</strong> (f, err, ...)
</dt>
794 This is a coroutine-safe drop-in replacement for Lua's
"xpcall"-function
802 f: Lua function to be called protected
806 err: Custom error handler
810 ...: Parameters passed to the function
820 <h3>Return value:
</h3>
821 A boolean whether the function call succeeded and the return
822 values of either the function or the error handler
831 <dt><a name=
"dumptable"></a><strong>dumptable
</strong> (t, maxdepth)
</dt>
835 Recursively dumps a table to stdout, useful for testing and debugging.
843 t: Table value to dump
847 maxdepth: Maximum depth
857 <h3>Return value:
</h3>
867 <dt><a name=
"exec"></a><strong>exec
</strong> (command)
</dt>
871 Execute given commandline and gather stdout.
879 command: String containing command to execute
889 <h3>Return value:
</h3>
890 String containing the command's stdout
899 <dt><a name=
"execi"></a><strong>execi
</strong> (command)
</dt>
903 Return a line-buffered iterator over the output of given command.
911 command: String containing the command to execute
921 <h3>Return value:
</h3>
931 <dt><a name=
"get_bytecode"></a><strong>get_bytecode
</strong> (val)
</dt>
935 Return the current runtime bytecode of the given data. The byte code
936 will be stripped before it is returned.
944 val: Value to return as bytecode
954 <h3>Return value:
</h3>
955 String value containing the bytecode of the given data
964 <dt><a name=
"imatch"></a><strong>imatch
</strong> (val)
</dt>
968 Return a matching iterator for the given value.
970 The iterator will return one token per invocation, the tokens are separated by
971 whitespace. If the input value is a table, it is transformed into a string first.
972 A nil value will result in a valid iterator which aborts with the first invocation.
980 val: The value to scan (table, string or nil)
990 <h3>Return value:
</h3>
991 Iterator which returns one token per call
1000 <dt><a name=
"instanceof"></a><strong>instanceof
</strong> (object, class)
</dt>
1004 Test whether the given object is an instance of the given class.
1012 object: Object instance
1016 class: Class object to test against
1026 <h3>Return value:
</h3>
1027 Boolean indicating whether the object is an instance
1034 <li><a href=
"#class">
1038 <li><a href=
"#clone">
1049 <dt><a name=
"keys"></a><strong>keys
</strong> (t)
</dt>
1053 Retrieve all keys of given associative table.
1061 t: Table to extract keys from
1071 <h3>Return value:
</h3>
1072 Sorted table containing the keys
1081 <dt><a name=
"kspairs"></a><strong>kspairs
</strong> (t)
</dt>
1085 Return a key, value iterator for the given table.
1087 The table pairs are sorted by key.
1095 t: The table to iterate
1105 <h3>Return value:
</h3>
1106 Function value containing the corresponding iterator
1115 <dt><a name=
"libpath"></a><strong>libpath
</strong> ()
</dt>
1119 Returns the absolute path to LuCI base directory.
1128 <h3>Return value:
</h3>
1129 String containing the directory path
1138 <dt><a name=
"parse_units"></a><strong>parse_units
</strong> (ustr)
</dt>
1142 Parse certain units from the given string and return the canonical integer
1143 value or
0 if the unit is unknown.
1145 Upper- or lower case is irrelevant.
1146 Recognized units are:
1148 o
"y" - one year (
60*
60*
24*
366)
1149 o
"m" - one month (
60*
60*
24*
31)
1150 o
"w" - one week (
60*
60*
24*
7)
1151 o
"d" - one day (
60*
60*
24)
1152 o
"h" - one hour (
60*
60)
1153 o
"min" - one minute (
60)
1154 o
"kb" - one kilobyte (
1024)
1155 o
"mb" - one megabyte (
1024*
1024)
1156 o
"gb" - one gigabyte (
1024*
1024*
1024)
1157 o
"kib" - one si kilobyte (
1000)
1158 o
"mib" - one si megabyte (
1000*
1000)
1159 o
"gib" - one si gigabyte (
1000*
1000*
1000)
1167 ustr: String containing a numerical value with trailing unit
1177 <h3>Return value:
</h3>
1178 Number containing the canonical value
1187 <dt><a name=
"perror"></a><strong>perror
</strong> (obj)
</dt>
1191 Write given object to stderr.
1199 obj: Value to write to stderr
1209 <h3>Return value:
</h3>
1210 Boolean indicating whether the write operation was successful
1219 <dt><a name=
"restore_data"></a><strong>restore_data
</strong> (str)
</dt>
1223 Restore data previously serialized with serialize_data().
1231 str: String containing the data to restore
1241 <h3>Return value:
</h3>
1242 Value containing the restored data structure
1249 <li><a href=
"#serialize_data">
1253 <li><a href=
"#get_bytecode">
1264 <dt><a name=
"serialize_data"></a><strong>serialize_data
</strong> (val)
</dt>
1268 Recursively serialize given data to lua code, suitable for restoring
1277 val: Value containing the data to serialize
1287 <h3>Return value:
</h3>
1288 String value containing the serialized code
1295 <li><a href=
"#restore_data">
1299 <li><a href=
"#get_bytecode">
1310 <dt><a name=
"serialize_json"></a><strong>serialize_json
</strong> (data, writer)
</dt>
1314 Convert data structure to JSON
1322 data: The data to serialize
1326 writer: A function to write a chunk of JSON data (optional)
1336 <h3>Return value:
</h3>
1337 String containing the JSON if called without write callback
1346 <dt><a name=
"shellquote"></a><strong>shellquote
</strong> (value)
</dt>
1350 Safely quote value for use in shell commands.
1358 value: String containing the value to quote
1368 <h3>Return value:
</h3>
1369 Single-quote enclosed string with embedded quotes escaped
1378 <dt><a name=
"spairs"></a><strong>spairs
</strong> (t, f)
</dt>
1382 Return a key, value iterator which returns the values sorted according to
1383 the provided callback function.
1391 t: The table to iterate
1395 f: A callback function to decide the order of elements
1405 <h3>Return value:
</h3>
1406 Function value containing the corresponding iterator
1415 <dt><a name=
"split"></a><strong>split
</strong> (str, pat, max, regex)
</dt>
1419 Splits given string on a defined separator sequence and return a table
1420 containing the resulting substrings.
1422 The optional max parameter specifies the number of bytes to process,
1423 regardless of the actual length of the given string. The optional last
1424 parameter, regex, specifies whether the separator sequence is
1425 nterpreted as regular expression.
1433 str: String value containing the data to split up
1437 pat: String with separator pattern (optional, defaults to
"\n")
1441 max: Maximum times to split (optional)
1445 regex: Boolean indicating whether to interpret the separator
1446 pattern as regular expression (optional, default is false)
1456 <h3>Return value:
</h3>
1457 Table containing the resulting substrings
1466 <dt><a name=
"strip_bytecode"></a><strong>strip_bytecode
</strong> (code)
</dt>
1470 Strips unnecessary lua bytecode from given string.
1472 Information like line numbers and debugging numbers will be discarded.
1473 Original version by Peter Cawley (http://lua-users.org/lists/lua-l/
2008-
02/msg01158.html)
1481 code: String value containing the original lua byte code
1491 <h3>Return value:
</h3>
1492 String value containing the stripped lua byte code
1501 <dt><a name=
"threadlocal"></a><strong>threadlocal
</strong> ()
</dt>
1505 Create a new or get an already existing thread local store associated with
1506 the current active coroutine.
1508 A thread local store is private a table object
1509 whose values can't be accessed from outside of the running coroutine.
1518 <h3>Return value:
</h3>
1519 Table value representing the corresponding thread local store
1528 <dt><a name=
"trim"></a><strong>trim
</strong> (str)
</dt>
1532 Remove leading and trailing whitespace from given string value.
1540 str: String value containing whitespace padded data
1550 <h3>Return value:
</h3>
1551 String value with leading and trailing space removed
1560 <dt><a name=
"ubus"></a><strong>ubus
</strong> (object, method, values)
</dt>
1572 object: String containing the ubus object to call
1576 method: String containing the ubus method to call
1580 values: Table containing the values to pass
1590 <h3>Return value:
</h3>
1591 Table containin the ubus result
1600 <dt><a name=
"update"></a><strong>update
</strong> (t, updates)
</dt>
1604 Update values in given table with the values from the second given table.
1606 Both table are - in fact - merged together.
1614 t: Table which should be updated
1618 updates: Table containing the values to update
1628 <h3>Return value:
</h3>
1638 <dt><a name=
"urldecode"></a><strong>urldecode
</strong> (str, decode_plus)
</dt>
1642 Decode an URL-encoded string - optionally decoding the
"+" sign to space.
1650 str: Input string in x-www-urlencoded format
1654 decode_plus: Decode
"+" signs to spaces if true (optional)
1664 <h3>Return value:
</h3>
1672 <li><a href=
"#urlencode">
1683 <dt><a name=
"urlencode"></a><strong>urlencode
</strong> (str)
</dt>
1687 URL-encode given string.
1695 str: String to encode
1705 <h3>Return value:
</h3>
1706 String containing the encoded data
1713 <li><a href=
"#urldecode">
1724 <dt><a name=
"vspairs"></a><strong>vspairs
</strong> (t)
</dt>
1728 Return a key, value iterator for the given table.
1730 The table pairs are sorted by value.
1738 t: The table to iterate
1748 <h3>Return value:
</h3>
1749 Function value containing the corresponding iterator
1762 </div> <!-- id="content" -->
1764 </div> <!-- id="main" -->
1767 <p><a href=
"http://validator.w3.org/check?uri=referer"><img src=
"http://www.w3.org/Icons/valid-xhtml10" alt=
"Valid XHTML 1.0!" height=
"31" width=
"88" /></a></p>
1768 </div> <!-- id="about" -->
1770 </div> <!-- id="container" -->