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