-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathstd.html
More file actions
843 lines (687 loc) · 26.3 KB
/
std.html
File metadata and controls
843 lines (687 loc) · 26.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<head>
<title>stdlib 41.2.2 Reference</title>
<link rel="stylesheet" href="../ldoc.css" type="text/css" />
</head>
<body>
<div id="container">
<div id="product">
<div id="product_logo"></div>
<div id="product_name"><big><b></b></big></div>
<div id="product_description"></div>
</div> <!-- id="product" -->
<div id="main">
<!-- Menu -->
<div id="navigation">
<br/>
<h1>stdlib 41.2.2</h1>
<ul>
<li><a href="../index.html">Index</a></li>
</ul>
<h2>Contents</h2>
<ul>
<li><a href="#Functions">Functions</a></li>
<li><a href="#Tables">Tables</a></li>
<li><a href="#Metamethods">Metamethods </a></li>
</ul>
<h2>Modules</h2>
<ul class="nowrap">
<li><strong>std</strong></li>
<li><a href="../modules/std.debug.html">std.debug</a></li>
<li><a href="../modules/std.functional.html">std.functional</a></li>
<li><a href="../modules/std.io.html">std.io</a></li>
<li><a href="../modules/std.math.html">std.math</a></li>
<li><a href="../modules/std.operator.html">std.operator</a></li>
<li><a href="../modules/std.package.html">std.package</a></li>
<li><a href="../modules/std.strict.html">std.strict</a></li>
<li><a href="../modules/std.string.html">std.string</a></li>
<li><a href="../modules/std.table.html">std.table</a></li>
</ul>
<h2>Classes</h2>
<ul class="nowrap">
<li><a href="../classes/std.tree.html">std.tree</a></li>
<li><a href="../classes/std.container.html">std.container</a></li>
<li><a href="../classes/std.object.html">std.object</a></li>
<li><a href="../classes/std.list.html">std.list</a></li>
<li><a href="../classes/std.optparse.html">std.optparse</a></li>
<li><a href="../classes/std.set.html">std.set</a></li>
<li><a href="../classes/std.strbuf.html">std.strbuf</a></li>
</ul>
</div>
<div id="content">
<h1>Module <code>std</code></h1>
<p>Lua Standard Libraries.</p>
<p> This module contains a selection of improved Lua core functions, among
others.</p>
<p> Also, after requiring this module, simply referencing symbols in the
submodule hierarchy will load the necessary modules on demand.</p>
<p> By default there are no changes to any global symbols, or monkey
patching of core module tables and metatables. However, sometimes it's
still convenient to do that: For example, when using stdlib from the
REPL, or in a prototype where you want to throw caution to the wind and
compatibility with other modules be damned. In that case, you can give
<code>stdlib</code> permission to scribble all over your namespaces by using the
various <code>monkey_patch</code> calls in the library.</p>
<h2><a href="#Functions">Functions</a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#assert">assert (expect[, f=""[, ...]])</a></td>
<td class="summary">Enhance core <code>assert</code> to also allow formatted arguments.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#barrel">barrel ([namespace=_G])</a></td>
<td class="summary">A <a href="http://dictionary.reference.com/browse/barrel+of+monkeys">barrel of monkey_patches</a>.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#elems">elems (t)</a></td>
<td class="summary">An iterator over all elements of a sequence.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#eval">eval (s)</a></td>
<td class="summary">Evaluate a string as Lua code.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#getmetamethod">getmetamethod (x, n)</a></td>
<td class="summary">Return named metamethod, if any, otherwise <code>nil</code>.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#ielems">ielems (t)</a></td>
<td class="summary">An iterator over the integer keyed elements of a sequence.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#ipairs">ipairs (t)</a></td>
<td class="summary">An iterator over elements of a sequence, until the first <code>nil</code> value.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#ireverse">ireverse (t)</a></td>
<td class="summary">Return a new table with element order reversed.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#monkey_patch">monkey_patch ([namespace=_G])</a></td>
<td class="summary">Overwrite core methods and metamethods with <code>std</code> enhanced versions.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#npairs">npairs (t)</a></td>
<td class="summary">Ordered iterator for integer keyed values.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#pairs">pairs (t)</a></td>
<td class="summary">Enhance core <code>pairs</code> to respect <code>__pairs</code> even in Lua 5.1.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#require">require (module[, min[, too_big[, pattern]]])</a></td>
<td class="summary">Enhance core <code>require</code> to assert version number compatibility.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#ripairs">ripairs (t)</a></td>
<td class="summary">An iterator like ipairs, but in reverse.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#rnpairs">rnpairs (t)</a></td>
<td class="summary">An iterator like npairs, but in reverse.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#tostring">tostring (x)</a></td>
<td class="summary">Enhance core <code>tostring</code> to render table contents as a string.</td>
</tr>
</table>
<h2><a href="#Tables">Tables</a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#std">std</a></td>
<td class="summary">Module table.</td>
</tr>
</table>
<h2><a href="#Metamethods">Metamethods </a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#__index">__index (name)</a></td>
<td class="summary">Lazy loading of stdlib modules.</td>
</tr>
</table>
<br/>
<br/>
<h2 class="section-header "><a name="Functions"></a>Functions</h2>
Methods
<dl class="function">
<dt>
<a name = "assert"></a>
<strong>assert (expect[, f=""[, ...]])</strong>
</dt>
<dd>
Enhance core <code>assert</code> to also allow formatted arguments.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">expect</span>
expression, expected to be <em>truthy</em>
</li>
<li><span class="parameter">f</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.3/manual.html#6.4">string</a></span>
format string
(<em>default</em> "")
</li>
<li><span class="parameter">...</span>
arguments to format
(<em>optional</em>)
</li>
</ul>
<h3>Returns:</h3>
<ol>
value of <em>expect</em>, if <em>truthy</em>
</ol>
<h3>Usage:</h3>
<ul>
<pre class="example">std.<span class="global">assert</span> (expected ~= <span class="keyword">nil</span>, <span class="string">"100% unexpected!"</span>)
std.<span class="global">assert</span> (expected ~= <span class="keyword">nil</span>, <span class="string">"%s unexpected!"</span>, expected)</pre>
</ul>
</dd>
<dt>
<a name = "barrel"></a>
<strong>barrel ([namespace=_G])</strong>
</dt>
<dd>
A <a href="http://dictionary.reference.com/browse/barrel+of+monkeys">barrel of monkey_patches</a>. </p>
<p> Apply <strong>all</strong> <code>monkey_patch</code> functions. Additionally, for backwards
compatibility only, write a selection of sub-module functions into
the given namespace.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">namespace</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.3/manual.html#6.6">table</a></span>
where to install global functions
(<em>default</em> _G)
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.3/manual.html#6.6">table</a></span>
module table
</ol>
<h3>Usage:</h3>
<ul>
<pre class="example"><span class="keyword">local</span> std = <span class="global">require</span> <span class="string">"std"</span>.barrel ()</pre>
</ul>
</dd>
<dt>
<a name = "elems"></a>
<strong>elems (t)</strong>
</dt>
<dd>
An iterator over all elements of a sequence.
If <em>t</em> has a <code>__pairs</code> metamethod, use that to iterate.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">t</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.3/manual.html#6.6">table</a></span>
a table
</li>
</ul>
<h3>Returns:</h3>
<ol>
<li>
<span class="types"><span class="type">function</span></span>
iterator function</li>
<li>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.3/manual.html#6.6">table</a></span>
<em>t</em>, the table being iterated over</li>
<li>
<em>key</em>, the previous iteration key</li>
</ol>
<h3>See also:</h3>
<ul>
<li><a href="../modules/std.html#ielems">ielems</a></li>
<li><a href="../modules/std.html#pairs">pairs</a></li>
</ul>
<h3>Usage:</h3>
<ul>
<pre class="example"><span class="keyword">for</span> value <span class="keyword">in</span> std.elems {a = <span class="number">1</span>, b = <span class="number">2</span>, c = <span class="number">5</span>} <span class="keyword">do</span> process (value) <span class="keyword">end</span></pre>
</ul>
</dd>
<dt>
<a name = "eval"></a>
<strong>eval (s)</strong>
</dt>
<dd>
Evaluate a string as Lua code.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">s</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.3/manual.html#6.4">string</a></span>
string of Lua code
</li>
</ul>
<h3>Returns:</h3>
<ol>
result of evaluating <code>s</code>
</ol>
<h3>Usage:</h3>
<ul>
<pre class="example">std.eval <span class="string">"math.min (2, 10)"</span></pre>
</ul>
</dd>
<dt>
<a name = "getmetamethod"></a>
<strong>getmetamethod (x, n)</strong>
</dt>
<dd>
Return named metamethod, if any, otherwise <code>nil</code>.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">x</span>
item to act on
</li>
<li><span class="parameter">n</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.3/manual.html#6.4">string</a></span>
name of metamethod to lookup
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><span class="type">function</span> or <span class="type">nil</span></span>
metamethod function, or <code>nil</code> if no metamethod
</ol>
<h3>Usage:</h3>
<ul>
<pre class="example">lookup = std.getmetamethod (<span class="global">require</span> <span class="string">"std.object"</span>, <span class="string">"__index"</span>)</pre>
</ul>
</dd>
<dt>
<a name = "ielems"></a>
<strong>ielems (t)</strong>
</dt>
<dd>
An iterator over the integer keyed elements of a sequence.
If <em>t</em> has a <code>__len</code> metamethod, iterate up to the index it returns.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">t</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.3/manual.html#6.6">table</a></span>
a table
</li>
</ul>
<h3>Returns:</h3>
<ol>
<li>
<span class="types"><span class="type">function</span></span>
iterator function</li>
<li>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.3/manual.html#6.6">table</a></span>
<em>t</em>, the table being iterated over</li>
<li>
<span class="types"><span class="type">int</span></span>
<em>index</em>, the previous iteration index</li>
</ol>
<h3>See also:</h3>
<ul>
<li><a href="../modules/std.html#elems">elems</a></li>
<li><a href="../modules/std.html#ipairs">ipairs</a></li>
</ul>
<h3>Usage:</h3>
<ul>
<pre class="example"><span class="keyword">for</span> v <span class="keyword">in</span> std.ielems {<span class="string">"a"</span>, <span class="string">"b"</span>, <span class="string">"c"</span>} <span class="keyword">do</span> process (v) <span class="keyword">end</span></pre>
</ul>
</dd>
<dt>
<a name = "ipairs"></a>
<strong>ipairs (t)</strong>
</dt>
<dd>
An iterator over elements of a sequence, until the first <code>nil</code> value. </p>
<p> Like Lua 5.1 and 5.3, but unlike Lua 5.2 (which looks for and uses the
<code>__ipairs</code> metamethod), this iterator returns successive key-value
pairs with integer keys starting at 1, up to the first <code>nil</code> valued
pair.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">t</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.3/manual.html#6.6">table</a></span>
a table
</li>
</ul>
<h3>Returns:</h3>
<ol>
<li>
<span class="types"><span class="type">function</span></span>
iterator function</li>
<li>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.3/manual.html#6.6">table</a></span>
<em>t</em>, the table being iterated over</li>
<li>
<span class="types"><span class="type">int</span></span>
<em>index</em>, the previous iteration index</li>
</ol>
<h3>See also:</h3>
<ul>
<li><a href="../modules/std.html#ielems">ielems</a></li>
<li><a href="../modules/std.html#npairs">npairs</a></li>
<li><a href="../modules/std.html#pairs">pairs</a></li>
</ul>
<h3>Usage:</h3>
<ul>
<pre class="example"><span class="comment">-- length of sequence
</span>args = {<span class="string">"first"</span>, <span class="string">"second"</span>, <span class="keyword">nil</span>, <span class="string">"last"</span>}
<span class="comment">--> 1=first
</span><span class="comment">--> 2=second
</span><span class="keyword">for</span> i, v <span class="keyword">in</span> std.<span class="global">ipairs</span> (args) <span class="keyword">do</span>
<span class="global">print</span> (<span class="global">string</span>.format (<span class="string">"%d=%s"</span>, i, v))
<span class="keyword">end</span></pre>
</ul>
</dd>
<dt>
<a name = "ireverse"></a>
<strong>ireverse (t)</strong>
</dt>
<dd>
Return a new table with element order reversed.
Apart from the order of the elments returned, this function follows
the same rules as <a href="../modules/std.html#ipairs">ipairs</a> for determining first and last elements.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">t</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.3/manual.html#6.6">table</a></span>
a table
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.3/manual.html#6.6">table</a></span>
a new table with integer keyed elements in reverse
order with respect to <em>t</em>
</ol>
<h3>See also:</h3>
<ul>
<li><a href="../modules/std.html#ielems">ielems</a></li>
<li><a href="../modules/std.html#ipairs">ipairs</a></li>
</ul>
<h3>Usage:</h3>
<ul>
<pre class="example"><span class="keyword">local</span> rielems = std.functional.compose (std.ireverse, std.ielems)
<span class="keyword">for</span> e <span class="keyword">in</span> rielems (l) <span class="keyword">do</span> process (e) <span class="keyword">end</span></pre>
</ul>
</dd>
<dt>
<a name = "monkey_patch"></a>
<strong>monkey_patch ([namespace=_G])</strong>
</dt>
<dd>
Overwrite core methods and metamethods with <code>std</code> enhanced versions. </p>
<p> Write all functions from this module, except <code>std.barrel</code> and
<code>std.monkey_patch</code>, into the given namespace.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">namespace</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.3/manual.html#6.6">table</a></span>
where to install global functions
(<em>default</em> _G)
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.3/manual.html#6.6">table</a></span>
the module table
</ol>
<h3>Usage:</h3>
<ul>
<pre class="example"><span class="keyword">local</span> std = <span class="global">require</span> <span class="string">"std"</span>.monkey_patch ()</pre>
</ul>
</dd>
<dt>
<a name = "npairs"></a>
<strong>npairs (t)</strong>
</dt>
<dd>
Ordered iterator for integer keyed values.
Like ipairs, but does not stop until the largest integer key.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">t</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.3/manual.html#6.6">table</a></span>
a table
</li>
</ul>
<h3>Returns:</h3>
<ol>
<li>
<span class="types"><span class="type">function</span></span>
iterator function</li>
<li>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.3/manual.html#6.6">table</a></span>
t</li>
</ol>
<h3>See also:</h3>
<ul>
<li><a href="../modules/std.html#ipairs">ipairs</a></li>
<li><a href="../modules/std.html#rnpairs">rnpairs</a></li>
</ul>
<h3>Usage:</h3>
<ul>
<pre class="example"><span class="keyword">for</span> i,v <span class="keyword">in</span> npairs {<span class="string">"one"</span>, <span class="keyword">nil</span>, <span class="string">"three"</span>} <span class="keyword">do</span> ... <span class="keyword">end</span></pre>
</ul>
</dd>
<dt>
<a name = "pairs"></a>
<strong>pairs (t)</strong>
</dt>
<dd>
Enhance core <code>pairs</code> to respect <code>__pairs</code> even in Lua 5.1.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">t</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.3/manual.html#6.6">table</a></span>
a table
</li>
</ul>
<h3>Returns:</h3>
<ol>
<li>
<span class="types"><span class="type">function</span></span>
iterator function</li>
<li>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.3/manual.html#6.6">table</a></span>
<em>t</em>, the table being iterated over</li>
<li>
<em>key</em>, the previous iteration key</li>
</ol>
<h3>See also:</h3>
<ul>
<li><a href="../modules/std.html#elems">elems</a></li>
<li><a href="../modules/std.html#ipairs">ipairs</a></li>
</ul>
<h3>Usage:</h3>
<ul>
<pre class="example"><span class="keyword">for</span> k, v <span class="keyword">in</span> <span class="global">pairs</span> {<span class="string">"a"</span>, b = <span class="string">"c"</span>, foo = <span class="number">42</span>} <span class="keyword">do</span> process (k, v) <span class="keyword">end</span></pre>
</ul>
</dd>
<dt>
<a name = "require"></a>
<strong>require (module[, min[, too_big[, pattern]]])</strong>
</dt>
<dd>
Enhance core <code>require</code> to assert version number compatibility.
By default match against the last substring of (dot-delimited)
digits in the module version string.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">module</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.3/manual.html#6.4">string</a></span>
module to require
</li>
<li><span class="parameter">min</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.3/manual.html#6.4">string</a></span>
lowest acceptable version
(<em>optional</em>)
</li>
<li><span class="parameter">too_big</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.3/manual.html#6.4">string</a></span>
lowest version that is too big
(<em>optional</em>)
</li>
<li><span class="parameter">pattern</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.3/manual.html#6.4">string</a></span>
to match version in <code>module.version</code> or
<code>module._VERSION</code> (default: <code>"([%.%d]+)%D*$"</code>)
(<em>optional</em>)
</li>
</ul>
<h3>Usage:</h3>
<ul>
<pre class="example"><span class="comment">-- posix.version == "posix library for Lua 5.2 / 32"
</span>posix = <span class="global">require</span> (<span class="string">"posix"</span>, <span class="string">"29"</span>)</pre>
</ul>
</dd>
<dt>
<a name = "ripairs"></a>
<strong>ripairs (t)</strong>
</dt>
<dd>
An iterator like ipairs, but in reverse.
Apart from the order of the elments returned, this function follows
the same rules as <a href="../modules/std.html#ipairs">ipairs</a> for determining first and last elements.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">t</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.3/manual.html#6.6">table</a></span>
any table
</li>
</ul>
<h3>Returns:</h3>
<ol>
<li>
<span class="types"><span class="type">function</span></span>
iterator function</li>
<li>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.3/manual.html#6.6">table</a></span>
<em>t</em></li>
<li>
<span class="types"><span class="type">number</span></span>
<code>#t + 1</code></li>
</ol>
<h3>See also:</h3>
<ul>
<li><a href="../modules/std.html#ipairs">ipairs</a></li>
<li><a href="../modules/std.html#rnpairs">rnpairs</a></li>
</ul>
<h3>Usage:</h3>
<ul>
<pre class="example"><span class="keyword">for</span> i, v = ripairs (t) <span class="keyword">do</span> ... <span class="keyword">end</span></pre>
</ul>
</dd>
<dt>
<a name = "rnpairs"></a>
<strong>rnpairs (t)</strong>
</dt>
<dd>
An iterator like npairs, but in reverse.
Apart from the order of the elments returned, this function follows
the same rules as <a href="../modules/std.html#npairs">npairs</a> for determining first and last elements.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">t</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.3/manual.html#6.6">table</a></span>
a table
</li>
</ul>
<h3>Returns:</h3>
<ol>
<li>
<span class="types"><span class="type">function</span></span>
iterator function</li>
<li>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.3/manual.html#6.6">table</a></span>
t</li>
</ol>
<h3>See also:</h3>
<ul>
<li><a href="../modules/std.html#npairs">npairs</a></li>
<li><a href="../modules/std.html#ripairs">ripairs</a></li>
</ul>
<h3>Usage:</h3>
<ul>
<pre class="example"><span class="keyword">for</span> i,v <span class="keyword">in</span> rnpairs {<span class="string">"one"</span>, <span class="keyword">nil</span>, <span class="string">"three"</span>} <span class="keyword">do</span> ... <span class="keyword">end</span></pre>
</ul>
</dd>
<dt>
<a name = "tostring"></a>
<strong>tostring (x)</strong>
</dt>
<dd>
Enhance core <code>tostring</code> to render table contents as a string.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">x</span>
object to convert to string
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.3/manual.html#6.4">string</a></span>
compact string rendering of <em>x</em>
</ol>
<h3>Usage:</h3>
<ul>
<pre class="example"><span class="comment">-- {1=baz,foo=bar}
</span><span class="global">print</span> (std.<span class="global">tostring</span> {foo=<span class="string">"bar"</span>,<span class="string">"baz"</span>})</pre>
</ul>
</dd>
</dl>
<h2 class="section-header "><a name="Tables"></a>Tables</h2>
<dl class="function">
<dt>
<a name = "std"></a>
<strong>std</strong>
</dt>
<dd>
Module table. </p>
<p> In addition to the functions documented on this page, and a <code>version</code>
field, references to other submodule functions will be loaded on
demand.
<h3>Fields:</h3>
<ul>
<li><span class="parameter">version</span>
release version string
</li>
</ul>
</dd>
</dl>
<h2 class="section-header "><a name="Metamethods"></a>Metamethods </h2>
<dl class="function">
<dt>
<a name = "__index"></a>
<strong>__index (name)</strong>
</dt>
<dd>
Lazy loading of stdlib modules.
Don't load everything on initial startup, wait until first attempt
to access a submodule, and then load it on demand.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">name</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.3/manual.html#6.4">string</a></span>
submodule name
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.3/manual.html#6.6">table</a> or <span class="type">nil</span></span>
the submodule that was loaded to satisfy the missing
<code>name</code>, otherwise <code>nil</code> if nothing was found
</ol>
<h3>Usage:</h3>
<ul>
<pre class="example"><span class="keyword">local</span> std = <span class="global">require</span> <span class="string">"std"</span>
<span class="keyword">local</span> prototype = std.object.prototype</pre>
</ul>
</dd>
</dl>
</div> <!-- id="content" -->
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
<i style="float:right;">Last updated 2018-09-16 19:20:25 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
</html>