forked from lua-stdlib/lua-stdlib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstd.debug.html
More file actions
857 lines (688 loc) · 28 KB
/
std.debug.html
File metadata and controls
857 lines (688 loc) · 28 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
844
845
846
847
848
849
850
851
852
853
854
855
856
857
<!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="#Fields">Fields</a></li>
</ul>
<h2>Modules</h2>
<ul class="$(kind=='Topics' and '' or 'nowrap'">
<li><a href="../modules/std.html">std</a></li>
<li><strong>std.debug</strong></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="$(kind=='Topics' and '' or '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.debug</code></h1>
<p>Additions to the core debug module.</p>
<p> The module table returned by <code>std.debug</code> also contains all of the entries
from the core debug table. An hygienic way to import this module, then, is
simply to override the core <code>debug</code> locally:</p>
<pre>
<span class="keyword">local</span> <span class="global">debug</span> = <span class="global">require</span> <span class="string">"std.debug"</span>
</pre>
<p> The behaviour of the functions in this module are controlled by the value
of the global <code>_DEBUG</code>. Not setting <code>_DEBUG</code> prior to requiring <strong>any</strong> of
stdlib's modules is equivalent to having <code>_DEBUG = true</code>.</p>
<p> The first line of Lua code in production quality projects that use stdlib
should be either:</p>
<pre>
_DEBUG = <span class="keyword">false</span>
</pre>
<p> or alternatively, if you need to be careful not to damage the global
environment:</p>
<pre>
<span class="keyword">local</span> init = <span class="global">require</span> <span class="string">"std.debug_init"</span>
init._DEBUG = <span class="keyword">false</span>
</pre>
<p> This mitigates almost all of the overhead of argument typechecking in
stdlib API functions.</p>
<h2><a href="#Functions">Functions</a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#DEPRECATED">DEPRECATED (version, name[, extramsg], fn)</a></td>
<td class="summary">Provide a deprecated function definition according to _DEBUG.deprecate.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#DEPRECATIONMSG">DEPRECATIONMSG (version, name[, extramsg], level)</a></td>
<td class="summary">Format a deprecation warning message.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#argcheck">argcheck (name, i, expected, actual[, level=2])</a></td>
<td class="summary">Check the type of an argument against expected types.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#argerror">argerror (name, i[, extramsg[, level=1]])</a></td>
<td class="summary">Raise a bad argument error.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#argscheck">argscheck (decl, inner)</a></td>
<td class="summary">Wrap a function definition with argument type and arity checking.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#debug">debug ()</a></td>
<td class="summary">Equivalent to calling <code>debug.say (1, ...)</code></td>
</tr>
<tr>
<td class="name" nowrap><a href="#extramsg_mismatch">extramsg_mismatch (expected, actual[, index])</a></td>
<td class="summary">Format a type mismatch error.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#parsetypes">parsetypes (types)</a></td>
<td class="summary">Compact permutation list into a list of valid types at each argument.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#say">say ([n=1], ...)</a></td>
<td class="summary">Print a debugging message to <code>io.stderr</code>.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#trace">trace (event)</a></td>
<td class="summary">Trace function calls.</td>
</tr>
</table>
<h2><a href="#Tables">Tables</a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#_DEBUG">_DEBUG</a></td>
<td class="summary">Control std.debug function behaviour.</td>
</tr>
</table>
<h2><a href="#Fields">Fields</a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#extramsg_toomany">extramsg_toomany</a></td>
<td class="summary">Format a too many things error.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#getfenv">getfenv</a></td>
<td class="summary">Extend <code>debug.getfenv</code> to unwrap functables correctly.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#resulterror">resulterror</a></td>
<td class="summary">Raise a bad result error.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#setfenv">setfenv</a></td>
<td class="summary">Extend <code>debug.setfenv</code> to unwrap functables correctly.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#typesplit">typesplit</a></td>
<td class="summary">Split a typespec string into a table of normalized type names.</td>
</tr>
</table>
<br/>
<br/>
<h2><a name="Functions"></a>Functions</h2>
Methods
<dl class="function">
<dt>
<a name = "DEPRECATED"></a>
<strong>DEPRECATED (version, name[, extramsg], fn)</strong>
</dt>
<dd>
Provide a deprecated function definition according to _DEBUG.deprecate.
You can check whether your covered code uses deprecated functions by
setting <code>_DEBUG.deprecate</code> to <code>true</code> before loading any stdlib modules,
or silence deprecation warnings by setting <code>_DEBUG.deprecate = false</code>.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">version</span>
<span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
first deprecation release version
</li>
<li><span class="parameter">name</span>
<span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
function name for automatic warning message
</li>
<li><span class="parameter">extramsg</span>
<span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
additional warning text
(<em>optional</em>)
</li>
<li><span class="parameter">fn</span>
<span class="types"><span class="type">func</span></span>
deprecated function
</li>
</ul>
<h3>Returns:</h3>
<ol>
a function to show the warning on first call, and hand off to <em>fn</em>
</ol>
<h3>Usage:</h3>
<ul>
<pre class="example">M.op = DEPRECATED (<span class="string">"41"</span>, <span class="string">"'std.functional.op'"</span>, std.operator)</pre>
</ul>
</dd>
<dt>
<a name = "DEPRECATIONMSG"></a>
<strong>DEPRECATIONMSG (version, name[, extramsg], level)</strong>
</dt>
<dd>
Format a deprecation warning message.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">version</span>
<span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
first deprecation release version
</li>
<li><span class="parameter">name</span>
<span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
function name for automatic warning message
</li>
<li><span class="parameter">extramsg</span>
<span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
additional warning text
(<em>optional</em>)
</li>
<li><span class="parameter">level</span>
<span class="types"><span class="type">int</span></span>
call stack level to blame for the error
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
deprecation warning message, or empty string
</ol>
<h3>Usage:</h3>
<ul>
<pre class="example"><span class="global">io</span>.stderr:write (DEPRECATIONMSG (<span class="string">"42"</span>, <span class="string">"multi-argument 'module.fname'"</span>, <span class="number">2</span>))</pre>
</ul>
</dd>
<dt>
<a name = "argcheck"></a>
<strong>argcheck (name, i, expected, actual[, level=2])</strong>
</dt>
<dd>
Check the type of an argument against expected types.
Equivalent to luaL_argcheck in the Lua C API.</p>
<p> Call <code>argerror</code> if there is a type mismatch.</p>
<p> Argument <code>actual</code> must match one of the types from in <code>expected</code>, each
of which can be the name of a primitive Lua type, a stdlib object type,
or one of the special options below:</p>
<pre><code>#table accept any non-empty table
any accept any non-nil argument type
file accept an open file object
function accept a function, or object with a __call metamethod
int accept an integer valued number
list accept a table where all keys are a contiguous 1-based integer range
#list accept any non-empty list
object accept any std.Object derived type
:foo accept only the exact string ":foo", works for any :-prefixed string
</code></pre>
<p> The <code>:foo</code> format allows for type-checking of self-documenting
boolean-like constant string parameters predicated on <code>nil</code> versus
<code>:option</code> instead of <code>false</code> versus <code>true</code>. Or you could support
both:</p>
<pre><code>argcheck ("table.copy", 2, "boolean|:nometa|nil", nometa)
</code></pre>
<p> A very common pattern is to have a list of possible types including
"nil" when the argument is optional. Rather than writing long-hand
as above, prepend a question mark to the list of types and omit the
explicit "nil" entry:</p>
<pre><code>argcheck ("table.copy", 2, "?boolean|:nometa", predicate)
</code></pre>
<p> Normally, you should not need to use the <code>level</code> parameter, as the
default is to blame the caller of the function using <code>argcheck</code> in
error messages; which is almost certainly what you want.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">name</span>
<span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
function to blame in error message
</li>
<li><span class="parameter">i</span>
<span class="types"><span class="type">int</span></span>
argument number to blame in error message
</li>
<li><span class="parameter">expected</span>
<span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
specification for acceptable argument types
</li>
<li><span class="parameter">actual</span>
argument passed
</li>
<li><span class="parameter">level</span>
<span class="types"><span class="type">int</span></span>
call stack level to blame for the error
(<em>default</em> 2)
</li>
</ul>
<h3>Usage:</h3>
<ul>
<pre class="example">
<span class="keyword">local</span> <span class="keyword">function</span> case (with, branches)
argcheck (<span class="string">"std.functional.case"</span>, <span class="number">2</span>, <span class="string">"#table"</span>, branches)
...</pre>
</ul>
</dd>
<dt>
<a name = "argerror"></a>
<strong>argerror (name, i[, extramsg[, level=1]])</strong>
</dt>
<dd>
Raise a bad argument error.
Equivalent to luaL_argerror in the Lua C API. This function does not
return. The <code>level</code> argument behaves just like the core <code>error</code>
function.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">name</span>
<span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
function to callout in error message
</li>
<li><span class="parameter">i</span>
<span class="types"><span class="type">int</span></span>
argument number
</li>
<li><span class="parameter">extramsg</span>
<span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
additional text to append to message inside parentheses
(<em>optional</em>)
</li>
<li><span class="parameter">level</span>
<span class="types"><span class="type">int</span></span>
call stack level to blame for the error
(<em>default</em> 1)
</li>
</ul>
<h3>See also:</h3>
<ul>
<li><a href="../modules/std.debug.html#resulterror">resulterror</a></li>
<li><a href="../modules/std.debug.html#extramsg_mismatch">extramsg_mismatch</a></li>
</ul>
<h3>Usage:</h3>
<ul>
<pre class="example">
<span class="keyword">local</span> <span class="keyword">function</span> slurp (file)
<span class="keyword">local</span> h, err = input_handle (file)
<span class="keyword">if</span> h == <span class="keyword">nil</span> <span class="keyword">then</span> argerror (<span class="string">"std.io.slurp"</span>, <span class="number">1</span>, err, <span class="number">2</span>) <span class="keyword">end</span>
...</pre>
</ul>
</dd>
<dt>
<a name = "argscheck"></a>
<strong>argscheck (decl, inner)</strong>
</dt>
<dd>
<p>Wrap a function definition with argument type and arity checking.
In addition to checking that each argument type matches the corresponding
element in the <em>types</em> table with <code>argcheck</code>, if the final element of
<em>types</em> ends with an ellipsis, remaining unchecked arguments are checked
against that type:</p>
<pre><code> format = argscheck ("string.format (string, ?any...)", string.format)
</code></pre>
<p> A colon in the function name indicates that the argument type list does
not have a type for <code>self</code>:</p>
<pre><code> format = argscheck ("string:format (?any...)", string.format)
</code></pre>
<p> If an argument can be omitted entirely, then put its type specification
in square brackets:</p>
<pre><code> insert = argscheck ("table.insert (table, [int], ?any)", table.insert)
</code></pre>
<p> Similarly return types can be checked with the same list syntax as
arguments:</p>
<pre><code> len = argscheck ("string.len (string) => int", string.len)
</code></pre>
<p> Additionally, variant return type lists can be listed like this:</p>
<pre><code> open = argscheck ("io.open (string, ?string) => file or nil, string",
io.open)
</code></pre>
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">decl</span>
<span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
function type declaration string
</li>
<li><span class="parameter">inner</span>
<span class="types"><span class="type">func</span></span>
function to wrap with argument checking
</li>
</ul>
<h3>Usage:</h3>
<ul>
<pre class="example">
<span class="keyword">local</span> case = argscheck (<span class="string">"std.functional.case (?any, #table) => [any...]"</span>,
<span class="keyword">function</span> (with, branches)
...
<span class="keyword">end</span>)</pre>
</ul>
</dd>
<dt>
<a name = "debug"></a>
<strong>debug ()</strong>
</dt>
<dd>
Equivalent to calling <code>debug.say (1, ...)</code>
<h3>See also:</h3>
<ul>
<a href="../modules/std.debug.html#say">say</a>
</ul>
<h3>Usage:</h3>
<ul>
<pre class="example">
<span class="keyword">local</span> <span class="global">debug</span> = <span class="global">require</span> <span class="string">"std.debug"</span>
<span class="global">debug</span> <span class="string">"oh noes!"</span></pre>
</ul>
</dd>
<dt>
<a name = "extramsg_mismatch"></a>
<strong>extramsg_mismatch (expected, actual[, index])</strong>
</dt>
<dd>
Format a type mismatch error.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">expected</span>
<span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
a pipe delimited list of matchable types
</li>
<li><span class="parameter">actual</span>
the actual argument to match with
</li>
<li><span class="parameter">index</span>
<span class="types"><span class="type">number</span></span>
erroring container element index
(<em>optional</em>)
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
formatted <em>extramsg</em> for this mismatch for <a href="../modules/std.debug.html#argerror">argerror</a>
</ol>
<h3>See also:</h3>
<ul>
<li><a href="../modules/std.debug.html#argerror">argerror</a></li>
<li><a href="../modules/std.debug.html#resulterror">resulterror</a></li>
</ul>
<h3>Usage:</h3>
<ul>
<pre class="example">
<span class="keyword">if</span> fmt ~= <span class="keyword">nil</span> <span class="keyword">and</span> <span class="global">type</span> (fmt) ~= <span class="string">"string"</span> <span class="keyword">then</span>
argerror (<span class="string">"format"</span>, <span class="number">1</span>, extramsg_mismatch (<span class="string">"?string"</span>, fmt))
<span class="keyword">end</span></pre>
</ul>
</dd>
<dt>
<a name = "parsetypes"></a>
<strong>parsetypes (types)</strong>
</dt>
<dd>
Compact permutation list into a list of valid types at each argument.
Eliminate bracketed types by combining all valid types at each position
for all permutations of <em>typelist</em>.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">types</span>
<span class="types"><a class="type" href="../classes/std.list.html">list</a></span>
a normalized list of type names
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><a class="type" href="../classes/std.list.html">list</a></span>
valid types for each positional parameter
</ol>
</dd>
<dt>
<a name = "say"></a>
<strong>say ([n=1], ...)</strong>
</dt>
<dd>
Print a debugging message to <code>io.stderr</code>.
Display arguments passed through <code>std.tostring</code> and separated by tab
characters when <code>_DEBUG</code> is <code>true</code> and <em>n</em> is 1 or less; or <code>_DEBUG.level</code>
is a number greater than or equal to <em>n</em>. If <code>_DEBUG</code> is false or
nil, nothing is written.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">n</span>
<span class="types"><span class="type">int</span></span>
debugging level, smaller is higher priority
(<em>default</em> 1)
</li>
<li><span class="parameter">...</span>
objects to print (as for print)
</li>
</ul>
<h3>Usage:</h3>
<ul>
<pre class="example">
<span class="keyword">local</span> _DEBUG = <span class="global">require</span> <span class="string">"std.debug_init"</span>._DEBUG
_DEBUG.level = <span class="number">3</span>
say (<span class="number">2</span>, <span class="string">"_DEBUG table contents:"</span>, _DEBUG)</pre>
</ul>
</dd>
<dt>
<a name = "trace"></a>
<strong>trace (event)</strong>
</dt>
<dd>
Trace function calls.
Use as debug.sethook (trace, "cr"), which is done automatically
when <code>_DEBUG.call</code> is set.
Based on test/trace-calls.lua from the Lua distribution.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">event</span>
<span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
event causing the call
</li>
</ul>
<h3>Usage:</h3>
<ul>
<pre class="example">
_DEBUG = { call = <span class="keyword">true</span> }
<span class="keyword">local</span> <span class="global">debug</span> = <span class="global">require</span> <span class="string">"std.debug"</span></pre>
</ul>
</dd>
</dl>
<h2><a name="Tables"></a>Tables</h2>
<dl class="function">
<dt>
<a name = "_DEBUG"></a>
<strong>_DEBUG</strong>
</dt>
<dd>
Control std.debug function behaviour.
To declare debugging state, set _DEBUG either to <code>false</code> to disable all
runtime debugging; to any "truthy" value (equivalent to enabling everything
except <em>call</em>, or as documented below.
<h3>Fields:</h3>
<ul>
<li><span class="parameter">argcheck</span>
<span class="types"><span class="type">boolean</span></span>
honor argcheck and argscheck calls
(<em>default</em> true)
</li>
<li><span class="parameter">call</span>
<span class="types"><span class="type">boolean</span></span>
do call trace debugging
(<em>default</em> false)
</li>
<li><span class="parameter">deprecate</span>
if <code>false</code>, deprecated APIs are defined,
and do not issue deprecation warnings when used; if <code>nil</code> issue a
deprecation warning each time a deprecated api is used; any other
value causes deprecated APIs not to be defined at all
(<em>default</em> nil)
</li>
<li><span class="parameter">level</span>
<span class="types"><span class="type">int</span></span>
debugging level
(<em>default</em> 1)
</li>
</ul>
<h3>Usage:</h3>
<ul>
<pre class="example">_DEBUG = { argcheck = <span class="keyword">false</span>, level = <span class="number">9</span> }</pre>
</ul>
</dd>
</dl>
<h2><a name="Fields"></a>Fields</h2>
<dl class="function">
<dt>
<a name = "extramsg_toomany"></a>
<strong>extramsg_toomany</strong>
</dt>
<dd>
Format a too many things error.
<ul>
<li><span class="parameter">bad</span>
<span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
the thing there are too many of
</li>
<li><span class="parameter">expected</span>
<span class="types"><span class="type">int</span></span>
maximum number of <em>bad</em> things expected
</li>
<li><span class="parameter">actual</span>
<span class="types"><span class="type">int</span></span>
actual number of <em>bad</em> things that triggered the error
</li>
</ul>
<h3>See also:</h3>
<ul>
<li><a href="../modules/std.debug.html#argerror">argerror</a></li>
<li><a href="../modules/std.debug.html#resulterror">resulterror</a></li>
<li><a href="../modules/std.debug.html#extramsg_mismatch">extramsg_mismatch</a></li>
</ul>
<h3>Usage:</h3>
<ul>
<pre class="example">
<span class="keyword">if</span> maxn (argt) > <span class="number">7</span> <span class="keyword">then</span>
argerror (<span class="string">"sevenses"</span>, <span class="number">8</span>, extramsg_toomany (<span class="string">"argument"</span>, <span class="number">7</span>, maxn (argt)))
<span class="keyword">end</span></pre>
</ul>
</dd>
<dt>
<a name = "getfenv"></a>
<strong>getfenv</strong>
</dt>
<dd>
Extend <code>debug.getfenv</code> to unwrap functables correctly.
<ul>
<li><span class="parameter">fn</span>
<span class="types"><span class="type">int</span>, <span class="type">function</span> or <span class="type">functable</span></span>
target function, or stack level
</li>
</ul>
</dd>
<dt>
<a name = "resulterror"></a>
<strong>resulterror</strong>
</dt>
<dd>
Raise a bad result error.
Like <a href="../modules/std.debug.html#argerror">argerror</a> for bad results. This function does not
return. The <code>level</code> argument behaves just like the core <code>error</code>
function.
<ul>
<li><span class="parameter">name</span>
<span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
function to callout in error message
</li>
<li><span class="parameter">i</span>
<span class="types"><span class="type">int</span></span>
argument number
</li>
<li><span class="parameter">extramsg</span>
<span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
additional text to append to message inside parentheses
(<em>optional</em>)
</li>
<li><span class="parameter">level</span>
<span class="types"><span class="type">int</span></span>
call stack level to blame for the error
(<em>default</em> 1)
</li>
</ul>
<h3>Usage:</h3>
<ul>
<pre class="example">
<span class="keyword">local</span> <span class="keyword">function</span> slurp (file)
<span class="keyword">local</span> h, err = input_handle (file)
<span class="keyword">if</span> h == <span class="keyword">nil</span> <span class="keyword">then</span> argerror (<span class="string">"std.io.slurp"</span>, <span class="number">1</span>, err, <span class="number">2</span>) <span class="keyword">end</span>
...</pre>
</ul>
</dd>
<dt>
<a name = "setfenv"></a>
<strong>setfenv</strong>
</dt>
<dd>
Extend <code>debug.setfenv</code> to unwrap functables correctly.
<ul>
<li><span class="parameter">fn</span>
<span class="types"><span class="type">function</span> or <span class="type">functable</span></span>
target function
</li>
<li><span class="parameter">env</span>
<span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.5">table</a></span>
new function environment
</li>
</ul>
</dd>
<dt>
<a name = "typesplit"></a>
<strong>typesplit</strong>
</dt>
<dd>
Split a typespec string into a table of normalized type names.
<ul>
<li><span class="parameter">either</span>
<span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a> or <a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.5">table</a></span>
<code>"?bool|:nometa"</code> or <code>{"boolean", ":nometa"}</code>
</li>
</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.3</a></i>
<i style="float:right;">Last updated 2018-09-03 17:48:42</i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
</html>