forked from keyring/Lua52doc_cn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathManualEN.htm
11090 lines (7596 loc) · 326 KB
/
ManualEN.htm
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
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Lua 5.2 Reference Manual</title>
<META HTTP-EQUIV="content-type" CONTENT="text/html; charset=iso-8859-1">
<STYLE TYPE="text/css">
ul {
list-style-type: none ;
list-style-position: outside ;
}
HTML {
BACKGROUND-COLOR: #f8f8f8
}
BODY {
BORDER-BOTTOM: #a0a0a0 1px solid; TEXT-ALIGN: justify; BORDER-LEFT: #a0a0a0 1px solid; PADDING-BOTTOM: 26px; BACKGROUND-COLOR: #ffffff; MARGIN: 16px; PADDING-LEFT: 26px; PADDING-RIGHT: 26px; FONT-FAMILY: Helvetica, Arial, sans-serif; COLOR: #000000; BORDER-TOP: #a0a0a0 1px solid; BORDER-RIGHT: #a0a0a0 1px solid; PADDING-TOP: 26px; border-radius: 20px
}
H1 {
FONT-STYLE: normal; FONT-FAMILY: Verdana, Geneva, sans-serif; FONT-WEIGHT: normal
}
H2 {
FONT-STYLE: normal; FONT-FAMILY: Verdana, Geneva, sans-serif; FONT-WEIGHT: normal
}
H3 {
FONT-STYLE: normal; FONT-FAMILY: Verdana, Geneva, sans-serif; FONT-WEIGHT: normal
}
H4 {
FONT-STYLE: normal; FONT-FAMILY: Verdana, Geneva, sans-serif; FONT-WEIGHT: normal
}
H1 {
FONT-STYLE: italic
}
H2 {
BORDER-BOTTOM: #000080 1px solid; BORDER-LEFT: #000080 1px solid; PADDING-BOTTOM: 0.4em; BACKGROUND-COLOR: #e0e0ff; PADDING-LEFT: 0.8em; PADDING-RIGHT: 0.8em; BORDER-TOP: #000080 1px solid; BORDER-RIGHT: #000080 1px solid; PADDING-TOP: 0.4em; border-radius: 8px
}
H3 {
BORDER-LEFT: #e0e0ff 1em solid; PADDING-LEFT: 0.5em
}
TABLE H3 {
BORDER-LEFT: medium none; PADDING-LEFT: 0px
}
A:link {
COLOR: #000080; TEXT-DECORATION: none
}
A:visited {
TEXT-DECORATION: none
}
A:hover:link {
BACKGROUND-COLOR: #e0e0ff; COLOR: #000080
}
A:hover:visited {
BACKGROUND-COLOR: #e0e0ff; COLOR: #000080
}
A:active {
COLOR: #ff0000
}
A:active {
COLOR: #ff0000
}
HR {
BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; BACKGROUND-COLOR: #a0a0a0; DISPLAY: none; HEIGHT: 1px; COLOR: #a0a0a0; BORDER-TOP: 0px; BORDER-RIGHT: 0px
}
TABLE HR {
DISPLAY: block
}
:unknown {
BORDER-BOTTOM: #a0a0a0 2px solid; BORDER-LEFT: #a0a0a0 2px solid; PADDING-BOTTOM: 8px; BACKGROUND-COLOR: #f8f8f8; PADDING-LEFT: 8px; PADDING-RIGHT: 8px; BORDER-TOP: #a0a0a0 2px solid; BORDER-RIGHT: #a0a0a0 2px solid; PADDING-TOP: 8px
}
.footer {
COLOR: gray; FONT-SIZE: x-small
}
INPUT[type=text] {
BACKGROUND-IMAGE: url(images/search.png); BORDER-BOTTOM: #a0a0a0 2px solid; BORDER-LEFT: #a0a0a0 2px solid; PADDING-LEFT: 20px; BACKGROUND-REPEAT: no-repeat; BACKGROUND-POSITION: 4px center; HEIGHT: 2em; BORDER-TOP: #a0a0a0 2px solid; BORDER-RIGHT: #a0a0a0 2px solid; border-radius: 2em; -moz-border-radius: 2em
}
H1 {
FONT-STYLE: normal
}
H3 CODE {
FONT-FAMILY: inherit
}
PRE {
FONT-SIZE: 12pt
}
CODE {
FONT-SIZE: 12pt
}
SPAN.apii {
FONT-STYLE: normal; FONT-FAMILY: inherit; FLOAT: right; COLOR: gray; FONT-SIZE: small
}
P + H1 {
PADDING-BOTTOM: 0.4em; BACKGROUND-COLOR: #e0e0ff; PADDING-LEFT: 16px; MARGIN-LEFT: -16px; PADDING-TOP: 0.4em; border-radius: 8px
}
UL + H1 {
PADDING-BOTTOM: 0.4em; BACKGROUND-COLOR: #e0e0ff; PADDING-LEFT: 16px; MARGIN-LEFT: -16px; PADDING-TOP: 0.4em; border-radius: 8px
}
</STYLE>
</head>
<body>
<hr>
<h1>
<a href="http://www.lua.org/home.html"><img src="data:image/gif;base64,R0lGODdhgACAAPcAAAAAcgAAdgAAegAAfQcHfgkJf29vb3FxcXZ2dnp6en9/fwEBgAQEgQgIgwsLhA4Ogg8PhQ4OhhERhRYWhxERiBUVihkZihoajB0dix0djSEhjiUljyIikCUlkSkpkiwskzU1lzExlTU1mTExmDo6mjo6nD8/nUJCn0REnkJCoEVFoUpKo0hIpExMo01NpVBQp1RUplFRqFdXq1lZqlparFxcq15erWBgr2NjsWdnsWlps2pqs29vt2xstHFxt3Z2u3R0uXl5u3t7vX9/v35+vYKCgoWFhYiIiI6OjpCQkJWVlZubm52dnYCAv6GhoaWlpampqa2trbOzs7e3t7m5ub29vYODwYeHwomJw4uLxY6OxpCQx5KSyJWVypmZy5mZzJ+fz6Ghz6Ki0aWl0qmp06mp1K2t1q+v17Gx17Gx2LW12ru73by83cPDw8fHx8rKyszMzMDA39LS0tXV1djY2N3d3cHB4MfH48fH5MnJ5MrK5c7O5tDQ59PT6dXV6tjY69ra7N3d7uHh4eXl5eDg7+rq6u7u7uLi8Obm8+jo8+np9O7u9vHx8fDw9/X19fPz+ff3+/n5+fv7/f///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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IBJQAEZjCJslkQhfCdH0ozntMHZqAFP4ADMeACLMACL3ADP4A7fVhWNfoQUYCYFyVIMVoQNEoTbXAAT1CbN6ITZNE9T/QECsB5OyEI05FwZXEhRgCm+xEJUFAtZYFLZnekv+kubHoQcGCaLREJavmmA9EGCGAEb0ClpgQHRVBPdiqRUpAAeoaGElVQBAogBXUaqAPBCKeFElNABanEqA4hBUngBk8qEYVQBeFFqRhBB09gBAlwBFz6EJEQqgpQBArqqRgxCHs6EIOABEwQBVOAppNQB1VABVGwBB7qelLQBpnKqiM0BVDABEeQYIeKl04QrMLarM76rNAardLqEQEBADs=" alt="Home" border="0"></a>
Lua 5.2 Reference Manual
</h1>
by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes
<p>
<small>
Copyright © 2011–2013 Lua.org, PUC-Rio.
Freely available under the terms of the
<a href="http://www.lua.org/license.html">Lua license</a>.
</small>
<hr>
<p>
<A HREF="#1">start</A>
·
<a href="#contents">contents</A>
·
<a href="#index">index</A>
·
<a href="index.htm">Chinese version</A>
<!-- ====================================================================== -->
<p>
<!-- $Id: manual.of,v 1.103 2013/03/14 18:51:56 roberto Exp $ -->
<H2><A NAME="contents">Contents</A></H2>
<UL style="padding: 0">
<LI><A HREF="#1">1 – Introduction</A>
<P>
<LI><A HREF="#2">2 – Basic Concepts</A>
<UL>
<LI><A HREF="#2.1">2.1 – Values and Types</A>
<LI><A HREF="#2.2">2.2 – Environments and the Global Environment</A>
<LI><A HREF="#2.3">2.3 – Error Handling</A>
<LI><A HREF="#2.4">2.4 – Metatables and Metamethods</A>
<LI><A HREF="#2.5">2.5 – Garbage Collection</A>
<UL>
<LI><A HREF="#2.5.1">2.5.1 – Garbage-Collection Metamethods</A>
<LI><A HREF="#2.5.2">2.5.2 – Weak Tables</A>
</UL>
<LI><A HREF="#2.6">2.6 – Coroutines</A>
</UL>
<P>
<LI><A HREF="#3">3 – The Language</A>
<UL>
<LI><A HREF="#3.1">3.1 – Lexical Conventions</A>
<LI><A HREF="#3.2">3.2 – Variables</A>
<LI><A HREF="#3.3">3.3 – Statements</A>
<UL>
<LI><A HREF="#3.3.1">3.3.1 – Blocks</A>
<LI><A HREF="#3.3.2">3.3.2 – Chunks</A>
<LI><A HREF="#3.3.3">3.3.3 – Assignment</A>
<LI><A HREF="#3.3.4">3.3.4 – Control Structures</A>
<LI><A HREF="#3.3.5">3.3.5 – For Statement</A>
<LI><A HREF="#3.3.6">3.3.6 – Function Calls as Statements</A>
<LI><A HREF="#3.3.7">3.3.7 – Local Declarations</A>
</UL>
<LI><A HREF="#3.4">3.4 – Expressions</A>
<UL>
<LI><A HREF="#3.4.1">3.4.1 – Arithmetic Operators</A>
<LI><A HREF="#3.4.2">3.4.2 – Coercion</A>
<LI><A HREF="#3.4.3">3.4.3 – Relational Operators</A>
<LI><A HREF="#3.4.4">3.4.4 – Logical Operators</A>
<LI><A HREF="#3.4.5">3.4.5 – Concatenation</A>
<LI><A HREF="#3.4.6">3.4.6 – The Length Operator</A>
<LI><A HREF="#3.4.7">3.4.7 – Precedence</A>
<LI><A HREF="#3.4.8">3.4.8 – Table Constructors</A>
<LI><A HREF="#3.4.9">3.4.9 – Function Calls</A>
<LI><A HREF="#3.4.10">3.4.10 – Function Definitions</A>
</UL>
<LI><A HREF="#3.5">3.5 – Visibility Rules</A>
</UL>
<P>
<LI><A HREF="#4">4 – The Application Program Interface</A>
<UL>
<LI><A HREF="#4.1">4.1 – The Stack</A>
<LI><A HREF="#4.2">4.2 – Stack Size</A>
<LI><A HREF="#4.3">4.3 – Valid and Acceptable Indices</A>
<LI><A HREF="#4.4">4.4 – C Closures</A>
<LI><A HREF="#4.5">4.5 – Registry</A>
<LI><A HREF="#4.6">4.6 – Error Handling in C</A>
<LI><A HREF="#4.7">4.7 – Handling Yields in C</A>
<LI><A HREF="#4.8">4.8 – Functions and Types</A>
<LI><A HREF="#4.9">4.9 – The Debug Interface</A>
</UL>
<P>
<LI><A HREF="#5">5 – The Auxiliary Library</A>
<UL>
<LI><A HREF="#5.1">5.1 – Functions and Types</A>
</UL>
<P>
<LI><A HREF="#6">6 – Standard Libraries</A>
<UL>
<LI><A HREF="#6.1">6.1 – Basic Functions</A>
<LI><A HREF="#6.2">6.2 – Coroutine Manipulation</A>
<LI><A HREF="#6.3">6.3 – Modules</A>
<LI><A HREF="#6.4">6.4 – String Manipulation</A>
<UL>
<LI><A HREF="#6.4.1">6.4.1 – Patterns</A>
</UL>
<LI><A HREF="#6.5">6.5 – Table Manipulation</A>
<LI><A HREF="#6.6">6.6 – Mathematical Functions</A>
<LI><A HREF="#6.7">6.7 – Bitwise Operations</A>
<LI><A HREF="#6.8">6.8 – Input and Output Facilities</A>
<LI><A HREF="#6.9">6.9 – Operating System Facilities</A>
<LI><A HREF="#6.10">6.10 – The Debug Library</A>
</UL>
<P>
<LI><A HREF="#7">7 – Lua Standalone</A>
<P>
<LI><A HREF="#8">8 – Incompatibilities with the Previous Version</A>
<UL>
<LI><A HREF="#8.1">8.1 – Changes in the Language</A>
<LI><A HREF="#8.2">8.2 – Changes in the Libraries</A>
<LI><A HREF="#8.3">8.3 – Changes in the API</A>
</UL>
<P>
<LI><A HREF="#9">9 – The Complete Syntax of Lua</A>
</UL>
<H2><A NAME="index">Index</A></H2>
<TABLE WIDTH="100%">
<TR VALIGN="top">
<TD>
<H3><A NAME="functions">Lua functions</A></H3>
<P>
<A HREF="#pdf-_G">_G</A><BR>
<A HREF="#pdf-_VERSION">_VERSION</A><BR>
<P>
<A HREF="#pdf-assert">assert</A><BR>
<A HREF="#pdf-collectgarbage">collectgarbage</A><BR>
<A HREF="#pdf-dofile">dofile</A><BR>
<A HREF="#pdf-error">error</A><BR>
<A HREF="#pdf-getmetatable">getmetatable</A><BR>
<A HREF="#pdf-ipairs">ipairs</A><BR>
<A HREF="#pdf-load">load</A><BR>
<A HREF="#pdf-loadfile">loadfile</A><BR>
<A HREF="#pdf-next">next</A><BR>
<A HREF="#pdf-pairs">pairs</A><BR>
<A HREF="#pdf-pcall">pcall</A><BR>
<A HREF="#pdf-print">print</A><BR>
<A HREF="#pdf-rawequal">rawequal</A><BR>
<A HREF="#pdf-rawget">rawget</A><BR>
<A HREF="#pdf-rawlen">rawlen</A><BR>
<A HREF="#pdf-rawset">rawset</A><BR>
<A HREF="#pdf-require">require</A><BR>
<A HREF="#pdf-select">select</A><BR>
<A HREF="#pdf-setmetatable">setmetatable</A><BR>
<A HREF="#pdf-tonumber">tonumber</A><BR>
<A HREF="#pdf-tostring">tostring</A><BR>
<A HREF="#pdf-type">type</A><BR>
<A HREF="#pdf-xpcall">xpcall</A><BR>
<P>
<A HREF="#pdf-bit32.arshift">bit32.arshift</A><BR>
<A HREF="#pdf-bit32.band">bit32.band</A><BR>
<A HREF="#pdf-bit32.bnot">bit32.bnot</A><BR>
<A HREF="#pdf-bit32.bor">bit32.bor</A><BR>
<A HREF="#pdf-bit32.btest">bit32.btest</A><BR>
<A HREF="#pdf-bit32.bxor">bit32.bxor</A><BR>
<A HREF="#pdf-bit32.extract">bit32.extract</A><BR>
<A HREF="#pdf-bit32.lrotate">bit32.lrotate</A><BR>
<A HREF="#pdf-bit32.lshift">bit32.lshift</A><BR>
<A HREF="#pdf-bit32.replace">bit32.replace</A><BR>
<A HREF="#pdf-bit32.rrotate">bit32.rrotate</A><BR>
<A HREF="#pdf-bit32.rshift">bit32.rshift</A><BR>
<P>
<A HREF="#pdf-coroutine.create">coroutine.create</A><BR>
<A HREF="#pdf-coroutine.resume">coroutine.resume</A><BR>
<A HREF="#pdf-coroutine.running">coroutine.running</A><BR>
<A HREF="#pdf-coroutine.status">coroutine.status</A><BR>
<A HREF="#pdf-coroutine.wrap">coroutine.wrap</A><BR>
<A HREF="#pdf-coroutine.yield">coroutine.yield</A><BR>
<P>
<A HREF="#pdf-debug.debug">debug.debug</A><BR>
<A HREF="#pdf-debug.getuservalue">debug.getuservalue</A><BR>
<A HREF="#pdf-debug.gethook">debug.gethook</A><BR>
<A HREF="#pdf-debug.getinfo">debug.getinfo</A><BR>
<A HREF="#pdf-debug.getlocal">debug.getlocal</A><BR>
<A HREF="#pdf-debug.getmetatable">debug.getmetatable</A><BR>
<A HREF="#pdf-debug.getregistry">debug.getregistry</A><BR>
<A HREF="#pdf-debug.getupvalue">debug.getupvalue</A><BR>
<A HREF="#pdf-debug.setuservalue">debug.setuservalue</A><BR>
<A HREF="#pdf-debug.sethook">debug.sethook</A><BR>
<A HREF="#pdf-debug.setlocal">debug.setlocal</A><BR>
<A HREF="#pdf-debug.setmetatable">debug.setmetatable</A><BR>
<A HREF="#pdf-debug.setupvalue">debug.setupvalue</A><BR>
<A HREF="#pdf-debug.traceback">debug.traceback</A><BR>
<A HREF="#pdf-debug.upvalueid">debug.upvalueid</A><BR>
<A HREF="#pdf-debug.upvaluejoin">debug.upvaluejoin</A><BR>
<P>
<A HREF="#pdf-file:close">file:close</A><BR>
<A HREF="#pdf-file:flush">file:flush</A><BR>
<A HREF="#pdf-file:lines">file:lines</A><BR>
<A HREF="#pdf-file:read">file:read</A><BR>
<A HREF="#pdf-file:seek">file:seek</A><BR>
<A HREF="#pdf-file:setvbuf">file:setvbuf</A><BR>
<A HREF="#pdf-file:write">file:write</A><BR>
<P>
<A HREF="#pdf-io.close">io.close</A><BR>
<A HREF="#pdf-io.flush">io.flush</A><BR>
<A HREF="#pdf-io.input">io.input</A><BR>
<A HREF="#pdf-io.lines">io.lines</A><BR>
<A HREF="#pdf-io.open">io.open</A><BR>
<A HREF="#pdf-io.output">io.output</A><BR>
<A HREF="#pdf-io.popen">io.popen</A><BR>
<A HREF="#pdf-io.read">io.read</A><BR>
<A HREF="#pdf-io.stderr">io.stderr</A><BR>
<A HREF="#pdf-io.stdin">io.stdin</A><BR>
<A HREF="#pdf-io.stdout">io.stdout</A><BR>
<A HREF="#pdf-io.tmpfile">io.tmpfile</A><BR>
<A HREF="#pdf-io.type">io.type</A><BR>
<A HREF="#pdf-io.write">io.write</A><BR>
</TD>
<TD>
<H3> </H3>
<P>
<A HREF="#pdf-math.abs">math.abs</A><BR>
<A HREF="#pdf-math.acos">math.acos</A><BR>
<A HREF="#pdf-math.asin">math.asin</A><BR>
<A HREF="#pdf-math.atan">math.atan</A><BR>
<A HREF="#pdf-math.atan2">math.atan2</A><BR>
<A HREF="#pdf-math.ceil">math.ceil</A><BR>
<A HREF="#pdf-math.cos">math.cos</A><BR>
<A HREF="#pdf-math.cosh">math.cosh</A><BR>
<A HREF="#pdf-math.deg">math.deg</A><BR>
<A HREF="#pdf-math.exp">math.exp</A><BR>
<A HREF="#pdf-math.floor">math.floor</A><BR>
<A HREF="#pdf-math.fmod">math.fmod</A><BR>
<A HREF="#pdf-math.frexp">math.frexp</A><BR>
<A HREF="#pdf-math.huge">math.huge</A><BR>
<A HREF="#pdf-math.ldexp">math.ldexp</A><BR>
<A HREF="#pdf-math.log">math.log</A><BR>
<A HREF="#pdf-math.max">math.max</A><BR>
<A HREF="#pdf-math.min">math.min</A><BR>
<A HREF="#pdf-math.modf">math.modf</A><BR>
<A HREF="#pdf-math.pi">math.pi</A><BR>
<A HREF="#pdf-math.pow">math.pow</A><BR>
<A HREF="#pdf-math.rad">math.rad</A><BR>
<A HREF="#pdf-math.random">math.random</A><BR>
<A HREF="#pdf-math.randomseed">math.randomseed</A><BR>
<A HREF="#pdf-math.sin">math.sin</A><BR>
<A HREF="#pdf-math.sinh">math.sinh</A><BR>
<A HREF="#pdf-math.sqrt">math.sqrt</A><BR>
<A HREF="#pdf-math.tan">math.tan</A><BR>
<A HREF="#pdf-math.tanh">math.tanh</A><BR>
<P>
<A HREF="#pdf-os.clock">os.clock</A><BR>
<A HREF="#pdf-os.date">os.date</A><BR>
<A HREF="#pdf-os.difftime">os.difftime</A><BR>
<A HREF="#pdf-os.execute">os.execute</A><BR>
<A HREF="#pdf-os.exit">os.exit</A><BR>
<A HREF="#pdf-os.getenv">os.getenv</A><BR>
<A HREF="#pdf-os.remove">os.remove</A><BR>
<A HREF="#pdf-os.rename">os.rename</A><BR>
<A HREF="#pdf-os.setlocale">os.setlocale</A><BR>
<A HREF="#pdf-os.time">os.time</A><BR>
<A HREF="#pdf-os.tmpname">os.tmpname</A><BR>
<P>
<A HREF="#pdf-package.config">package.config</A><BR>
<A HREF="#pdf-package.cpath">package.cpath</A><BR>
<A HREF="#pdf-package.loaded">package.loaded</A><BR>
<A HREF="#pdf-package.loadlib">package.loadlib</A><BR>
<A HREF="#pdf-package.path">package.path</A><BR>
<A HREF="#pdf-package.preload">package.preload</A><BR>
<A HREF="#pdf-package.searchers">package.searchers</A><BR>
<A HREF="#pdf-package.searchpath">package.searchpath</A><BR>
<P>
<A HREF="#pdf-string.byte">string.byte</A><BR>
<A HREF="#pdf-string.char">string.char</A><BR>
<A HREF="#pdf-string.dump">string.dump</A><BR>
<A HREF="#pdf-string.find">string.find</A><BR>
<A HREF="#pdf-string.format">string.format</A><BR>
<A HREF="#pdf-string.gmatch">string.gmatch</A><BR>
<A HREF="#pdf-string.gsub">string.gsub</A><BR>
<A HREF="#pdf-string.len">string.len</A><BR>
<A HREF="#pdf-string.lower">string.lower</A><BR>
<A HREF="#pdf-string.match">string.match</A><BR>
<A HREF="#pdf-string.rep">string.rep</A><BR>
<A HREF="#pdf-string.reverse">string.reverse</A><BR>
<A HREF="#pdf-string.sub">string.sub</A><BR>
<A HREF="#pdf-string.upper">string.upper</A><BR>
<P>
<A HREF="#pdf-table.concat">table.concat</A><BR>
<A HREF="#pdf-table.insert">table.insert</A><BR>
<A HREF="#pdf-table.pack">table.pack</A><BR>
<A HREF="#pdf-table.remove">table.remove</A><BR>
<A HREF="#pdf-table.sort">table.sort</A><BR>
<A HREF="#pdf-table.unpack">table.unpack</A><BR>
</TD>
<TD>
<H3>C API</H3>
<P>
<A HREF="#lua_Alloc">lua_Alloc</A><BR>
<A HREF="#lua_CFunction">lua_CFunction</A><BR>
<A HREF="#lua_Debug">lua_Debug</A><BR>
<A HREF="#lua_Hook">lua_Hook</A><BR>
<A HREF="#lua_Integer">lua_Integer</A><BR>
<A HREF="#lua_Number">lua_Number</A><BR>
<A HREF="#lua_Reader">lua_Reader</A><BR>
<A HREF="#lua_State">lua_State</A><BR>
<A HREF="#lua_Unsigned">lua_Unsigned</A><BR>
<A HREF="#lua_Writer">lua_Writer</A><BR>
<P>
<A HREF="#lua_absindex">lua_absindex</A><BR>
<A HREF="#lua_arith">lua_arith</A><BR>
<A HREF="#lua_atpanic">lua_atpanic</A><BR>
<A HREF="#lua_call">lua_call</A><BR>
<A HREF="#lua_callk">lua_callk</A><BR>
<A HREF="#lua_checkstack">lua_checkstack</A><BR>
<A HREF="#lua_close">lua_close</A><BR>
<A HREF="#lua_compare">lua_compare</A><BR>
<A HREF="#lua_concat">lua_concat</A><BR>
<A HREF="#lua_copy">lua_copy</A><BR>
<A HREF="#lua_createtable">lua_createtable</A><BR>
<A HREF="#lua_dump">lua_dump</A><BR>
<A HREF="#lua_error">lua_error</A><BR>
<A HREF="#lua_gc">lua_gc</A><BR>
<A HREF="#lua_getallocf">lua_getallocf</A><BR>
<A HREF="#lua_getctx">lua_getctx</A><BR>
<A HREF="#lua_getfield">lua_getfield</A><BR>
<A HREF="#lua_getglobal">lua_getglobal</A><BR>
<A HREF="#lua_gethook">lua_gethook</A><BR>
<A HREF="#lua_gethookcount">lua_gethookcount</A><BR>
<A HREF="#lua_gethookmask">lua_gethookmask</A><BR>
<A HREF="#lua_getinfo">lua_getinfo</A><BR>
<A HREF="#lua_getlocal">lua_getlocal</A><BR>
<A HREF="#lua_getmetatable">lua_getmetatable</A><BR>
<A HREF="#lua_getstack">lua_getstack</A><BR>
<A HREF="#lua_gettable">lua_gettable</A><BR>
<A HREF="#lua_gettop">lua_gettop</A><BR>
<A HREF="#lua_getupvalue">lua_getupvalue</A><BR>
<A HREF="#lua_getuservalue">lua_getuservalue</A><BR>
<A HREF="#lua_insert">lua_insert</A><BR>
<A HREF="#lua_isboolean">lua_isboolean</A><BR>
<A HREF="#lua_iscfunction">lua_iscfunction</A><BR>
<A HREF="#lua_isfunction">lua_isfunction</A><BR>
<A HREF="#lua_islightuserdata">lua_islightuserdata</A><BR>
<A HREF="#lua_isnil">lua_isnil</A><BR>
<A HREF="#lua_isnone">lua_isnone</A><BR>
<A HREF="#lua_isnoneornil">lua_isnoneornil</A><BR>
<A HREF="#lua_isnumber">lua_isnumber</A><BR>
<A HREF="#lua_isstring">lua_isstring</A><BR>
<A HREF="#lua_istable">lua_istable</A><BR>
<A HREF="#lua_isthread">lua_isthread</A><BR>
<A HREF="#lua_isuserdata">lua_isuserdata</A><BR>
<A HREF="#lua_len">lua_len</A><BR>
<A HREF="#lua_load">lua_load</A><BR>
<A HREF="#lua_newstate">lua_newstate</A><BR>
<A HREF="#lua_newtable">lua_newtable</A><BR>
<A HREF="#lua_newthread">lua_newthread</A><BR>
<A HREF="#lua_newuserdata">lua_newuserdata</A><BR>
<A HREF="#lua_next">lua_next</A><BR>
<A HREF="#lua_pcall">lua_pcall</A><BR>
<A HREF="#lua_pcallk">lua_pcallk</A><BR>
<A HREF="#lua_pop">lua_pop</A><BR>
<A HREF="#lua_pushboolean">lua_pushboolean</A><BR>
<A HREF="#lua_pushcclosure">lua_pushcclosure</A><BR>
<A HREF="#lua_pushcfunction">lua_pushcfunction</A><BR>
<A HREF="#lua_pushfstring">lua_pushfstring</A><BR>
<A HREF="#lua_pushglobaltable">lua_pushglobaltable</A><BR>
<A HREF="#lua_pushinteger">lua_pushinteger</A><BR>
<A HREF="#lua_pushlightuserdata">lua_pushlightuserdata</A><BR>
<A HREF="#lua_pushliteral">lua_pushliteral</A><BR>
<A HREF="#lua_pushlstring">lua_pushlstring</A><BR>
<A HREF="#lua_pushnil">lua_pushnil</A><BR>
<A HREF="#lua_pushnumber">lua_pushnumber</A><BR>
<A HREF="#lua_pushstring">lua_pushstring</A><BR>
<A HREF="#lua_pushthread">lua_pushthread</A><BR>
<A HREF="#lua_pushunsigned">lua_pushunsigned</A><BR>
<A HREF="#lua_pushvalue">lua_pushvalue</A><BR>
<A HREF="#lua_pushvfstring">lua_pushvfstring</A><BR>
<A HREF="#lua_rawequal">lua_rawequal</A><BR>
<A HREF="#lua_rawget">lua_rawget</A><BR>
<A HREF="#lua_rawgeti">lua_rawgeti</A><BR>
<A HREF="#lua_rawgetp">lua_rawgetp</A><BR>
<A HREF="#lua_rawlen">lua_rawlen</A><BR>
<A HREF="#lua_rawset">lua_rawset</A><BR>
<A HREF="#lua_rawseti">lua_rawseti</A><BR>
<A HREF="#lua_rawsetp">lua_rawsetp</A><BR>
<A HREF="#lua_register">lua_register</A><BR>
<A HREF="#lua_remove">lua_remove</A><BR>
<A HREF="#lua_replace">lua_replace</A><BR>
<A HREF="#lua_resume">lua_resume</A><BR>
<A HREF="#lua_setallocf">lua_setallocf</A><BR>
<A HREF="#lua_setfield">lua_setfield</A><BR>
<A HREF="#lua_setglobal">lua_setglobal</A><BR>
<A HREF="#lua_sethook">lua_sethook</A><BR>
<A HREF="#lua_setlocal">lua_setlocal</A><BR>
<A HREF="#lua_setmetatable">lua_setmetatable</A><BR>
<A HREF="#lua_settable">lua_settable</A><BR>
<A HREF="#lua_settop">lua_settop</A><BR>
<A HREF="#lua_setupvalue">lua_setupvalue</A><BR>
<A HREF="#lua_setuservalue">lua_setuservalue</A><BR>
<A HREF="#lua_status">lua_status</A><BR>
<A HREF="#lua_toboolean">lua_toboolean</A><BR>
<A HREF="#lua_tocfunction">lua_tocfunction</A><BR>
<A HREF="#lua_tointeger">lua_tointeger</A><BR>
<A HREF="#lua_tointegerx">lua_tointegerx</A><BR>
<A HREF="#lua_tolstring">lua_tolstring</A><BR>
<A HREF="#lua_tonumber">lua_tonumber</A><BR>
<A HREF="#lua_tonumberx">lua_tonumberx</A><BR>
<A HREF="#lua_topointer">lua_topointer</A><BR>
<A HREF="#lua_tostring">lua_tostring</A><BR>
<A HREF="#lua_tothread">lua_tothread</A><BR>
<A HREF="#lua_tounsigned">lua_tounsigned</A><BR>
<A HREF="#lua_tounsignedx">lua_tounsignedx</A><BR>
<A HREF="#lua_touserdata">lua_touserdata</A><BR>
<A HREF="#lua_type">lua_type</A><BR>
<A HREF="#lua_typename">lua_typename</A><BR>
<A HREF="#lua_upvalueid">lua_upvalueid</A><BR>
<A HREF="#lua_upvalueindex">lua_upvalueindex</A><BR>
<A HREF="#lua_upvaluejoin">lua_upvaluejoin</A><BR>
<A HREF="#lua_version">lua_version</A><BR>
<A HREF="#lua_xmove">lua_xmove</A><BR>
<A HREF="#lua_yield">lua_yield</A><BR>
<A HREF="#lua_yieldk">lua_yieldk</A><BR>
</TD>
<TD>
<H3>auxiliary library</H3>
<P>
<A HREF="#luaL_Buffer">luaL_Buffer</A><BR>
<A HREF="#luaL_Reg">luaL_Reg</A><BR>
<P>
<A HREF="#luaL_addchar">luaL_addchar</A><BR>
<A HREF="#luaL_addlstring">luaL_addlstring</A><BR>
<A HREF="#luaL_addsize">luaL_addsize</A><BR>
<A HREF="#luaL_addstring">luaL_addstring</A><BR>
<A HREF="#luaL_addvalue">luaL_addvalue</A><BR>
<A HREF="#luaL_argcheck">luaL_argcheck</A><BR>
<A HREF="#luaL_argerror">luaL_argerror</A><BR>
<A HREF="#luaL_buffinit">luaL_buffinit</A><BR>
<A HREF="#luaL_buffinitsize">luaL_buffinitsize</A><BR>
<A HREF="#luaL_callmeta">luaL_callmeta</A><BR>
<A HREF="#luaL_checkany">luaL_checkany</A><BR>
<A HREF="#luaL_checkint">luaL_checkint</A><BR>
<A HREF="#luaL_checkinteger">luaL_checkinteger</A><BR>
<A HREF="#luaL_checklong">luaL_checklong</A><BR>
<A HREF="#luaL_checklstring">luaL_checklstring</A><BR>
<A HREF="#luaL_checknumber">luaL_checknumber</A><BR>
<A HREF="#luaL_checkoption">luaL_checkoption</A><BR>
<A HREF="#luaL_checkstack">luaL_checkstack</A><BR>
<A HREF="#luaL_checkstring">luaL_checkstring</A><BR>
<A HREF="#luaL_checktype">luaL_checktype</A><BR>
<A HREF="#luaL_checkudata">luaL_checkudata</A><BR>
<A HREF="#luaL_checkunsigned">luaL_checkunsigned</A><BR>
<A HREF="#luaL_checkversion">luaL_checkversion</A><BR>
<A HREF="#luaL_dofile">luaL_dofile</A><BR>
<A HREF="#luaL_dostring">luaL_dostring</A><BR>
<A HREF="#luaL_error">luaL_error</A><BR>
<A HREF="#luaL_execresult">luaL_execresult</A><BR>
<A HREF="#luaL_fileresult">luaL_fileresult</A><BR>
<A HREF="#luaL_getmetafield">luaL_getmetafield</A><BR>
<A HREF="#luaL_getmetatable">luaL_getmetatable</A><BR>
<A HREF="#luaL_getsubtable">luaL_getsubtable</A><BR>
<A HREF="#luaL_gsub">luaL_gsub</A><BR>
<A HREF="#luaL_len">luaL_len</A><BR>
<A HREF="#luaL_loadbuffer">luaL_loadbuffer</A><BR>
<A HREF="#luaL_loadbufferx">luaL_loadbufferx</A><BR>
<A HREF="#luaL_loadfile">luaL_loadfile</A><BR>
<A HREF="#luaL_loadfilex">luaL_loadfilex</A><BR>
<A HREF="#luaL_loadstring">luaL_loadstring</A><BR>
<A HREF="#luaL_newlib">luaL_newlib</A><BR>
<A HREF="#luaL_newlibtable">luaL_newlibtable</A><BR>
<A HREF="#luaL_newmetatable">luaL_newmetatable</A><BR>
<A HREF="#luaL_newstate">luaL_newstate</A><BR>
<A HREF="#luaL_openlibs">luaL_openlibs</A><BR>
<A HREF="#luaL_optint">luaL_optint</A><BR>
<A HREF="#luaL_optinteger">luaL_optinteger</A><BR>
<A HREF="#luaL_optlong">luaL_optlong</A><BR>
<A HREF="#luaL_optlstring">luaL_optlstring</A><BR>
<A HREF="#luaL_optnumber">luaL_optnumber</A><BR>
<A HREF="#luaL_optstring">luaL_optstring</A><BR>
<A HREF="#luaL_optunsigned">luaL_optunsigned</A><BR>
<A HREF="#luaL_prepbuffer">luaL_prepbuffer</A><BR>
<A HREF="#luaL_prepbuffsize">luaL_prepbuffsize</A><BR>
<A HREF="#luaL_pushresult">luaL_pushresult</A><BR>
<A HREF="#luaL_pushresultsize">luaL_pushresultsize</A><BR>
<A HREF="#luaL_ref">luaL_ref</A><BR>
<A HREF="#luaL_requiref">luaL_requiref</A><BR>
<A HREF="#luaL_setfuncs">luaL_setfuncs</A><BR>
<A HREF="#luaL_setmetatable">luaL_setmetatable</A><BR>
<A HREF="#luaL_testudata">luaL_testudata</A><BR>
<A HREF="#luaL_tolstring">luaL_tolstring</A><BR>
<A HREF="#luaL_traceback">luaL_traceback</A><BR>
<A HREF="#luaL_typename">luaL_typename</A><BR>
<A HREF="#luaL_unref">luaL_unref</A><BR>
<A HREF="#luaL_where">luaL_where</A><BR>
</TD>
</TR>
</TABLE>
<HR>
<h1>1 – <a name="1">Introduction</a></h1>
<p>
Lua is an extension programming language designed to support
general procedural programming with data description
facilities.
It also offers good support for object-oriented programming,
functional programming, and data-driven programming.
Lua is intended to be used as a powerful, lightweight,
embeddable scripting language for any program that needs one.
Lua is implemented as a library, written in <em>clean C</em>,
the common subset of Standard C and C++.
<p>
Being an extension language, Lua has no notion of a "main" program:
it only works <em>embedded</em> in a host client,
called the <em>embedding program</em> or simply the <em>host</em>.
The host program can invoke functions to execute a piece of Lua code,
can write and read Lua variables,
and can register C functions to be called by Lua code.
Through the use of C functions, Lua can be augmented to cope with
a wide range of different domains,
thus creating customized programming languages sharing a syntactical framework.
The Lua distribution includes a sample host program called <code>lua</code>,
which uses the Lua library to offer a complete, standalone Lua interpreter,
for interactive or batch use.
<p>
Lua is free software,
and is provided as usual with no guarantees,
as stated in its license.
The implementation described in this manual is available
at Lua's official web site, <code>www.lua.org</code>.
<p>
Like any other reference manual,
this document is dry in places.
For a discussion of the decisions behind the design of Lua,
see the technical papers available at Lua's web site.
For a detailed introduction to programming in Lua,
see Roberto's book, <em>Programming in Lua</em>.
<h1>2 – <a name="2">Basic Concepts</a></h1>
<p>
This section describes the basic concepts of the language.
<h2>2.1 – <a name="2.1">Values and Types</a></h2>
<p>
Lua is a <em>dynamically typed language</em>.
This means that
variables do not have types; only values do.
There are no type definitions in the language.
All values carry their own type.
<p>
All values in Lua are <em>first-class values</em>.
This means that all values can be stored in variables,
passed as arguments to other functions, and returned as results.
<p>
There are eight basic types in Lua:
<em>nil</em>, <em>boolean</em>, <em>number</em>,
<em>string</em>, <em>function</em>, <em>userdata</em>,
<em>thread</em>, and <em>table</em>.
<em>Nil</em> is the type of the value <b>nil</b>,
whose main property is to be different from any other value;
it usually represents the absence of a useful value.
<em>Boolean</em> is the type of the values <b>false</b> and <b>true</b>.
Both <b>nil</b> and <b>false</b> make a condition false;
any other value makes it true.
<em>Number</em> represents real (double-precision floating-point) numbers.
Operations on numbers follow the same rules of
the underlying C implementation,
which, in turn, usually follows the IEEE 754 standard.
(It is easy to build Lua interpreters that use other
internal representations for numbers,
such as single-precision floats or long integers;
see file <code>luaconf.h</code>.)
<em>String</em> represents immutable sequences of bytes.
Lua is 8-bit clean:
strings can contain any 8-bit value,
including embedded zeros ('<code>\0</code>').
<p>
Lua can call (and manipulate) functions written in Lua and
functions written in C
(see <a href="#3.4.9">§3.4.9</a>).
<p>
The type <em>userdata</em> is provided to allow arbitrary C data to
be stored in Lua variables.
A userdata value is a pointer to a block of raw memory.
There are two kinds of userdata:
full userdata, where the block of memory is managed by Lua,
and light userdata, where the block of memory is managed by the host.
Userdata has no predefined operations in Lua,
except assignment and identity test.
By using <em>metatables</em>,
the programmer can define operations for full userdata values
(see <a href="#2.4">§2.4</a>).
Userdata values cannot be created or modified in Lua,
only through the C API.
This guarantees the integrity of data owned by the host program.
<p>
The type <em>thread</em> represents independent threads of execution
and it is used to implement coroutines (see <a href="#2.6">§2.6</a>).
Do not confuse Lua threads with operating-system threads.
Lua supports coroutines on all systems,
even those that do not support threads.
<p>
The type <em>table</em> implements associative arrays,
that is, arrays that can be indexed not only with numbers,
but with any Lua value except <b>nil</b> and NaN
(<em>Not a Number</em>, a special numeric value used to represent
undefined or unrepresentable results, such as <code>0/0</code>).
Tables can be <em>heterogeneous</em>;
that is, they can contain values of all types (except <b>nil</b>).
Any key with value <b>nil</b> is not considered part of the table.
Conversely, any key that is not part of a table has
an associated value <b>nil</b>.
<p>
Tables are the sole data structuring mechanism in Lua;
they can be used to represent ordinary arrays, sequences,
symbol tables, sets, records, graphs, trees, etc.
To represent records, Lua uses the field name as an index.
The language supports this representation by
providing <code>a.name</code> as syntactic sugar for <code>a["name"]</code>.
There are several convenient ways to create tables in Lua
(see <a href="#3.4.8">§3.4.8</a>).
<p>
We use the term <em>sequence</em> to denote a table where
the set of all positive numeric keys is equal to <em>{1..n}</em>
for some integer <em>n</em>,
which is called the length of the sequence (see <a href="#3.4.6">§3.4.6</a>).
<p>
Like indices,
the values of table fields can be of any type.
In particular,
because functions are first-class values,
table fields can contain functions.
Thus tables can also carry <em>methods</em> (see <a href="#3.4.10">§3.4.10</a>).
<p>
The indexing of tables follows
the definition of raw equality in the language.
The expressions <code>a[i]</code> and <code>a[j]</code>
denote the same table element
if and only if <code>i</code> and <code>j</code> are raw equal
(that is, equal without metamethods).
<p>
Tables, functions, threads, and (full) userdata values are <em>objects</em>:
variables do not actually <em>contain</em> these values,
only <em>references</em> to them.
Assignment, parameter passing, and function returns
always manipulate references to such values;
these operations do not imply any kind of copy.
<p>
The library function <a href="#pdf-type"><code>type</code></a> returns a string describing the type
of a given value (see <a href="#6.1">§6.1</a>).
<h2>2.2 – <a name="2.2">Environments and the Global Environment</a></h2>
<p>
As will be discussed in <a href="#3.2">§3.2</a> and <a href="#3.3.3">§3.3.3</a>,
any reference to a global name <code>var</code> is syntactically translated
to <code>_ENV.var</code>.
Moreover, every chunk is compiled in the scope of
an external local variable called <code>_ENV</code> (see <a href="#3.3.2">§3.3.2</a>),
so <code>_ENV</code> itself is never a global name in a chunk.
<p>
Despite the existence of this external <code>_ENV</code> variable and
the translation of global names,
<code>_ENV</code> is a completely regular name.
In particular,
you can define new variables and parameters with that name.
Each reference to a global name uses the <code>_ENV</code> that is
visible at that point in the program,
following the usual visibility rules of Lua (see <a href="#3.5">§3.5</a>).
<p>
Any table used as the value of <code>_ENV</code> is called an <em>environment</em>.
<p>
Lua keeps a distinguished environment called the <em>global environment</em>.
This value is kept at a special index in the C registry (see <a href="#4.5">§4.5</a>).
In Lua, the variable <a href="#pdf-_G"><code>_G</code></a> is initialized with this same value.
<p>
When Lua compiles a chunk,
it initializes the value of its <code>_ENV</code> upvalue
with the global environment (see <a href="#pdf-load"><code>load</code></a>).
Therefore, by default,
global variables in Lua code refer to entries in the global environment.
Moreover, all standard libraries are loaded in the global environment
and several functions there operate on that environment.
You can use <a href="#pdf-load"><code>load</code></a> (or <a href="#pdf-loadfile"><code>loadfile</code></a>)
to load a chunk with a different environment.
(In C, you have to load the chunk and then change the value
of its first upvalue.)
<p>
If you change the global environment in the registry
(through C code or the debug library),
all chunks loaded after the change will get the new environment.
Previously loaded chunks are not affected, however,
as each has its own reference to the environment in its <code>_ENV</code> variable.
Moreover, the variable <a href="#pdf-_G"><code>_G</code></a>
(which is stored in the original global environment)
is never updated by Lua.
<h2>2.3 – <a name="2.3">Error Handling</a></h2>
<p>
Because Lua is an embedded extension language,
all Lua actions start from C code in the host program
calling a function from the Lua library (see <a href="#lua_pcall"><code>lua_pcall</code></a>).
Whenever an error occurs during
the compilation or execution of a Lua chunk,
control returns to the host,
which can take appropriate measures
(such as printing an error message).
<p>
Lua code can explicitly generate an error by calling the
<a href="#pdf-error"><code>error</code></a> function.
If you need to catch errors in Lua,
you can use <a href="#pdf-pcall"><code>pcall</code></a> or <a href="#pdf-xpcall"><code>xpcall</code></a>
to call a given function in <em>protected mode</em>.
<p>
Whenever there is an error,
an <em>error object</em> (also called an <em>error message</em>)
is propagated with information about the error.
Lua itself only generates errors where the error object is a string,
but programs may generate errors with
any value for the error object.
<p>
When you use <a href="#pdf-xpcall"><code>xpcall</code></a> or <a href="#lua_pcall"><code>lua_pcall</code></a>,
you may give a <em>message handler</em>
to be called in case of errors.
This function is called with the original error message
and returns a new error message.
It is called before the error unwinds the stack,
so that it can gather more information about the error,
for instance by inspecting the stack and creating a stack traceback.
This message handler is still protected by the protected call;
so, an error inside the message handler
will call the message handler again.
If this loop goes on, Lua breaks it and returns an appropriate message.
<h2>2.4 – <a name="2.4">Metatables and Metamethods</a></h2>
<p>
Every value in Lua can have a <em>metatable</em>.
This <em>metatable</em> is an ordinary Lua table
that defines the behavior of the original value
under certain special operations.
You can change several aspects of the behavior
of operations over a value by setting specific fields in its metatable.
For instance, when a non-numeric value is the operand of an addition,
Lua checks for a function in the field "<code>__add</code>" of the value's metatable.
If it finds one,
Lua calls this function to perform the addition.
<p>
The keys in a metatable are derived from the <em>event</em> names;
the corresponding values are called <em>metamethods</em>.
In the previous example, the event is <code>"add"</code>
and the metamethod is the function that performs the addition.
<p>
You can query the metatable of any value
using the <a href="#pdf-getmetatable"><code>getmetatable</code></a> function.
<p>
You can replace the metatable of tables
using the <a href="#pdf-setmetatable"><code>setmetatable</code></a> function.
You cannot change the metatable of other types from Lua
(except by using the debug library);
you must use the C API for that.
<p>
Tables and full userdata have individual metatables
(although multiple tables and userdata can share their metatables).
Values of all other types share one single metatable per type;
that is, there is one single metatable for all numbers,
one for all strings, etc.
By default, a value has no metatable,
but the string library sets a metatable for the string type (see <a href="#6.4">§6.4</a>).
<p>
A metatable controls how an object behaves in arithmetic operations,
order comparisons, concatenation, length operation, and indexing.
A metatable also can define a function to be called
when a userdata or a table is garbage collected.
When Lua performs one of these operations over a value,
it checks whether this value has a metatable with the corresponding event.
If so, the value associated with that key (the metamethod)
controls how Lua will perform the operation.
<p>
Metatables control the operations listed next.
Each operation is identified by its corresponding name.
The key for each operation is a string with its name prefixed by
two underscores, '<code>__</code>';
for instance, the key for operation "add" is the
string "<code>__add</code>".
<p>
The semantics of these operations is better explained by a Lua function
describing how the interpreter executes the operation.
The code shown here in Lua is only illustrative;
the real behavior is hard coded in the interpreter
and it is much more efficient than this simulation.
All functions used in these descriptions
(<a href="#pdf-rawget"><code>rawget</code></a>, <a href="#pdf-tonumber"><code>tonumber</code></a>, etc.)
are described in <a href="#6.1">§6.1</a>.
In particular, to retrieve the metamethod of a given object,
we use the expression