docs: rename documentation folder to docs
[project/luci.git] / docs / api / modules / luci.util.html
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html>
4 <head>
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"/-->
8 </head>
9
10 <body>
11 <div id="container">
12
13 <div id="product">
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" -->
18
19 <div id="main">
20
21 <div id="navigation">
22
23
24 <h1>LuaDoc</h1>
25 <ul>
26
27 <li><a href="../index.html">Index</a></li>
28
29 </ul>
30
31
32 <!-- Module list -->
33
34 <h1>Modules</h1>
35 <ul>
36
37 <li>
38 <a href="../modules/luci.dispatcher.html">luci.dispatcher</a>
39 </li>
40
41 <li>
42 <a href="../modules/luci.http.html">luci.http</a>
43 </li>
44
45 <li>
46 <a href="../modules/luci.http.conditionals.html">luci.http.conditionals</a>
47 </li>
48
49 <li>
50 <a href="../modules/luci.http.date.html">luci.http.date</a>
51 </li>
52
53 <li>
54 <a href="../modules/luci.http.mime.html">luci.http.mime</a>
55 </li>
56
57 <li>
58 <a href="../modules/luci.i18n.html">luci.i18n</a>
59 </li>
60
61 <li>
62 <a href="../modules/luci.ip.html">luci.ip</a>
63 </li>
64
65 <li>
66 <a href="../modules/luci.ip.cidr.html">luci.ip.cidr</a>
67 </li>
68
69 <li>
70 <a href="../modules/luci.json.html">luci.json</a>
71 </li>
72
73 <li>
74 <a href="../modules/luci.jsonc.html">luci.jsonc</a>
75 </li>
76
77 <li>
78 <a href="../modules/luci.jsonc.parser.html">luci.jsonc.parser</a>
79 </li>
80
81 <li>
82 <a href="../modules/luci.model.ipkg.html">luci.model.ipkg</a>
83 </li>
84
85 <li>
86 <a href="../modules/luci.model.uci.html">luci.model.uci</a>
87 </li>
88
89 <li>
90 <a href="../modules/luci.rpcc.html">luci.rpcc</a>
91 </li>
92
93 <li>
94 <a href="../modules/luci.rpcc.ruci.html">luci.rpcc.ruci</a>
95 </li>
96
97 <li>
98 <a href="../modules/luci.sys.html">luci.sys</a>
99 </li>
100
101 <li>
102 <a href="../modules/luci.sys.init.html">luci.sys.init</a>
103 </li>
104
105 <li>
106 <a href="../modules/luci.sys.iptparser.html">luci.sys.iptparser</a>
107 </li>
108
109 <li>
110 <a href="../modules/luci.sys.net.html">luci.sys.net</a>
111 </li>
112
113 <li>
114 <a href="../modules/luci.sys.process.html">luci.sys.process</a>
115 </li>
116
117 <li>
118 <a href="../modules/luci.sys.user.html">luci.sys.user</a>
119 </li>
120
121 <li>
122 <a href="../modules/luci.sys.wifi.html">luci.sys.wifi</a>
123 </li>
124
125 <li><strong>luci.util</strong></li>
126
127 <li>
128 <a href="../modules/nixio.html">nixio</a>
129 </li>
130
131 <li>
132 <a href="../modules/nixio.CHANGELOG.html">nixio.CHANGELOG</a>
133 </li>
134
135 <li>
136 <a href="../modules/nixio.CryptoHash.html">nixio.CryptoHash</a>
137 </li>
138
139 <li>
140 <a href="../modules/nixio.File.html">nixio.File</a>
141 </li>
142
143 <li>
144 <a href="../modules/nixio.README.html">nixio.README</a>
145 </li>
146
147 <li>
148 <a href="../modules/nixio.Socket.html">nixio.Socket</a>
149 </li>
150
151 <li>
152 <a href="../modules/nixio.TLSContext.html">nixio.TLSContext</a>
153 </li>
154
155 <li>
156 <a href="../modules/nixio.TLSSocket.html">nixio.TLSSocket</a>
157 </li>
158
159 <li>
160 <a href="../modules/nixio.UnifiedIO.html">nixio.UnifiedIO</a>
161 </li>
162
163 <li>
164 <a href="../modules/nixio.bin.html">nixio.bin</a>
165 </li>
166
167 <li>
168 <a href="../modules/nixio.bit.html">nixio.bit</a>
169 </li>
170
171 <li>
172 <a href="../modules/nixio.crypto.html">nixio.crypto</a>
173 </li>
174
175 <li>
176 <a href="../modules/nixio.fs.html">nixio.fs</a>
177 </li>
178
179 </ul>
180
181
182
183 <!-- File list -->
184
185
186
187
188
189
190
191 </div><!-- id="navigation" -->
192
193 <div id="content">
194
195 <h1>Class <code>luci.util</code></h1>
196
197 <p></p>
198
199
200
201
202
203
204
205 <h2>Functions</h2>
206 <table class="function_list">
207
208 <tr>
209 <td class="name" nowrap><a href="#append">append</a>&nbsp;(src, ...)</td>
210 <td class="summary">
211
212 Appends numerically indexed tables or single objects to a given table.</td>
213 </tr>
214
215 <tr>
216 <td class="name" nowrap><a href="#bigendian">bigendian</a>&nbsp;()</td>
217 <td class="summary">
218
219 Test whether the current system is operating in big endian mode.</td>
220 </tr>
221
222 <tr>
223 <td class="name" nowrap><a href="#class">class</a>&nbsp;(base)</td>
224 <td class="summary">
225
226 Create a Class object (Python-style object model).</td>
227 </tr>
228
229 <tr>
230 <td class="name" nowrap><a href="#clone">clone</a>&nbsp;(object, deep)</td>
231 <td class="summary">
232
233 Clones the given object and return it's copy.</td>
234 </tr>
235
236 <tr>
237 <td class="name" nowrap><a href="#cmatch">cmatch</a>&nbsp;(str, pattern)</td>
238 <td class="summary">
239
240 Count the occurrences of given substring in given string.</td>
241 </tr>
242
243 <tr>
244 <td class="name" nowrap><a href="#combine">combine</a>&nbsp;(tbl1, tbl2, ...)</td>
245 <td class="summary">
246
247 Combines two or more numerically indexed tables and single objects into one table.</td>
248 </tr>
249
250 <tr>
251 <td class="name" nowrap><a href="#contains">contains</a>&nbsp;(table, value)</td>
252 <td class="summary">
253
254 Checks whether the given table contains the given value.</td>
255 </tr>
256
257 <tr>
258 <td class="name" nowrap><a href="#copcall">copcall</a>&nbsp;(f, ...)</td>
259 <td class="summary">
260
261 This is a coroutine-safe drop-in replacement for Lua's "pcall"-function
262 </td>
263 </tr>
264
265 <tr>
266 <td class="name" nowrap><a href="#coxpcall">coxpcall</a>&nbsp;(f, err, ...)</td>
267 <td class="summary">
268
269 This is a coroutine-safe drop-in replacement for Lua's "xpcall"-function
270 </td>
271 </tr>
272
273 <tr>
274 <td class="name" nowrap><a href="#dumptable">dumptable</a>&nbsp;(t, maxdepth)</td>
275 <td class="summary">
276
277 Recursively dumps a table to stdout, useful for testing and debugging.</td>
278 </tr>
279
280 <tr>
281 <td class="name" nowrap><a href="#exec">exec</a>&nbsp;(command)</td>
282 <td class="summary">
283
284 Execute given commandline and gather stdout.</td>
285 </tr>
286
287 <tr>
288 <td class="name" nowrap><a href="#execi">execi</a>&nbsp;(command)</td>
289 <td class="summary">
290
291 Return a line-buffered iterator over the output of given command.</td>
292 </tr>
293
294 <tr>
295 <td class="name" nowrap><a href="#get_bytecode">get_bytecode</a>&nbsp;(val)</td>
296 <td class="summary">
297
298 Return the current runtime bytecode of the given data.</td>
299 </tr>
300
301 <tr>
302 <td class="name" nowrap><a href="#imatch">imatch</a>&nbsp;(val)</td>
303 <td class="summary">
304
305 Return a matching iterator for the given value.</td>
306 </tr>
307
308 <tr>
309 <td class="name" nowrap><a href="#instanceof">instanceof</a>&nbsp;(object, class)</td>
310 <td class="summary">
311
312 Test whether the given object is an instance of the given class.</td>
313 </tr>
314
315 <tr>
316 <td class="name" nowrap><a href="#keys">keys</a>&nbsp;(t)</td>
317 <td class="summary">
318
319 Retrieve all keys of given associative table.</td>
320 </tr>
321
322 <tr>
323 <td class="name" nowrap><a href="#kspairs">kspairs</a>&nbsp;(t)</td>
324 <td class="summary">
325
326 Return a key, value iterator for the given table.</td>
327 </tr>
328
329 <tr>
330 <td class="name" nowrap><a href="#libpath">libpath</a>&nbsp;()</td>
331 <td class="summary">
332
333 Returns the absolute path to LuCI base directory.</td>
334 </tr>
335
336 <tr>
337 <td class="name" nowrap><a href="#parse_units">parse_units</a>&nbsp;(ustr)</td>
338 <td class="summary">
339
340 Parse certain units from the given string and return the canonical integer
341 value or 0 if the unit is unknown.</td>
342 </tr>
343
344 <tr>
345 <td class="name" nowrap><a href="#pcdata">pcdata</a>&nbsp;(value)</td>
346 <td class="summary">
347
348 Create valid XML PCDATA from given string.</td>
349 </tr>
350
351 <tr>
352 <td class="name" nowrap><a href="#perror">perror</a>&nbsp;(obj)</td>
353 <td class="summary">
354
355 Write given object to stderr.</td>
356 </tr>
357
358 <tr>
359 <td class="name" nowrap><a href="#restore_data">restore_data</a>&nbsp;(str)</td>
360 <td class="summary">
361
362 Restore data previously serialized with serialize_data().</td>
363 </tr>
364
365 <tr>
366 <td class="name" nowrap><a href="#serialize_data">serialize_data</a>&nbsp;(val)</td>
367 <td class="summary">
368
369 Recursively serialize given data to lua code, suitable for restoring
370 with loadstring().</td>
371 </tr>
372
373 <tr>
374 <td class="name" nowrap><a href="#serialize_json">serialize_json</a>&nbsp;(data, writer)</td>
375 <td class="summary">
376
377 Convert data structure to JSON
378 </td>
379 </tr>
380
381 <tr>
382 <td class="name" nowrap><a href="#shellquote">shellquote</a>&nbsp;(value)</td>
383 <td class="summary">
384
385 Safely quote value for use in shell commands.</td>
386 </tr>
387
388 <tr>
389 <td class="name" nowrap><a href="#spairs">spairs</a>&nbsp;(t, f)</td>
390 <td class="summary">
391
392 Return a key, value iterator which returns the values sorted according to
393 the provided callback function.</td>
394 </tr>
395
396 <tr>
397 <td class="name" nowrap><a href="#split">split</a>&nbsp;(str, pat, max, regex)</td>
398 <td class="summary">
399
400 Splits given string on a defined separator sequence and return a table
401 containing the resulting substrings.</td>
402 </tr>
403
404 <tr>
405 <td class="name" nowrap><a href="#strip_bytecode">strip_bytecode</a>&nbsp;(code)</td>
406 <td class="summary">
407
408 Strips unnecessary lua bytecode from given string.</td>
409 </tr>
410
411 <tr>
412 <td class="name" nowrap><a href="#striptags">striptags</a>&nbsp;(value)</td>
413 <td class="summary">
414
415 Strip HTML tags from given string.</td>
416 </tr>
417
418 <tr>
419 <td class="name" nowrap><a href="#threadlocal">threadlocal</a>&nbsp;()</td>
420 <td class="summary">
421
422 Create a new or get an already existing thread local store associated with
423 the current active coroutine.</td>
424 </tr>
425
426 <tr>
427 <td class="name" nowrap><a href="#trim">trim</a>&nbsp;(str)</td>
428 <td class="summary">
429
430 Remove leading and trailing whitespace from given string value.</td>
431 </tr>
432
433 <tr>
434 <td class="name" nowrap><a href="#ubus">ubus</a>&nbsp;(object, method, values)</td>
435 <td class="summary">
436
437 Issue an ubus call.</td>
438 </tr>
439
440 <tr>
441 <td class="name" nowrap><a href="#update">update</a>&nbsp;(t, updates)</td>
442 <td class="summary">
443
444 Update values in given table with the values from the second given table.</td>
445 </tr>
446
447 <tr>
448 <td class="name" nowrap><a href="#urldecode">urldecode</a>&nbsp;(str, decode_plus)</td>
449 <td class="summary">
450
451 Decode an URL-encoded string - optionally decoding the "+" sign to space.</td>
452 </tr>
453
454 <tr>
455 <td class="name" nowrap><a href="#urlencode">urlencode</a>&nbsp;(str)</td>
456 <td class="summary">
457
458 URL-encode given string.</td>
459 </tr>
460
461 <tr>
462 <td class="name" nowrap><a href="#vspairs">vspairs</a>&nbsp;(t)</td>
463 <td class="summary">
464
465 Return a key, value iterator for the given table.</td>
466 </tr>
467
468 </table>
469
470
471
472
473
474
475 <br/>
476 <br/>
477
478
479 <h2><a name="functions"></a>Functions</h2>
480 <dl class="function">
481
482
483
484 <dt><a name="append"></a><strong>append</strong>&nbsp;(src, ...)</dt>
485 <dd>
486
487
488 Appends numerically indexed tables or single objects to a given table.
489
490
491
492 <h3>Parameters</h3>
493 <ul>
494
495 <li>
496 src: Target table
497 </li>
498
499 <li>
500 ...: Objects to insert
501 </li>
502
503 </ul>
504
505
506
507
508
509
510 <h3>Return value:</h3>
511 Target table
512
513
514
515 </dd>
516
517
518
519
520 <dt><a name="bigendian"></a><strong>bigendian</strong>&nbsp;()</dt>
521 <dd>
522
523
524 Test whether the current system is operating in big endian mode.
525
526
527
528
529
530
531
532
533 <h3>Return value:</h3>
534 Boolean value indicating whether system is big endian
535
536
537
538 </dd>
539
540
541
542
543 <dt><a name="class"></a><strong>class</strong>&nbsp;(base)</dt>
544 <dd>
545
546
547 Create a Class object (Python-style object model).
548
549 The class object can be instantiated by calling itself.
550 Any class functions or shared parameters can be attached to this object.
551 Attaching a table to the class object makes this table shared between
552 all instances of this class. For object parameters use the __init__ function.
553 Classes can inherit member functions and values from a base class.
554 Class can be instantiated by calling them. All parameters will be passed
555 to the __init__ function of this class - if such a function exists.
556 The __init__ function must be used to set any object parameters that are not shared
557 with other objects of this class. Any return values will be ignored.
558
559
560
561 <h3>Parameters</h3>
562 <ul>
563
564 <li>
565 base: The base class to inherit from (optional)
566 </li>
567
568 </ul>
569
570
571
572
573
574
575 <h3>Return value:</h3>
576 A class object
577
578
579
580 <h3>See also:</h3>
581 <ul>
582
583 <li><a href="#instanceof">
584 instanceof
585 </a>
586
587 <li><a href="#clone">
588 clone
589 </a>
590
591 </ul>
592
593 </dd>
594
595
596
597
598 <dt><a name="clone"></a><strong>clone</strong>&nbsp;(object, deep)</dt>
599 <dd>
600
601
602 Clones the given object and return it's copy.
603
604
605
606 <h3>Parameters</h3>
607 <ul>
608
609 <li>
610 object: Table value to clone
611 </li>
612
613 <li>
614 deep: Boolean indicating whether to do recursive cloning
615 </li>
616
617 </ul>
618
619
620
621
622
623
624 <h3>Return value:</h3>
625 Cloned table value
626
627
628
629 </dd>
630
631
632
633
634 <dt><a name="cmatch"></a><strong>cmatch</strong>&nbsp;(str, pattern)</dt>
635 <dd>
636
637
638 Count the occurrences of given substring in given string.
639
640
641
642 <h3>Parameters</h3>
643 <ul>
644
645 <li>
646 str: String to search in
647 </li>
648
649 <li>
650 pattern: String containing pattern to find
651 </li>
652
653 </ul>
654
655
656
657
658
659
660 <h3>Return value:</h3>
661 Number of found occurrences
662
663
664
665 </dd>
666
667
668
669
670 <dt><a name="combine"></a><strong>combine</strong>&nbsp;(tbl1, tbl2, ...)</dt>
671 <dd>
672
673
674 Combines two or more numerically indexed tables and single objects into one table.
675
676
677
678 <h3>Parameters</h3>
679 <ul>
680
681 <li>
682 tbl1: Table value to combine
683 </li>
684
685 <li>
686 tbl2: Table value to combine
687 </li>
688
689 <li>
690 ...: More tables to combine
691 </li>
692
693 </ul>
694
695
696
697
698
699
700 <h3>Return value:</h3>
701 Table value containing all values of given tables
702
703
704
705 </dd>
706
707
708
709
710 <dt><a name="contains"></a><strong>contains</strong>&nbsp;(table, value)</dt>
711 <dd>
712
713
714 Checks whether the given table contains the given value.
715
716
717
718 <h3>Parameters</h3>
719 <ul>
720
721 <li>
722 table: Table value
723 </li>
724
725 <li>
726 value: Value to search within the given table
727 </li>
728
729 </ul>
730
731
732
733
734
735
736 <h3>Return value:</h3>
737 Number indicating the first index at which the given value occurs
738 within table or false.
739
740
741
742 </dd>
743
744
745
746
747 <dt><a name="copcall"></a><strong>copcall</strong>&nbsp;(f, ...)</dt>
748 <dd>
749
750
751 This is a coroutine-safe drop-in replacement for Lua's "pcall"-function
752
753
754
755 <h3>Parameters</h3>
756 <ul>
757
758 <li>
759 f: Lua function to be called protected
760 </li>
761
762 <li>
763 ...: Parameters passed to the function
764 </li>
765
766 </ul>
767
768
769
770
771
772
773 <h3>Return value:</h3>
774 A boolean whether the function call succeeded and the returns
775 values of the function or the error object
776
777
778
779 </dd>
780
781
782
783
784 <dt><a name="coxpcall"></a><strong>coxpcall</strong>&nbsp;(f, err, ...)</dt>
785 <dd>
786
787
788 This is a coroutine-safe drop-in replacement for Lua's "xpcall"-function
789
790
791
792 <h3>Parameters</h3>
793 <ul>
794
795 <li>
796 f: Lua function to be called protected
797 </li>
798
799 <li>
800 err: Custom error handler
801 </li>
802
803 <li>
804 ...: Parameters passed to the function
805 </li>
806
807 </ul>
808
809
810
811
812
813
814 <h3>Return value:</h3>
815 A boolean whether the function call succeeded and the return
816 values of either the function or the error handler
817
818
819
820 </dd>
821
822
823
824
825 <dt><a name="dumptable"></a><strong>dumptable</strong>&nbsp;(t, maxdepth)</dt>
826 <dd>
827
828
829 Recursively dumps a table to stdout, useful for testing and debugging.
830
831
832
833 <h3>Parameters</h3>
834 <ul>
835
836 <li>
837 t: Table value to dump
838 </li>
839
840 <li>
841 maxdepth: Maximum depth
842 </li>
843
844 </ul>
845
846
847
848
849
850
851 <h3>Return value:</h3>
852 Always nil
853
854
855
856 </dd>
857
858
859
860
861 <dt><a name="exec"></a><strong>exec</strong>&nbsp;(command)</dt>
862 <dd>
863
864
865 Execute given commandline and gather stdout.
866
867
868
869 <h3>Parameters</h3>
870 <ul>
871
872 <li>
873 command: String containing command to execute
874 </li>
875
876 </ul>
877
878
879
880
881
882
883 <h3>Return value:</h3>
884 String containing the command's stdout
885
886
887
888 </dd>
889
890
891
892
893 <dt><a name="execi"></a><strong>execi</strong>&nbsp;(command)</dt>
894 <dd>
895
896
897 Return a line-buffered iterator over the output of given command.
898
899
900
901 <h3>Parameters</h3>
902 <ul>
903
904 <li>
905 command: String containing the command to execute
906 </li>
907
908 </ul>
909
910
911
912
913
914
915 <h3>Return value:</h3>
916 Iterator
917
918
919
920 </dd>
921
922
923
924
925 <dt><a name="get_bytecode"></a><strong>get_bytecode</strong>&nbsp;(val)</dt>
926 <dd>
927
928
929 Return the current runtime bytecode of the given data. The byte code
930 will be stripped before it is returned.
931
932
933
934 <h3>Parameters</h3>
935 <ul>
936
937 <li>
938 val: Value to return as bytecode
939 </li>
940
941 </ul>
942
943
944
945
946
947
948 <h3>Return value:</h3>
949 String value containing the bytecode of the given data
950
951
952
953 </dd>
954
955
956
957
958 <dt><a name="imatch"></a><strong>imatch</strong>&nbsp;(val)</dt>
959 <dd>
960
961
962 Return a matching iterator for the given value.
963
964 The iterator will return one token per invocation, the tokens are separated by
965 whitespace. If the input value is a table, it is transformed into a string first.
966 A nil value will result in a valid iterator which aborts with the first invocation.
967
968
969
970 <h3>Parameters</h3>
971 <ul>
972
973 <li>
974 val: The value to scan (table, string or nil)
975 </li>
976
977 </ul>
978
979
980
981
982
983
984 <h3>Return value:</h3>
985 Iterator which returns one token per call
986
987
988
989 </dd>
990
991
992
993
994 <dt><a name="instanceof"></a><strong>instanceof</strong>&nbsp;(object, class)</dt>
995 <dd>
996
997
998 Test whether the given object is an instance of the given class.
999
1000
1001
1002 <h3>Parameters</h3>
1003 <ul>
1004
1005 <li>
1006 object: Object instance
1007 </li>
1008
1009 <li>
1010 class: Class object to test against
1011 </li>
1012
1013 </ul>
1014
1015
1016
1017
1018
1019
1020 <h3>Return value:</h3>
1021 Boolean indicating whether the object is an instance
1022
1023
1024
1025 <h3>See also:</h3>
1026 <ul>
1027
1028 <li><a href="#class">
1029 class
1030 </a>
1031
1032 <li><a href="#clone">
1033 clone
1034 </a>
1035
1036 </ul>
1037
1038 </dd>
1039
1040
1041
1042
1043 <dt><a name="keys"></a><strong>keys</strong>&nbsp;(t)</dt>
1044 <dd>
1045
1046
1047 Retrieve all keys of given associative table.
1048
1049
1050
1051 <h3>Parameters</h3>
1052 <ul>
1053
1054 <li>
1055 t: Table to extract keys from
1056 </li>
1057
1058 </ul>
1059
1060
1061
1062
1063
1064
1065 <h3>Return value:</h3>
1066 Sorted table containing the keys
1067
1068
1069
1070 </dd>
1071
1072
1073
1074
1075 <dt><a name="kspairs"></a><strong>kspairs</strong>&nbsp;(t)</dt>
1076 <dd>
1077
1078
1079 Return a key, value iterator for the given table.
1080
1081 The table pairs are sorted by key.
1082
1083
1084
1085 <h3>Parameters</h3>
1086 <ul>
1087
1088 <li>
1089 t: The table to iterate
1090 </li>
1091
1092 </ul>
1093
1094
1095
1096
1097
1098
1099 <h3>Return value:</h3>
1100 Function value containing the corresponding iterator
1101
1102
1103
1104 </dd>
1105
1106
1107
1108
1109 <dt><a name="libpath"></a><strong>libpath</strong>&nbsp;()</dt>
1110 <dd>
1111
1112
1113 Returns the absolute path to LuCI base directory.
1114
1115
1116
1117
1118
1119
1120
1121
1122 <h3>Return value:</h3>
1123 String containing the directory path
1124
1125
1126
1127 </dd>
1128
1129
1130
1131
1132 <dt><a name="parse_units"></a><strong>parse_units</strong>&nbsp;(ustr)</dt>
1133 <dd>
1134
1135
1136 Parse certain units from the given string and return the canonical integer
1137 value or 0 if the unit is unknown.
1138
1139 Upper- or lower case is irrelevant.
1140 Recognized units are:
1141
1142 o "y" - one year (60*60*24*366)
1143 o "m" - one month (60*60*24*31)
1144 o "w" - one week (60*60*24*7)
1145 o "d" - one day (60*60*24)
1146 o "h" - one hour (60*60)
1147 o "min" - one minute (60)
1148 o "kb" - one kilobyte (1024)
1149 o "mb" - one megabyte (1024*1024)
1150 o "gb" - one gigabyte (1024*1024*1024)
1151 o "kib" - one si kilobyte (1000)
1152 o "mib" - one si megabyte (1000*1000)
1153 o "gib" - one si gigabyte (1000*1000*1000)
1154
1155
1156
1157 <h3>Parameters</h3>
1158 <ul>
1159
1160 <li>
1161 ustr: String containing a numerical value with trailing unit
1162 </li>
1163
1164 </ul>
1165
1166
1167
1168
1169
1170
1171 <h3>Return value:</h3>
1172 Number containing the canonical value
1173
1174
1175
1176 </dd>
1177
1178
1179
1180
1181 <dt><a name="pcdata"></a><strong>pcdata</strong>&nbsp;(value)</dt>
1182 <dd>
1183
1184
1185 Create valid XML PCDATA from given string.
1186
1187
1188
1189 <h3>Parameters</h3>
1190 <ul>
1191
1192 <li>
1193 value: String value containing the data to escape
1194 </li>
1195
1196 </ul>
1197
1198
1199
1200
1201
1202
1203 <h3>Return value:</h3>
1204 String value containing the escaped data
1205
1206
1207
1208 </dd>
1209
1210
1211
1212
1213 <dt><a name="perror"></a><strong>perror</strong>&nbsp;(obj)</dt>
1214 <dd>
1215
1216
1217 Write given object to stderr.
1218
1219
1220
1221 <h3>Parameters</h3>
1222 <ul>
1223
1224 <li>
1225 obj: Value to write to stderr
1226 </li>
1227
1228 </ul>
1229
1230
1231
1232
1233
1234
1235 <h3>Return value:</h3>
1236 Boolean indicating whether the write operation was successful
1237
1238
1239
1240 </dd>
1241
1242
1243
1244
1245 <dt><a name="restore_data"></a><strong>restore_data</strong>&nbsp;(str)</dt>
1246 <dd>
1247
1248
1249 Restore data previously serialized with serialize_data().
1250
1251
1252
1253 <h3>Parameters</h3>
1254 <ul>
1255
1256 <li>
1257 str: String containing the data to restore
1258 </li>
1259
1260 </ul>
1261
1262
1263
1264
1265
1266
1267 <h3>Return value:</h3>
1268 Value containing the restored data structure
1269
1270
1271
1272 <h3>See also:</h3>
1273 <ul>
1274
1275 <li><a href="#serialize_data">
1276 serialize_data
1277 </a>
1278
1279 <li><a href="#get_bytecode">
1280 get_bytecode
1281 </a>
1282
1283 </ul>
1284
1285 </dd>
1286
1287
1288
1289
1290 <dt><a name="serialize_data"></a><strong>serialize_data</strong>&nbsp;(val)</dt>
1291 <dd>
1292
1293
1294 Recursively serialize given data to lua code, suitable for restoring
1295 with loadstring().
1296
1297
1298
1299 <h3>Parameters</h3>
1300 <ul>
1301
1302 <li>
1303 val: Value containing the data to serialize
1304 </li>
1305
1306 </ul>
1307
1308
1309
1310
1311
1312
1313 <h3>Return value:</h3>
1314 String value containing the serialized code
1315
1316
1317
1318 <h3>See also:</h3>
1319 <ul>
1320
1321 <li><a href="#restore_data">
1322 restore_data
1323 </a>
1324
1325 <li><a href="#get_bytecode">
1326 get_bytecode
1327 </a>
1328
1329 </ul>
1330
1331 </dd>
1332
1333
1334
1335
1336 <dt><a name="serialize_json"></a><strong>serialize_json</strong>&nbsp;(data, writer)</dt>
1337 <dd>
1338
1339
1340 Convert data structure to JSON
1341
1342
1343
1344 <h3>Parameters</h3>
1345 <ul>
1346
1347 <li>
1348 data: The data to serialize
1349 </li>
1350
1351 <li>
1352 writer: A function to write a chunk of JSON data (optional)
1353 </li>
1354
1355 </ul>
1356
1357
1358
1359
1360
1361
1362 <h3>Return value:</h3>
1363 String containing the JSON if called without write callback
1364
1365
1366
1367 </dd>
1368
1369
1370
1371
1372 <dt><a name="shellquote"></a><strong>shellquote</strong>&nbsp;(value)</dt>
1373 <dd>
1374
1375
1376 Safely quote value for use in shell commands.
1377
1378
1379
1380 <h3>Parameters</h3>
1381 <ul>
1382
1383 <li>
1384 value: String containing the value to quote
1385 </li>
1386
1387 </ul>
1388
1389
1390
1391
1392
1393
1394 <h3>Return value:</h3>
1395 Single-quote enclosed string with embedded quotes escaped
1396
1397
1398
1399 </dd>
1400
1401
1402
1403
1404 <dt><a name="spairs"></a><strong>spairs</strong>&nbsp;(t, f)</dt>
1405 <dd>
1406
1407
1408 Return a key, value iterator which returns the values sorted according to
1409 the provided callback function.
1410
1411
1412
1413 <h3>Parameters</h3>
1414 <ul>
1415
1416 <li>
1417 t: The table to iterate
1418 </li>
1419
1420 <li>
1421 f: A callback function to decide the order of elements
1422 </li>
1423
1424 </ul>
1425
1426
1427
1428
1429
1430
1431 <h3>Return value:</h3>
1432 Function value containing the corresponding iterator
1433
1434
1435
1436 </dd>
1437
1438
1439
1440
1441 <dt><a name="split"></a><strong>split</strong>&nbsp;(str, pat, max, regex)</dt>
1442 <dd>
1443
1444
1445 Splits given string on a defined separator sequence and return a table
1446 containing the resulting substrings.
1447
1448 The optional max parameter specifies the number of bytes to process,
1449 regardless of the actual length of the given string. The optional last
1450 parameter, regex, specifies whether the separator sequence is
1451 nterpreted as regular expression.
1452
1453
1454
1455 <h3>Parameters</h3>
1456 <ul>
1457
1458 <li>
1459 str: String value containing the data to split up
1460 </li>
1461
1462 <li>
1463 pat: String with separator pattern (optional, defaults to "\n")
1464 </li>
1465
1466 <li>
1467 max: Maximum times to split (optional)
1468 </li>
1469
1470 <li>
1471 regex: Boolean indicating whether to interpret the separator
1472 pattern as regular expression (optional, default is false)
1473 </li>
1474
1475 </ul>
1476
1477
1478
1479
1480
1481
1482 <h3>Return value:</h3>
1483 Table containing the resulting substrings
1484
1485
1486
1487 </dd>
1488
1489
1490
1491
1492 <dt><a name="strip_bytecode"></a><strong>strip_bytecode</strong>&nbsp;(code)</dt>
1493 <dd>
1494
1495
1496 Strips unnecessary lua bytecode from given string.
1497
1498 Information like line numbers and debugging numbers will be discarded.
1499 Original version by Peter Cawley (http://lua-users.org/lists/lua-l/2008-02/msg01158.html)
1500
1501
1502
1503 <h3>Parameters</h3>
1504 <ul>
1505
1506 <li>
1507 code: String value containing the original lua byte code
1508 </li>
1509
1510 </ul>
1511
1512
1513
1514
1515
1516
1517 <h3>Return value:</h3>
1518 String value containing the stripped lua byte code
1519
1520
1521
1522 </dd>
1523
1524
1525
1526
1527 <dt><a name="striptags"></a><strong>striptags</strong>&nbsp;(value)</dt>
1528 <dd>
1529
1530
1531 Strip HTML tags from given string.
1532
1533
1534
1535 <h3>Parameters</h3>
1536 <ul>
1537
1538 <li>
1539 value: String containing the HTML text
1540 </li>
1541
1542 </ul>
1543
1544
1545
1546
1547
1548
1549 <h3>Return value:</h3>
1550 String with HTML tags stripped of
1551
1552
1553
1554 </dd>
1555
1556
1557
1558
1559 <dt><a name="threadlocal"></a><strong>threadlocal</strong>&nbsp;()</dt>
1560 <dd>
1561
1562
1563 Create a new or get an already existing thread local store associated with
1564 the current active coroutine.
1565
1566 A thread local store is private a table object
1567 whose values can't be accessed from outside of the running coroutine.
1568
1569
1570
1571
1572
1573
1574
1575
1576 <h3>Return value:</h3>
1577 Table value representing the corresponding thread local store
1578
1579
1580
1581 </dd>
1582
1583
1584
1585
1586 <dt><a name="trim"></a><strong>trim</strong>&nbsp;(str)</dt>
1587 <dd>
1588
1589
1590 Remove leading and trailing whitespace from given string value.
1591
1592
1593
1594 <h3>Parameters</h3>
1595 <ul>
1596
1597 <li>
1598 str: String value containing whitespace padded data
1599 </li>
1600
1601 </ul>
1602
1603
1604
1605
1606
1607
1608 <h3>Return value:</h3>
1609 String value with leading and trailing space removed
1610
1611
1612
1613 </dd>
1614
1615
1616
1617
1618 <dt><a name="ubus"></a><strong>ubus</strong>&nbsp;(object, method, values)</dt>
1619 <dd>
1620
1621
1622 Issue an ubus call.
1623
1624
1625
1626 <h3>Parameters</h3>
1627 <ul>
1628
1629 <li>
1630 object: String containing the ubus object to call
1631 </li>
1632
1633 <li>
1634 method: String containing the ubus method to call
1635 </li>
1636
1637 <li>
1638 values: Table containing the values to pass
1639 </li>
1640
1641 </ul>
1642
1643
1644
1645
1646
1647
1648 <h3>Return value:</h3>
1649 Table containin the ubus result
1650
1651
1652
1653 </dd>
1654
1655
1656
1657
1658 <dt><a name="update"></a><strong>update</strong>&nbsp;(t, updates)</dt>
1659 <dd>
1660
1661
1662 Update values in given table with the values from the second given table.
1663
1664 Both table are - in fact - merged together.
1665
1666
1667
1668 <h3>Parameters</h3>
1669 <ul>
1670
1671 <li>
1672 t: Table which should be updated
1673 </li>
1674
1675 <li>
1676 updates: Table containing the values to update
1677 </li>
1678
1679 </ul>
1680
1681
1682
1683
1684
1685
1686 <h3>Return value:</h3>
1687 Always nil
1688
1689
1690
1691 </dd>
1692
1693
1694
1695
1696 <dt><a name="urldecode"></a><strong>urldecode</strong>&nbsp;(str, decode_plus)</dt>
1697 <dd>
1698
1699
1700 Decode an URL-encoded string - optionally decoding the "+" sign to space.
1701
1702
1703
1704 <h3>Parameters</h3>
1705 <ul>
1706
1707 <li>
1708 str: Input string in x-www-urlencoded format
1709 </li>
1710
1711 <li>
1712 decode_plus: Decode "+" signs to spaces if true (optional)
1713 </li>
1714
1715 </ul>
1716
1717
1718
1719
1720
1721
1722 <h3>Return value:</h3>
1723 The decoded string
1724
1725
1726
1727 <h3>See also:</h3>
1728 <ul>
1729
1730 <li><a href="#urlencode">
1731 urlencode
1732 </a>
1733
1734 </ul>
1735
1736 </dd>
1737
1738
1739
1740
1741 <dt><a name="urlencode"></a><strong>urlencode</strong>&nbsp;(str)</dt>
1742 <dd>
1743
1744
1745 URL-encode given string.
1746
1747
1748
1749 <h3>Parameters</h3>
1750 <ul>
1751
1752 <li>
1753 str: String to encode
1754 </li>
1755
1756 </ul>
1757
1758
1759
1760
1761
1762
1763 <h3>Return value:</h3>
1764 String containing the encoded data
1765
1766
1767
1768 <h3>See also:</h3>
1769 <ul>
1770
1771 <li><a href="#urldecode">
1772 urldecode
1773 </a>
1774
1775 </ul>
1776
1777 </dd>
1778
1779
1780
1781
1782 <dt><a name="vspairs"></a><strong>vspairs</strong>&nbsp;(t)</dt>
1783 <dd>
1784
1785
1786 Return a key, value iterator for the given table.
1787
1788 The table pairs are sorted by value.
1789
1790
1791
1792 <h3>Parameters</h3>
1793 <ul>
1794
1795 <li>
1796 t: The table to iterate
1797 </li>
1798
1799 </ul>
1800
1801
1802
1803
1804
1805
1806 <h3>Return value:</h3>
1807 Function value containing the corresponding iterator
1808
1809
1810
1811 </dd>
1812
1813
1814 </dl>
1815
1816
1817
1818
1819
1820 </div> <!-- id="content" -->
1821
1822 </div> <!-- id="main" -->
1823
1824 <div id="about">
1825 <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>
1826 </div> <!-- id="about" -->
1827
1828 </div> <!-- id="container" -->
1829 </body>
1830 </html>