Mercurial Hosting > luan
annotate docs/manual.html @ 242:b5a926c481a5
Handle first h1 tag differently.
git-svn-id: https://luan-java.googlecode.com/svn/trunk@243 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | hugo.tech@gmail.com <hugo.tech@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Tue, 07 Oct 2014 01:43:07 +0000 |
parents | 852840d64a7f |
children | c912f6de2053 |
rev | line source |
---|---|
239
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2 <html> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4 <head> |
241
852840d64a7f
minor
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
240
diff
changeset
|
5 <title>Luan Reference Manual</title> |
240
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
6 <link rel="stylesheet" type="text/css" href="lua.css"> |
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
7 <link rel="stylesheet" type="text/css" href="manual.css"> |
239
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8 <META HTTP-EQUIV="content-type" CONTENT="text/html; charset=iso-8859-1"> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9 </head> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
11 <body> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
12 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
13 <hr> |
242
b5a926c481a5
Handle first h1 tag differently.
hugo.tech@gmail.com <hugo.tech@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
241
diff
changeset
|
14 <h1 class="main"> |
240
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
15 Luan Reference Manual |
239
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
16 </h1> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
17 |
240
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
18 <P> |
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
19 The reference manual is the official definition of the Luan language. |
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
20 |
239
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
21 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
22 <small> |
240
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
23 Original Copyright © 2011–2013 Lua.org, PUC-Rio. |
239
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
24 Freely available under the terms of the |
240
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
25 <a href="http://www.lua.org/license.html">Lua license</a>. |
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
26 Modified for Luan in 2014. |
239
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
27 </small> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
28 <hr> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
29 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
30 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
31 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
32 <!-- ====================================================================== --> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
33 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
34 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
35 <!-- $Id: manual.of,v 1.103 2013/03/14 18:51:56 roberto Exp $ --> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
36 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
37 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
38 <H2><A NAME="contents">Contents</A></H2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
39 <UL style="padding: 0"> |
240
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
40 <LI><A HREF="#1">1 – Introduction</A> |
239
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
41 <P> |
240
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
42 <LI><A HREF="#2">2 – Basic Concepts</A> |
239
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
43 <UL> |
240
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
44 <LI><A HREF="#2.1">2.1 – Values and Types</A> |
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
45 <LI><A HREF="#2.2">2.2 – Environments and the Global Environment</A> |
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
46 <LI><A HREF="#2.3">2.3 – Error Handling</A> |
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
47 <LI><A HREF="#2.4">2.4 – Metatables and Metamethods</A> |
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
48 <LI><A HREF="#2.5">2.5 – Garbage Collection</A> |
239
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
49 <UL> |
240
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
50 <LI><A HREF="#2.5.1">2.5.1 – Garbage-Collection Metamethods</A> |
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
51 <LI><A HREF="#2.5.2">2.5.2 – Weak Tables</A> |
239
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
52 </UL> |
240
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
53 <LI><A HREF="#2.6">2.6 – Coroutines</A> |
239
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
54 </UL> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
55 <P> |
240
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
56 <LI><A HREF="#3">3 – The Language</A> |
239
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
57 <UL> |
240
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
58 <LI><A HREF="#3.1">3.1 – Lexical Conventions</A> |
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
59 <LI><A HREF="#3.2">3.2 – Variables</A> |
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
60 <LI><A HREF="#3.3">3.3 – Statements</A> |
239
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
61 <UL> |
240
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
62 <LI><A HREF="#3.3.1">3.3.1 – Blocks</A> |
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
63 <LI><A HREF="#3.3.2">3.3.2 – Chunks</A> |
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
64 <LI><A HREF="#3.3.3">3.3.3 – Assignment</A> |
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
65 <LI><A HREF="#3.3.4">3.3.4 – Control Structures</A> |
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
66 <LI><A HREF="#3.3.5">3.3.5 – For Statement</A> |
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
67 <LI><A HREF="#3.3.6">3.3.6 – Function Calls as Statements</A> |
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
68 <LI><A HREF="#3.3.7">3.3.7 – Local Declarations</A> |
239
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
69 </UL> |
240
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
70 <LI><A HREF="#3.4">3.4 – Expressions</A> |
239
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
71 <UL> |
240
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
72 <LI><A HREF="#3.4.1">3.4.1 – Arithmetic Operators</A> |
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
73 <LI><A HREF="#3.4.2">3.4.2 – Coercion</A> |
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
74 <LI><A HREF="#3.4.3">3.4.3 – Relational Operators</A> |
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
75 <LI><A HREF="#3.4.4">3.4.4 – Logical Operators</A> |
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
76 <LI><A HREF="#3.4.5">3.4.5 – Concatenation</A> |
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
77 <LI><A HREF="#3.4.6">3.4.6 – The Length Operator</A> |
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
78 <LI><A HREF="#3.4.7">3.4.7 – Precedence</A> |
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
79 <LI><A HREF="#3.4.8">3.4.8 – Table Constructors</A> |
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
80 <LI><A HREF="#3.4.9">3.4.9 – Function Calls</A> |
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
81 <LI><A HREF="#3.4.10">3.4.10 – Function Definitions</A> |
239
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
82 </UL> |
240
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
83 <LI><A HREF="#3.5">3.5 – Visibility Rules</A> |
239
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
84 </UL> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
85 <P> |
240
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
86 <LI><A HREF="#4">4 – The Application Program Interface</A> |
239
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
87 <UL> |
240
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
88 <LI><A HREF="#4.1">4.1 – The Stack</A> |
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
89 <LI><A HREF="#4.2">4.2 – Stack Size</A> |
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
90 <LI><A HREF="#4.3">4.3 – Valid and Acceptable Indices</A> |
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
91 <LI><A HREF="#4.4">4.4 – C Closures</A> |
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
92 <LI><A HREF="#4.5">4.5 – Registry</A> |
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
93 <LI><A HREF="#4.6">4.6 – Error Handling in C</A> |
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
94 <LI><A HREF="#4.7">4.7 – Handling Yields in C</A> |
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
95 <LI><A HREF="#4.8">4.8 – Functions and Types</A> |
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
96 <LI><A HREF="#4.9">4.9 – The Debug Interface</A> |
239
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
97 </UL> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
98 <P> |
240
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
99 <LI><A HREF="#5">5 – The Auxiliary Library</A> |
239
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
100 <UL> |
240
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
101 <LI><A HREF="#5.1">5.1 – Functions and Types</A> |
239
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
102 </UL> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
103 <P> |
240
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
104 <LI><A HREF="#6">6 – Standard Libraries</A> |
239
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
105 <UL> |
240
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
106 <LI><A HREF="#6.1">6.1 – Basic Functions</A> |
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
107 <LI><A HREF="#6.2">6.2 – Coroutine Manipulation</A> |
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
108 <LI><A HREF="#6.3">6.3 – Modules</A> |
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
109 <LI><A HREF="#6.4">6.4 – String Manipulation</A> |
239
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
110 <UL> |
240
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
111 <LI><A HREF="#6.4.1">6.4.1 – Patterns</A> |
239
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
112 </UL> |
240
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
113 <LI><A HREF="#6.5">6.5 – Table Manipulation</A> |
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
114 <LI><A HREF="#6.6">6.6 – Mathematical Functions</A> |
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
115 <LI><A HREF="#6.7">6.7 – Bitwise Operations</A> |
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
116 <LI><A HREF="#6.8">6.8 – Input and Output Facilities</A> |
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
117 <LI><A HREF="#6.9">6.9 – Operating System Facilities</A> |
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
118 <LI><A HREF="#6.10">6.10 – The Debug Library</A> |
239
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
119 </UL> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
120 <P> |
240
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
121 <LI><A HREF="#7">7 – Lua Standalone</A> |
239
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
122 <P> |
240
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
123 <LI><A HREF="#8">8 – Incompatibilities with the Previous Version</A> |
239
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
124 <UL> |
240
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
125 <LI><A HREF="#8.1">8.1 – Changes in the Language</A> |
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
126 <LI><A HREF="#8.2">8.2 – Changes in the Libraries</A> |
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
127 <LI><A HREF="#8.3">8.3 – Changes in the API</A> |
239
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
128 </UL> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
129 <P> |
240
bcc3911285a2
add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
239
diff
changeset
|
130 <LI><A HREF="#9">9 – The Complete Syntax of Lua</A> |
239
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
131 </UL> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
132 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
133 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
134 <h1>1 – <a name="1">Introduction</a></h1> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
135 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
136 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
137 Lua is an extension programming language designed to support |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
138 general procedural programming with data description |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
139 facilities. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
140 It also offers good support for object-oriented programming, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
141 functional programming, and data-driven programming. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
142 Lua is intended to be used as a powerful, lightweight, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
143 embeddable scripting language for any program that needs one. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
144 Lua is implemented as a library, written in <em>clean C</em>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
145 the common subset of Standard C and C++. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
146 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
147 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
148 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
149 Being an extension language, Lua has no notion of a "main" program: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
150 it only works <em>embedded</em> in a host client, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
151 called the <em>embedding program</em> or simply the <em>host</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
152 The host program can invoke functions to execute a piece of Lua code, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
153 can write and read Lua variables, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
154 and can register C functions to be called by Lua code. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
155 Through the use of C functions, Lua can be augmented to cope with |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
156 a wide range of different domains, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
157 thus creating customized programming languages sharing a syntactical framework. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
158 The Lua distribution includes a sample host program called <code>lua</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
159 which uses the Lua library to offer a complete, standalone Lua interpreter, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
160 for interactive or batch use. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
161 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
162 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
163 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
164 Lua is free software, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
165 and is provided as usual with no guarantees, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
166 as stated in its license. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
167 The implementation described in this manual is available |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
168 at Lua's official web site, <code>www.lua.org</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
169 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
170 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
171 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
172 Like any other reference manual, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
173 this document is dry in places. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
174 For a discussion of the decisions behind the design of Lua, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
175 see the technical papers available at Lua's web site. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
176 For a detailed introduction to programming in Lua, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
177 see Roberto's book, <em>Programming in Lua</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
178 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
179 <h1>2 – <a name="2">Basic Concepts</a></h1> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
180 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
181 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
182 This section describes the basic concepts of the language. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
183 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
184 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
185 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
186 <h2>2.1 – <a name="2.1">Values and Types</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
187 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
188 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
189 Lua is a <em>dynamically typed language</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
190 This means that |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
191 variables do not have types; only values do. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
192 There are no type definitions in the language. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
193 All values carry their own type. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
194 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
195 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
196 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
197 All values in Lua are <em>first-class values</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
198 This means that all values can be stored in variables, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
199 passed as arguments to other functions, and returned as results. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
200 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
201 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
202 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
203 There are eight basic types in Lua: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
204 <em>nil</em>, <em>boolean</em>, <em>number</em>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
205 <em>string</em>, <em>function</em>, <em>userdata</em>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
206 <em>thread</em>, and <em>table</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
207 <em>Nil</em> is the type of the value <b>nil</b>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
208 whose main property is to be different from any other value; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
209 it usually represents the absence of a useful value. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
210 <em>Boolean</em> is the type of the values <b>false</b> and <b>true</b>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
211 Both <b>nil</b> and <b>false</b> make a condition false; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
212 any other value makes it true. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
213 <em>Number</em> represents real (double-precision floating-point) numbers. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
214 Operations on numbers follow the same rules of |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
215 the underlying C implementation, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
216 which, in turn, usually follows the IEEE 754 standard. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
217 (It is easy to build Lua interpreters that use other |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
218 internal representations for numbers, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
219 such as single-precision floats or long integers; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
220 see file <code>luaconf.h</code>.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
221 <em>String</em> represents immutable sequences of bytes. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
222 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
223 Lua is 8-bit clean: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
224 strings can contain any 8-bit value, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
225 including embedded zeros ('<code>\0</code>'). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
226 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
227 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
228 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
229 Lua can call (and manipulate) functions written in Lua and |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
230 functions written in C |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
231 (see <a href="#3.4.9">§3.4.9</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
232 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
233 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
234 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
235 The type <em>userdata</em> is provided to allow arbitrary C data to |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
236 be stored in Lua variables. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
237 A userdata value is a pointer to a block of raw memory. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
238 There are two kinds of userdata: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
239 full userdata, where the block of memory is managed by Lua, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
240 and light userdata, where the block of memory is managed by the host. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
241 Userdata has no predefined operations in Lua, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
242 except assignment and identity test. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
243 By using <em>metatables</em>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
244 the programmer can define operations for full userdata values |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
245 (see <a href="#2.4">§2.4</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
246 Userdata values cannot be created or modified in Lua, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
247 only through the C API. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
248 This guarantees the integrity of data owned by the host program. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
249 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
250 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
251 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
252 The type <em>thread</em> represents independent threads of execution |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
253 and it is used to implement coroutines (see <a href="#2.6">§2.6</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
254 Do not confuse Lua threads with operating-system threads. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
255 Lua supports coroutines on all systems, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
256 even those that do not support threads. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
257 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
258 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
259 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
260 The type <em>table</em> implements associative arrays, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
261 that is, arrays that can be indexed not only with numbers, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
262 but with any Lua value except <b>nil</b> and NaN |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
263 (<em>Not a Number</em>, a special numeric value used to represent |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
264 undefined or unrepresentable results, such as <code>0/0</code>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
265 Tables can be <em>heterogeneous</em>; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
266 that is, they can contain values of all types (except <b>nil</b>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
267 Any key with value <b>nil</b> is not considered part of the table. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
268 Conversely, any key that is not part of a table has |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
269 an associated value <b>nil</b>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
270 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
271 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
272 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
273 Tables are the sole data structuring mechanism in Lua; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
274 they can be used to represent ordinary arrays, sequences, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
275 symbol tables, sets, records, graphs, trees, etc. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
276 To represent records, Lua uses the field name as an index. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
277 The language supports this representation by |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
278 providing <code>a.name</code> as syntactic sugar for <code>a["name"]</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
279 There are several convenient ways to create tables in Lua |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
280 (see <a href="#3.4.8">§3.4.8</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
281 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
282 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
283 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
284 We use the term <em>sequence</em> to denote a table where |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
285 the set of all positive numeric keys is equal to <em>{1..n}</em> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
286 for some integer <em>n</em>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
287 which is called the length of the sequence (see <a href="#3.4.6">§3.4.6</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
288 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
289 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
290 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
291 Like indices, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
292 the values of table fields can be of any type. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
293 In particular, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
294 because functions are first-class values, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
295 table fields can contain functions. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
296 Thus tables can also carry <em>methods</em> (see <a href="#3.4.10">§3.4.10</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
297 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
298 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
299 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
300 The indexing of tables follows |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
301 the definition of raw equality in the language. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
302 The expressions <code>a[i]</code> and <code>a[j]</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
303 denote the same table element |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
304 if and only if <code>i</code> and <code>j</code> are raw equal |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
305 (that is, equal without metamethods). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
306 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
307 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
308 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
309 Tables, functions, threads, and (full) userdata values are <em>objects</em>: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
310 variables do not actually <em>contain</em> these values, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
311 only <em>references</em> to them. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
312 Assignment, parameter passing, and function returns |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
313 always manipulate references to such values; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
314 these operations do not imply any kind of copy. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
315 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
316 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
317 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
318 The library function <a href="#pdf-type"><code>type</code></a> returns a string describing the type |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
319 of a given value (see <a href="#6.1">§6.1</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
320 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
321 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
322 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
323 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
324 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
325 <h2>2.2 – <a name="2.2">Environments and the Global Environment</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
326 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
327 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
328 As will be discussed in <a href="#3.2">§3.2</a> and <a href="#3.3.3">§3.3.3</a>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
329 any reference to a global name <code>var</code> is syntactically translated |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
330 to <code>_ENV.var</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
331 Moreover, every chunk is compiled in the scope of |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
332 an external local variable called <code>_ENV</code> (see <a href="#3.3.2">§3.3.2</a>), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
333 so <code>_ENV</code> itself is never a global name in a chunk. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
334 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
335 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
336 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
337 Despite the existence of this external <code>_ENV</code> variable and |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
338 the translation of global names, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
339 <code>_ENV</code> is a completely regular name. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
340 In particular, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
341 you can define new variables and parameters with that name. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
342 Each reference to a global name uses the <code>_ENV</code> that is |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
343 visible at that point in the program, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
344 following the usual visibility rules of Lua (see <a href="#3.5">§3.5</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
345 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
346 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
347 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
348 Any table used as the value of <code>_ENV</code> is called an <em>environment</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
349 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
350 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
351 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
352 Lua keeps a distinguished environment called the <em>global environment</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
353 This value is kept at a special index in the C registry (see <a href="#4.5">§4.5</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
354 In Lua, the variable <a href="#pdf-_G"><code>_G</code></a> is initialized with this same value. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
355 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
356 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
357 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
358 When Lua compiles a chunk, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
359 it initializes the value of its <code>_ENV</code> upvalue |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
360 with the global environment (see <a href="#pdf-load"><code>load</code></a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
361 Therefore, by default, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
362 global variables in Lua code refer to entries in the global environment. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
363 Moreover, all standard libraries are loaded in the global environment |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
364 and several functions there operate on that environment. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
365 You can use <a href="#pdf-load"><code>load</code></a> (or <a href="#pdf-loadfile"><code>loadfile</code></a>) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
366 to load a chunk with a different environment. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
367 (In C, you have to load the chunk and then change the value |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
368 of its first upvalue.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
369 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
370 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
371 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
372 If you change the global environment in the registry |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
373 (through C code or the debug library), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
374 all chunks loaded after the change will get the new environment. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
375 Previously loaded chunks are not affected, however, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
376 as each has its own reference to the environment in its <code>_ENV</code> variable. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
377 Moreover, the variable <a href="#pdf-_G"><code>_G</code></a> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
378 (which is stored in the original global environment) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
379 is never updated by Lua. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
380 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
381 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
382 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
383 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
384 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
385 <h2>2.3 – <a name="2.3">Error Handling</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
386 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
387 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
388 Because Lua is an embedded extension language, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
389 all Lua actions start from C code in the host program |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
390 calling a function from the Lua library (see <a href="#lua_pcall"><code>lua_pcall</code></a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
391 Whenever an error occurs during |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
392 the compilation or execution of a Lua chunk, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
393 control returns to the host, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
394 which can take appropriate measures |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
395 (such as printing an error message). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
396 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
397 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
398 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
399 Lua code can explicitly generate an error by calling the |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
400 <a href="#pdf-error"><code>error</code></a> function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
401 If you need to catch errors in Lua, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
402 you can use <a href="#pdf-pcall"><code>pcall</code></a> or <a href="#pdf-xpcall"><code>xpcall</code></a> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
403 to call a given function in <em>protected mode</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
404 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
405 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
406 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
407 Whenever there is an error, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
408 an <em>error object</em> (also called an <em>error message</em>) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
409 is propagated with information about the error. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
410 Lua itself only generates errors where the error object is a string, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
411 but programs may generate errors with |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
412 any value for the error object. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
413 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
414 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
415 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
416 When you use <a href="#pdf-xpcall"><code>xpcall</code></a> or <a href="#lua_pcall"><code>lua_pcall</code></a>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
417 you may give a <em>message handler</em> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
418 to be called in case of errors. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
419 This function is called with the original error message |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
420 and returns a new error message. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
421 It is called before the error unwinds the stack, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
422 so that it can gather more information about the error, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
423 for instance by inspecting the stack and creating a stack traceback. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
424 This message handler is still protected by the protected call; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
425 so, an error inside the message handler |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
426 will call the message handler again. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
427 If this loop goes on, Lua breaks it and returns an appropriate message. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
428 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
429 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
430 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
431 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
432 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
433 <h2>2.4 – <a name="2.4">Metatables and Metamethods</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
434 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
435 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
436 Every value in Lua can have a <em>metatable</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
437 This <em>metatable</em> is an ordinary Lua table |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
438 that defines the behavior of the original value |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
439 under certain special operations. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
440 You can change several aspects of the behavior |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
441 of operations over a value by setting specific fields in its metatable. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
442 For instance, when a non-numeric value is the operand of an addition, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
443 Lua checks for a function in the field "<code>__add</code>" of the value's metatable. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
444 If it finds one, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
445 Lua calls this function to perform the addition. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
446 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
447 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
448 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
449 The keys in a metatable are derived from the <em>event</em> names; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
450 the corresponding values are called <em>metamethods</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
451 In the previous example, the event is <code>"add"</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
452 and the metamethod is the function that performs the addition. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
453 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
454 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
455 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
456 You can query the metatable of any value |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
457 using the <a href="#pdf-getmetatable"><code>getmetatable</code></a> function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
458 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
459 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
460 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
461 You can replace the metatable of tables |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
462 using the <a href="#pdf-setmetatable"><code>setmetatable</code></a> function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
463 You cannot change the metatable of other types from Lua |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
464 (except by using the debug library); |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
465 you must use the C API for that. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
466 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
467 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
468 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
469 Tables and full userdata have individual metatables |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
470 (although multiple tables and userdata can share their metatables). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
471 Values of all other types share one single metatable per type; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
472 that is, there is one single metatable for all numbers, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
473 one for all strings, etc. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
474 By default, a value has no metatable, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
475 but the string library sets a metatable for the string type (see <a href="#6.4">§6.4</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
476 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
477 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
478 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
479 A metatable controls how an object behaves in arithmetic operations, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
480 order comparisons, concatenation, length operation, and indexing. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
481 A metatable also can define a function to be called |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
482 when a userdata or a table is garbage collected. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
483 When Lua performs one of these operations over a value, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
484 it checks whether this value has a metatable with the corresponding event. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
485 If so, the value associated with that key (the metamethod) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
486 controls how Lua will perform the operation. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
487 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
488 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
489 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
490 Metatables control the operations listed next. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
491 Each operation is identified by its corresponding name. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
492 The key for each operation is a string with its name prefixed by |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
493 two underscores, '<code>__</code>'; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
494 for instance, the key for operation "add" is the |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
495 string "<code>__add</code>". |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
496 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
497 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
498 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
499 The semantics of these operations is better explained by a Lua function |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
500 describing how the interpreter executes the operation. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
501 The code shown here in Lua is only illustrative; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
502 the real behavior is hard coded in the interpreter |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
503 and it is much more efficient than this simulation. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
504 All functions used in these descriptions |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
505 (<a href="#pdf-rawget"><code>rawget</code></a>, <a href="#pdf-tonumber"><code>tonumber</code></a>, etc.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
506 are described in <a href="#6.1">§6.1</a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
507 In particular, to retrieve the metamethod of a given object, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
508 we use the expression |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
509 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
510 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
511 metatable(obj)[event] |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
512 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
513 This should be read as |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
514 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
515 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
516 rawget(getmetatable(obj) or {}, event) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
517 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
518 This means that the access to a metamethod does not invoke other metamethods, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
519 and access to objects with no metatables does not fail |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
520 (it simply results in <b>nil</b>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
521 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
522 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
523 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
524 For the unary <code>-</code> and <code>#</code> operators, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
525 the metamethod is called with a dummy second argument. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
526 This extra argument is only to simplify Lua's internals; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
527 it may be removed in future versions and therefore it is not present |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
528 in the following code. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
529 (For most uses this extra argument is irrelevant.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
530 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
531 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
532 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
533 <ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
534 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
535 <li><b>"add": </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
536 the <code>+</code> operation. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
537 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
538 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
539 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
540 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
541 The function <code>getbinhandler</code> below defines how Lua chooses a handler |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
542 for a binary operation. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
543 First, Lua tries the first operand. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
544 If its type does not define a handler for the operation, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
545 then Lua tries the second operand. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
546 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
547 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
548 function getbinhandler (op1, op2, event) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
549 return metatable(op1)[event] or metatable(op2)[event] |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
550 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
551 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
552 By using this function, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
553 the behavior of the <code>op1 + op2</code> is |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
554 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
555 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
556 function add_event (op1, op2) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
557 local o1, o2 = tonumber(op1), tonumber(op2) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
558 if o1 and o2 then -- both operands are numeric? |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
559 return o1 + o2 -- '+' here is the primitive 'add' |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
560 else -- at least one of the operands is not numeric |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
561 local h = getbinhandler(op1, op2, "__add") |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
562 if h then |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
563 -- call the handler with both operands |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
564 return (h(op1, op2)) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
565 else -- no handler available: default behavior |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
566 error(···) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
567 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
568 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
569 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
570 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
571 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
572 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
573 <li><b>"sub": </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
574 the <code>-</code> operation. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
575 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
576 Behavior similar to the "add" operation. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
577 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
578 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
579 <li><b>"mul": </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
580 the <code>*</code> operation. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
581 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
582 Behavior similar to the "add" operation. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
583 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
584 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
585 <li><b>"div": </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
586 the <code>/</code> operation. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
587 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
588 Behavior similar to the "add" operation. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
589 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
590 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
591 <li><b>"mod": </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
592 the <code>%</code> operation. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
593 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
594 Behavior similar to the "add" operation, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
595 with the operation |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
596 <code>o1 - floor(o1/o2)*o2</code> as the primitive operation. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
597 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
598 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
599 <li><b>"pow": </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
600 the <code>^</code> (exponentiation) operation. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
601 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
602 Behavior similar to the "add" operation, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
603 with the function <code>pow</code> (from the C math library) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
604 as the primitive operation. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
605 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
606 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
607 <li><b>"unm": </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
608 the unary <code>-</code> operation. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
609 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
610 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
611 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
612 function unm_event (op) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
613 local o = tonumber(op) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
614 if o then -- operand is numeric? |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
615 return -o -- '-' here is the primitive 'unm' |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
616 else -- the operand is not numeric. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
617 -- Try to get a handler from the operand |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
618 local h = metatable(op).__unm |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
619 if h then |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
620 -- call the handler with the operand |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
621 return (h(op)) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
622 else -- no handler available: default behavior |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
623 error(···) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
624 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
625 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
626 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
627 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
628 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
629 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
630 <li><b>"concat": </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
631 the <code>..</code> (concatenation) operation. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
632 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
633 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
634 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
635 function concat_event (op1, op2) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
636 if (type(op1) == "string" or type(op1) == "number") and |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
637 (type(op2) == "string" or type(op2) == "number") then |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
638 return op1 .. op2 -- primitive string concatenation |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
639 else |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
640 local h = getbinhandler(op1, op2, "__concat") |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
641 if h then |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
642 return (h(op1, op2)) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
643 else |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
644 error(···) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
645 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
646 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
647 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
648 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
649 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
650 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
651 <li><b>"len": </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
652 the <code>#</code> operation. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
653 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
654 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
655 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
656 function len_event (op) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
657 if type(op) == "string" then |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
658 return strlen(op) -- primitive string length |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
659 else |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
660 local h = metatable(op).__len |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
661 if h then |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
662 return (h(op)) -- call handler with the operand |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
663 elseif type(op) == "table" then |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
664 return #op -- primitive table length |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
665 else -- no handler available: error |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
666 error(···) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
667 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
668 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
669 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
670 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
671 See <a href="#3.4.6">§3.4.6</a> for a description of the length of a table. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
672 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
673 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
674 <li><b>"eq": </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
675 the <code>==</code> operation. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
676 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
677 The function <code>getequalhandler</code> defines how Lua chooses a metamethod |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
678 for equality. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
679 A metamethod is selected only when both values |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
680 being compared have the same type |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
681 and the same metamethod for the selected operation, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
682 and the values are either tables or full userdata. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
683 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
684 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
685 function getequalhandler (op1, op2) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
686 if type(op1) ~= type(op2) or |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
687 (type(op1) ~= "table" and type(op1) ~= "userdata") then |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
688 return nil -- different values |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
689 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
690 local mm1 = metatable(op1).__eq |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
691 local mm2 = metatable(op2).__eq |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
692 if mm1 == mm2 then return mm1 else return nil end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
693 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
694 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
695 The "eq" event is defined as follows: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
696 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
697 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
698 function eq_event (op1, op2) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
699 if op1 == op2 then -- primitive equal? |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
700 return true -- values are equal |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
701 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
702 -- try metamethod |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
703 local h = getequalhandler(op1, op2) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
704 if h then |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
705 return not not h(op1, op2) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
706 else |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
707 return false |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
708 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
709 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
710 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
711 Note that the result is always a boolean. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
712 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
713 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
714 <li><b>"lt": </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
715 the <code><</code> operation. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
716 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
717 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
718 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
719 function lt_event (op1, op2) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
720 if type(op1) == "number" and type(op2) == "number" then |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
721 return op1 < op2 -- numeric comparison |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
722 elseif type(op1) == "string" and type(op2) == "string" then |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
723 return op1 < op2 -- lexicographic comparison |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
724 else |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
725 local h = getbinhandler(op1, op2, "__lt") |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
726 if h then |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
727 return not not h(op1, op2) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
728 else |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
729 error(···) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
730 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
731 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
732 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
733 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
734 Note that the result is always a boolean. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
735 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
736 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
737 <li><b>"le": </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
738 the <code><=</code> operation. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
739 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
740 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
741 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
742 function le_event (op1, op2) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
743 if type(op1) == "number" and type(op2) == "number" then |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
744 return op1 <= op2 -- numeric comparison |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
745 elseif type(op1) == "string" and type(op2) == "string" then |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
746 return op1 <= op2 -- lexicographic comparison |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
747 else |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
748 local h = getbinhandler(op1, op2, "__le") |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
749 if h then |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
750 return not not h(op1, op2) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
751 else |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
752 h = getbinhandler(op1, op2, "__lt") |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
753 if h then |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
754 return not h(op2, op1) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
755 else |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
756 error(···) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
757 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
758 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
759 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
760 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
761 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
762 Note that, in the absence of a "le" metamethod, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
763 Lua tries the "lt", assuming that <code>a <= b</code> is |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
764 equivalent to <code>not (b < a)</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
765 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
766 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
767 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
768 As with the other comparison operators, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
769 the result is always a boolean. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
770 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
771 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
772 <li><b>"index": </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
773 The indexing access <code>table[key]</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
774 Note that the metamethod is tried only |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
775 when <code>key</code> is not present in <code>table</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
776 (When <code>table</code> is not a table, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
777 no key is ever present, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
778 so the metamethod is always tried.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
779 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
780 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
781 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
782 function gettable_event (table, key) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
783 local h |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
784 if type(table) == "table" then |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
785 local v = rawget(table, key) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
786 -- if key is present, return raw value |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
787 if v ~= nil then return v end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
788 h = metatable(table).__index |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
789 if h == nil then return nil end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
790 else |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
791 h = metatable(table).__index |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
792 if h == nil then |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
793 error(···) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
794 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
795 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
796 if type(h) == "function" then |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
797 return (h(table, key)) -- call the handler |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
798 else return h[key] -- or repeat operation on it |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
799 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
800 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
801 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
802 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
803 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
804 <li><b>"newindex": </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
805 The indexing assignment <code>table[key] = value</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
806 Note that the metamethod is tried only |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
807 when <code>key</code> is not present in <code>table</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
808 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
809 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
810 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
811 function settable_event (table, key, value) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
812 local h |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
813 if type(table) == "table" then |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
814 local v = rawget(table, key) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
815 -- if key is present, do raw assignment |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
816 if v ~= nil then rawset(table, key, value); return end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
817 h = metatable(table).__newindex |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
818 if h == nil then rawset(table, key, value); return end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
819 else |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
820 h = metatable(table).__newindex |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
821 if h == nil then |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
822 error(···) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
823 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
824 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
825 if type(h) == "function" then |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
826 h(table, key,value) -- call the handler |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
827 else h[key] = value -- or repeat operation on it |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
828 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
829 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
830 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
831 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
832 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
833 <li><b>"call": </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
834 called when Lua calls a value. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
835 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
836 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
837 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
838 function function_event (func, ...) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
839 if type(func) == "function" then |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
840 return func(...) -- primitive call |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
841 else |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
842 local h = metatable(func).__call |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
843 if h then |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
844 return h(func, ...) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
845 else |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
846 error(···) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
847 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
848 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
849 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
850 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
851 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
852 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
853 </ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
854 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
855 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
856 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
857 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
858 <h2>2.5 – <a name="2.5">Garbage Collection</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
859 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
860 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
861 Lua performs automatic memory management. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
862 This means that |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
863 you have to worry neither about allocating memory for new objects |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
864 nor about freeing it when the objects are no longer needed. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
865 Lua manages memory automatically by running |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
866 a <em>garbage collector</em> to collect all <em>dead objects</em> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
867 (that is, objects that are no longer accessible from Lua). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
868 All memory used by Lua is subject to automatic management: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
869 strings, tables, userdata, functions, threads, internal structures, etc. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
870 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
871 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
872 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
873 Lua implements an incremental mark-and-sweep collector. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
874 It uses two numbers to control its garbage-collection cycles: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
875 the <em>garbage-collector pause</em> and |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
876 the <em>garbage-collector step multiplier</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
877 Both use percentage points as units |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
878 (e.g., a value of 100 means an internal value of 1). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
879 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
880 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
881 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
882 The garbage-collector pause |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
883 controls how long the collector waits before starting a new cycle. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
884 Larger values make the collector less aggressive. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
885 Values smaller than 100 mean the collector will not wait to |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
886 start a new cycle. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
887 A value of 200 means that the collector waits for the total memory in use |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
888 to double before starting a new cycle. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
889 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
890 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
891 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
892 The garbage-collector step multiplier |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
893 controls the relative speed of the collector relative to |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
894 memory allocation. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
895 Larger values make the collector more aggressive but also increase |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
896 the size of each incremental step. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
897 Values smaller than 100 make the collector too slow and |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
898 can result in the collector never finishing a cycle. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
899 The default is 200, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
900 which means that the collector runs at "twice" |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
901 the speed of memory allocation. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
902 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
903 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
904 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
905 If you set the step multiplier to a very large number |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
906 (larger than 10% of the maximum number of |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
907 bytes that the program may use), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
908 the collector behaves like a stop-the-world collector. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
909 If you then set the pause to 200, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
910 the collector behaves as in old Lua versions, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
911 doing a complete collection every time Lua doubles its |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
912 memory usage. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
913 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
914 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
915 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
916 You can change these numbers by calling <a href="#lua_gc"><code>lua_gc</code></a> in C |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
917 or <a href="#pdf-collectgarbage"><code>collectgarbage</code></a> in Lua. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
918 You can also use these functions to control |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
919 the collector directly (e.g., stop and restart it). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
920 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
921 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
922 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
923 As an experimental feature in Lua 5.2, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
924 you can change the collector's operation mode |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
925 from incremental to <em>generational</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
926 A <em>generational collector</em> assumes that most objects die young, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
927 and therefore it traverses only young (recently created) objects. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
928 This behavior can reduce the time used by the collector, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
929 but also increases memory usage (as old dead objects may accumulate). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
930 To mitigate this second problem, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
931 from time to time the generational collector performs a full collection. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
932 Remember that this is an experimental feature; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
933 you are welcome to try it, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
934 but check your gains. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
935 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
936 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
937 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
938 <h3>2.5.1 – <a name="2.5.1">Garbage-Collection Metamethods</a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
939 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
940 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
941 You can set garbage-collector metamethods for tables |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
942 and, using the C API, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
943 for full userdata (see <a href="#2.4">§2.4</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
944 These metamethods are also called <em>finalizers</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
945 Finalizers allow you to coordinate Lua's garbage collection |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
946 with external resource management |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
947 (such as closing files, network or database connections, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
948 or freeing your own memory). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
949 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
950 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
951 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
952 For an object (table or userdata) to be finalized when collected, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
953 you must <em>mark</em> it for finalization. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
954 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
955 You mark an object for finalization when you set its metatable |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
956 and the metatable has a field indexed by the string "<code>__gc</code>". |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
957 Note that if you set a metatable without a <code>__gc</code> field |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
958 and later create that field in the metatable, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
959 the object will not be marked for finalization. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
960 However, after an object is marked, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
961 you can freely change the <code>__gc</code> field of its metatable. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
962 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
963 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
964 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
965 When a marked object becomes garbage, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
966 it is not collected immediately by the garbage collector. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
967 Instead, Lua puts it in a list. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
968 After the collection, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
969 Lua does the equivalent of the following function |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
970 for each object in that list: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
971 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
972 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
973 function gc_event (obj) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
974 local h = metatable(obj).__gc |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
975 if type(h) == "function" then |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
976 h(obj) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
977 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
978 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
979 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
980 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
981 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
982 At the end of each garbage-collection cycle, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
983 the finalizers for objects are called in |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
984 the reverse order that they were marked for collection, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
985 among those collected in that cycle; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
986 that is, the first finalizer to be called is the one associated |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
987 with the object marked last in the program. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
988 The execution of each finalizer may occur at any point during |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
989 the execution of the regular code. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
990 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
991 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
992 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
993 Because the object being collected must still be used by the finalizer, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
994 it (and other objects accessible only through it) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
995 must be <em>resurrected</em> by Lua. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
996 Usually, this resurrection is transient, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
997 and the object memory is freed in the next garbage-collection cycle. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
998 However, if the finalizer stores the object in some global place |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
999 (e.g., a global variable), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1000 then there is a permanent resurrection. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1001 In any case, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1002 the object memory is freed only when it becomes completely inaccessible; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1003 its finalizer will never be called twice. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1004 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1005 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1006 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1007 When you close a state (see <a href="#lua_close"><code>lua_close</code></a>), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1008 Lua calls the finalizers of all objects marked for finalization, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1009 following the reverse order that they were marked. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1010 If any finalizer marks new objects for collection during that phase, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1011 these new objects will not be finalized. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1012 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1013 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1014 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1015 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1016 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1017 <h3>2.5.2 – <a name="2.5.2">Weak Tables</a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1018 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1019 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1020 A <em>weak table</em> is a table whose elements are |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1021 <em>weak references</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1022 A weak reference is ignored by the garbage collector. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1023 In other words, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1024 if the only references to an object are weak references, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1025 then the garbage collector will collect that object. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1026 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1027 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1028 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1029 A weak table can have weak keys, weak values, or both. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1030 A table with weak keys allows the collection of its keys, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1031 but prevents the collection of its values. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1032 A table with both weak keys and weak values allows the collection of |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1033 both keys and values. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1034 In any case, if either the key or the value is collected, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1035 the whole pair is removed from the table. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1036 The weakness of a table is controlled by the |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1037 <code>__mode</code> field of its metatable. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1038 If the <code>__mode</code> field is a string containing the character '<code>k</code>', |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1039 the keys in the table are weak. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1040 If <code>__mode</code> contains '<code>v</code>', |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1041 the values in the table are weak. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1042 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1043 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1044 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1045 A table with weak keys and strong values |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1046 is also called an <em>ephemeron table</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1047 In an ephemeron table, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1048 a value is considered reachable only if its key is reachable. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1049 In particular, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1050 if the only reference to a key comes through its value, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1051 the pair is removed. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1052 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1053 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1054 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1055 Any change in the weakness of a table may take effect only |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1056 at the next collect cycle. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1057 In particular, if you change the weakness to a stronger mode, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1058 Lua may still collect some items from that table |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1059 before the change takes effect. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1060 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1061 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1062 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1063 Only objects that have an explicit construction |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1064 are removed from weak tables. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1065 Values, such as numbers and light C functions, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1066 are not subject to garbage collection, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1067 and therefore are not removed from weak tables |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1068 (unless its associated value is collected). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1069 Although strings are subject to garbage collection, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1070 they do not have an explicit construction, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1071 and therefore are not removed from weak tables. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1072 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1073 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1074 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1075 Resurrected objects |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1076 (that is, objects being finalized |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1077 and objects accessible only through objects being finalized) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1078 have a special behavior in weak tables. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1079 They are removed from weak values before running their finalizers, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1080 but are removed from weak keys only in the next collection |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1081 after running their finalizers, when such objects are actually freed. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1082 This behavior allows the finalizer to access properties |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1083 associated with the object through weak tables. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1084 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1085 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1086 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1087 If a weak table is among the resurrected objects in a collection cycle, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1088 it may not be properly cleared until the next cycle. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1089 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1090 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1091 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1092 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1093 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1094 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1095 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1096 <h2>2.6 – <a name="2.6">Coroutines</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1097 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1098 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1099 Lua supports coroutines, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1100 also called <em>collaborative multithreading</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1101 A coroutine in Lua represents an independent thread of execution. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1102 Unlike threads in multithread systems, however, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1103 a coroutine only suspends its execution by explicitly calling |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1104 a yield function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1105 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1106 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1107 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1108 You create a coroutine by calling <a href="#pdf-coroutine.create"><code>coroutine.create</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1109 Its sole argument is a function |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1110 that is the main function of the coroutine. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1111 The <code>create</code> function only creates a new coroutine and |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1112 returns a handle to it (an object of type <em>thread</em>); |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1113 it does not start the coroutine. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1114 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1115 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1116 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1117 You execute a coroutine by calling <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1118 When you first call <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1119 passing as its first argument |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1120 a thread returned by <a href="#pdf-coroutine.create"><code>coroutine.create</code></a>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1121 the coroutine starts its execution, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1122 at the first line of its main function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1123 Extra arguments passed to <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a> are passed on |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1124 to the coroutine main function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1125 After the coroutine starts running, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1126 it runs until it terminates or <em>yields</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1127 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1128 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1129 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1130 A coroutine can terminate its execution in two ways: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1131 normally, when its main function returns |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1132 (explicitly or implicitly, after the last instruction); |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1133 and abnormally, if there is an unprotected error. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1134 In the first case, <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a> returns <b>true</b>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1135 plus any values returned by the coroutine main function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1136 In case of errors, <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a> returns <b>false</b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1137 plus an error message. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1138 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1139 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1140 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1141 A coroutine yields by calling <a href="#pdf-coroutine.yield"><code>coroutine.yield</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1142 When a coroutine yields, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1143 the corresponding <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a> returns immediately, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1144 even if the yield happens inside nested function calls |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1145 (that is, not in the main function, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1146 but in a function directly or indirectly called by the main function). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1147 In the case of a yield, <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a> also returns <b>true</b>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1148 plus any values passed to <a href="#pdf-coroutine.yield"><code>coroutine.yield</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1149 The next time you resume the same coroutine, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1150 it continues its execution from the point where it yielded, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1151 with the call to <a href="#pdf-coroutine.yield"><code>coroutine.yield</code></a> returning any extra |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1152 arguments passed to <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1153 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1154 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1155 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1156 Like <a href="#pdf-coroutine.create"><code>coroutine.create</code></a>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1157 the <a href="#pdf-coroutine.wrap"><code>coroutine.wrap</code></a> function also creates a coroutine, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1158 but instead of returning the coroutine itself, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1159 it returns a function that, when called, resumes the coroutine. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1160 Any arguments passed to this function |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1161 go as extra arguments to <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1162 <a href="#pdf-coroutine.wrap"><code>coroutine.wrap</code></a> returns all the values returned by <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1163 except the first one (the boolean error code). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1164 Unlike <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1165 <a href="#pdf-coroutine.wrap"><code>coroutine.wrap</code></a> does not catch errors; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1166 any error is propagated to the caller. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1167 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1168 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1169 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1170 As an example of how coroutines work, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1171 consider the following code: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1172 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1173 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1174 function foo (a) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1175 print("foo", a) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1176 return coroutine.yield(2*a) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1177 end |
242
b5a926c481a5
Handle first h1 tag differently.
hugo.tech@gmail.com <hugo.tech@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
241
diff
changeset
|
1178 |
239
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1179 co = coroutine.create(function (a,b) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1180 print("co-body", a, b) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1181 local r = foo(a+1) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1182 print("co-body", r) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1183 local r, s = coroutine.yield(a+b, a-b) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1184 print("co-body", r, s) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1185 return b, "end" |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1186 end) |
242
b5a926c481a5
Handle first h1 tag differently.
hugo.tech@gmail.com <hugo.tech@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
241
diff
changeset
|
1187 |
239
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1188 print("main", coroutine.resume(co, 1, 10)) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1189 print("main", coroutine.resume(co, "r")) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1190 print("main", coroutine.resume(co, "x", "y")) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1191 print("main", coroutine.resume(co, "x", "y")) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1192 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1193 When you run it, it produces the following output: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1194 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1195 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1196 co-body 1 10 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1197 foo 2 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1198 main true 4 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1199 co-body r |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1200 main true 11 -9 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1201 co-body x y |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1202 main true 10 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1203 main false cannot resume dead coroutine |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1204 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1205 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1206 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1207 You can also create and manipulate coroutines through the C API: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1208 see functions <a href="#lua_newthread"><code>lua_newthread</code></a>, <a href="#lua_resume"><code>lua_resume</code></a>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1209 and <a href="#lua_yield"><code>lua_yield</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1210 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1211 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1212 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1213 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1214 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1215 <h1>3 – <a name="3">The Language</a></h1> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1216 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1217 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1218 This section describes the lexis, the syntax, and the semantics of Lua. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1219 In other words, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1220 this section describes |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1221 which tokens are valid, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1222 how they can be combined, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1223 and what their combinations mean. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1224 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1225 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1226 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1227 Language constructs will be explained using the usual extended BNF notation, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1228 in which |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1229 {<em>a</em>} means 0 or more <em>a</em>'s, and |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1230 [<em>a</em>] means an optional <em>a</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1231 Non-terminals are shown like non-terminal, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1232 keywords are shown like <b>kword</b>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1233 and other terminal symbols are shown like ‘<b>=</b>’. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1234 The complete syntax of Lua can be found in <a href="#9">§9</a> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1235 at the end of this manual. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1236 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1237 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1238 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1239 <h2>3.1 – <a name="3.1">Lexical Conventions</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1240 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1241 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1242 Lua is a free-form language. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1243 It ignores spaces (including new lines) and comments |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1244 between lexical elements (tokens), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1245 except as delimiters between names and keywords. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1246 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1247 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1248 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1249 <em>Names</em> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1250 (also called <em>identifiers</em>) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1251 in Lua can be any string of letters, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1252 digits, and underscores, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1253 not beginning with a digit. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1254 Identifiers are used to name variables, table fields, and labels. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1255 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1256 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1257 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1258 The following <em>keywords</em> are reserved |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1259 and cannot be used as names: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1260 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1261 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1262 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1263 and break do else elseif end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1264 false for function goto if in |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1265 local nil not or repeat return |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1266 then true until while |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1267 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1268 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1269 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1270 Lua is a case-sensitive language: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1271 <code>and</code> is a reserved word, but <code>And</code> and <code>AND</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1272 are two different, valid names. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1273 As a convention, names starting with an underscore followed by |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1274 uppercase letters (such as <a href="#pdf-_VERSION"><code>_VERSION</code></a>) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1275 are reserved for variables used by Lua. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1276 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1277 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1278 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1279 The following strings denote other tokens: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1280 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1281 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1282 + - * / % ^ # |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1283 == ~= <= >= < > = |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1284 ( ) { } [ ] :: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1285 ; : , . .. ... |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1286 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1287 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1288 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1289 <em>Literal strings</em> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1290 can be delimited by matching single or double quotes, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1291 and can contain the following C-like escape sequences: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1292 '<code>\a</code>' (bell), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1293 '<code>\b</code>' (backspace), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1294 '<code>\f</code>' (form feed), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1295 '<code>\n</code>' (newline), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1296 '<code>\r</code>' (carriage return), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1297 '<code>\t</code>' (horizontal tab), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1298 '<code>\v</code>' (vertical tab), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1299 '<code>\\</code>' (backslash), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1300 '<code>\"</code>' (quotation mark [double quote]), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1301 and '<code>\'</code>' (apostrophe [single quote]). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1302 A backslash followed by a real newline |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1303 results in a newline in the string. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1304 The escape sequence '<code>\z</code>' skips the following span |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1305 of white-space characters, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1306 including line breaks; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1307 it is particularly useful to break and indent a long literal string |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1308 into multiple lines without adding the newlines and spaces |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1309 into the string contents. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1310 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1311 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1312 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1313 A byte in a literal string can also be specified by its numerical value. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1314 This can be done with the escape sequence <code>\x<em>XX</em></code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1315 where <em>XX</em> is a sequence of exactly two hexadecimal digits, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1316 or with the escape sequence <code>\<em>ddd</em></code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1317 where <em>ddd</em> is a sequence of up to three decimal digits. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1318 (Note that if a decimal escape is to be followed by a digit, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1319 it must be expressed using exactly three digits.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1320 Strings in Lua can contain any 8-bit value, including embedded zeros, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1321 which can be specified as '<code>\0</code>'. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1322 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1323 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1324 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1325 Literal strings can also be defined using a long format |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1326 enclosed by <em>long brackets</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1327 We define an <em>opening long bracket of level <em>n</em></em> as an opening |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1328 square bracket followed by <em>n</em> equal signs followed by another |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1329 opening square bracket. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1330 So, an opening long bracket of level 0 is written as <code>[[</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1331 an opening long bracket of level 1 is written as <code>[=[</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1332 and so on. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1333 A <em>closing long bracket</em> is defined similarly; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1334 for instance, a closing long bracket of level 4 is written as <code>]====]</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1335 A <em>long literal</em> starts with an opening long bracket of any level and |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1336 ends at the first closing long bracket of the same level. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1337 It can contain any text except a closing bracket of the proper level. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1338 Literals in this bracketed form can run for several lines, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1339 do not interpret any escape sequences, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1340 and ignore long brackets of any other level. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1341 Any kind of end-of-line sequence |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1342 (carriage return, newline, carriage return followed by newline, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1343 or newline followed by carriage return) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1344 is converted to a simple newline. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1345 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1346 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1347 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1348 Any byte in a literal string not |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1349 explicitly affected by the previous rules represents itself. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1350 However, Lua opens files for parsing in text mode, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1351 and the system file functions may have problems with |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1352 some control characters. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1353 So, it is safer to represent |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1354 non-text data as a quoted literal with |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1355 explicit escape sequences for non-text characters. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1356 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1357 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1358 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1359 For convenience, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1360 when the opening long bracket is immediately followed by a newline, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1361 the newline is not included in the string. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1362 As an example, in a system using ASCII |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1363 (in which '<code>a</code>' is coded as 97, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1364 newline is coded as 10, and '<code>1</code>' is coded as 49), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1365 the five literal strings below denote the same string: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1366 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1367 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1368 a = 'alo\n123"' |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1369 a = "alo\n123\"" |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1370 a = '\97lo\10\04923"' |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1371 a = [[alo |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1372 123"]] |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1373 a = [==[ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1374 alo |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1375 123"]==] |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1376 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1377 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1378 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1379 A <em>numerical constant</em> can be written with an optional fractional part |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1380 and an optional decimal exponent, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1381 marked by a letter '<code>e</code>' or '<code>E</code>'. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1382 Lua also accepts hexadecimal constants, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1383 which start with <code>0x</code> or <code>0X</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1384 Hexadecimal constants also accept an optional fractional part |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1385 plus an optional binary exponent, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1386 marked by a letter '<code>p</code>' or '<code>P</code>'. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1387 Examples of valid numerical constants are |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1388 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1389 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1390 3 3.0 3.1416 314.16e-2 0.31416E1 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1391 0xff 0x0.1E 0xA23p-4 0X1.921FB54442D18P+1 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1392 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1393 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1394 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1395 A <em>comment</em> starts with a double hyphen (<code>--</code>) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1396 anywhere outside a string. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1397 If the text immediately after <code>--</code> is not an opening long bracket, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1398 the comment is a <em>short comment</em>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1399 which runs until the end of the line. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1400 Otherwise, it is a <em>long comment</em>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1401 which runs until the corresponding closing long bracket. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1402 Long comments are frequently used to disable code temporarily. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1403 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1404 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1405 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1406 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1407 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1408 <h2>3.2 – <a name="3.2">Variables</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1409 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1410 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1411 Variables are places that store values. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1412 There are three kinds of variables in Lua: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1413 global variables, local variables, and table fields. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1414 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1415 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1416 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1417 A single name can denote a global variable or a local variable |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1418 (or a function's formal parameter, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1419 which is a particular kind of local variable): |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1420 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1421 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1422 var ::= Name |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1423 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1424 Name denotes identifiers, as defined in <a href="#3.1">§3.1</a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1425 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1426 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1427 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1428 Any variable name is assumed to be global unless explicitly declared |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1429 as a local (see <a href="#3.3.7">§3.3.7</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1430 Local variables are <em>lexically scoped</em>: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1431 local variables can be freely accessed by functions |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1432 defined inside their scope (see <a href="#3.5">§3.5</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1433 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1434 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1435 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1436 Before the first assignment to a variable, its value is <b>nil</b>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1437 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1438 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1439 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1440 Square brackets are used to index a table: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1441 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1442 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1443 var ::= prefixexp ‘<b>[</b>’ exp ‘<b>]</b>’ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1444 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1445 The meaning of accesses to table fields can be changed via metatables. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1446 An access to an indexed variable <code>t[i]</code> is equivalent to |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1447 a call <code>gettable_event(t,i)</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1448 (See <a href="#2.4">§2.4</a> for a complete description of the |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1449 <code>gettable_event</code> function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1450 This function is not defined or callable in Lua. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1451 We use it here only for explanatory purposes.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1452 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1453 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1454 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1455 The syntax <code>var.Name</code> is just syntactic sugar for |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1456 <code>var["Name"]</code>: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1457 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1458 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1459 var ::= prefixexp ‘<b>.</b>’ Name |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1460 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1461 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1462 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1463 An access to a global variable <code>x</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1464 is equivalent to <code>_ENV.x</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1465 Due to the way that chunks are compiled, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1466 <code>_ENV</code> is never a global name (see <a href="#2.2">§2.2</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1467 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1468 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1469 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1470 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1471 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1472 <h2>3.3 – <a name="3.3">Statements</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1473 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1474 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1475 Lua supports an almost conventional set of statements, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1476 similar to those in Pascal or C. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1477 This set includes |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1478 assignments, control structures, function calls, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1479 and variable declarations. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1480 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1481 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1482 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1483 <h3>3.3.1 – <a name="3.3.1">Blocks</a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1484 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1485 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1486 A block is a list of statements, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1487 which are executed sequentially: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1488 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1489 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1490 block ::= {stat} |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1491 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1492 Lua has <em>empty statements</em> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1493 that allow you to separate statements with semicolons, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1494 start a block with a semicolon |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1495 or write two semicolons in sequence: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1496 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1497 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1498 stat ::= ‘<b>;</b>’ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1499 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1500 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1501 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1502 Function calls and assignments |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1503 can start with an open parenthesis. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1504 This possibility leads to an ambiguity in Lua's grammar. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1505 Consider the following fragment: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1506 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1507 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1508 a = b + c |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1509 (print or io.write)('done') |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1510 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1511 The grammar could see it in two ways: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1512 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1513 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1514 a = b + c(print or io.write)('done') |
242
b5a926c481a5
Handle first h1 tag differently.
hugo.tech@gmail.com <hugo.tech@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
241
diff
changeset
|
1515 |
239
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1516 a = b + c; (print or io.write)('done') |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1517 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1518 The current parser always sees such constructions |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1519 in the first way, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1520 interpreting the open parenthesis |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1521 as the start of the arguments to a call. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1522 To avoid this ambiguity, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1523 it is a good practice to always precede with a semicolon |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1524 statements that start with a parenthesis: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1525 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1526 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1527 ;(print or io.write)('done') |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1528 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1529 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1530 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1531 A block can be explicitly delimited to produce a single statement: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1532 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1533 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1534 stat ::= <b>do</b> block <b>end</b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1535 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1536 Explicit blocks are useful |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1537 to control the scope of variable declarations. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1538 Explicit blocks are also sometimes used to |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1539 add a <b>return</b> statement in the middle |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1540 of another block (see <a href="#3.3.4">§3.3.4</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1541 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1542 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1543 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1544 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1545 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1546 <h3>3.3.2 – <a name="3.3.2">Chunks</a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1547 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1548 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1549 The unit of compilation of Lua is called a <em>chunk</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1550 Syntactically, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1551 a chunk is simply a block: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1552 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1553 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1554 chunk ::= block |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1555 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1556 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1557 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1558 Lua handles a chunk as the body of an anonymous function |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1559 with a variable number of arguments |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1560 (see <a href="#3.4.10">§3.4.10</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1561 As such, chunks can define local variables, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1562 receive arguments, and return values. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1563 Moreover, such anonymous function is compiled as in the |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1564 scope of an external local variable called <code>_ENV</code> (see <a href="#2.2">§2.2</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1565 The resulting function always has <code>_ENV</code> as its only upvalue, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1566 even if it does not use that variable. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1567 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1568 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1569 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1570 A chunk can be stored in a file or in a string inside the host program. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1571 To execute a chunk, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1572 Lua first precompiles the chunk into instructions for a virtual machine, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1573 and then it executes the compiled code |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1574 with an interpreter for the virtual machine. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1575 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1576 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1577 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1578 Chunks can also be precompiled into binary form; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1579 see program <code>luac</code> for details. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1580 Programs in source and compiled forms are interchangeable; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1581 Lua automatically detects the file type and acts accordingly. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1582 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1583 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1584 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1585 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1586 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1587 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1588 <h3>3.3.3 – <a name="3.3.3">Assignment</a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1589 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1590 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1591 Lua allows multiple assignments. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1592 Therefore, the syntax for assignment |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1593 defines a list of variables on the left side |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1594 and a list of expressions on the right side. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1595 The elements in both lists are separated by commas: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1596 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1597 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1598 stat ::= varlist ‘<b>=</b>’ explist |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1599 varlist ::= var {‘<b>,</b>’ var} |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1600 explist ::= exp {‘<b>,</b>’ exp} |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1601 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1602 Expressions are discussed in <a href="#3.4">§3.4</a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1603 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1604 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1605 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1606 Before the assignment, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1607 the list of values is <em>adjusted</em> to the length of |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1608 the list of variables. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1609 If there are more values than needed, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1610 the excess values are thrown away. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1611 If there are fewer values than needed, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1612 the list is extended with as many <b>nil</b>'s as needed. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1613 If the list of expressions ends with a function call, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1614 then all values returned by that call enter the list of values, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1615 before the adjustment |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1616 (except when the call is enclosed in parentheses; see <a href="#3.4">§3.4</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1617 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1618 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1619 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1620 The assignment statement first evaluates all its expressions |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1621 and only then are the assignments performed. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1622 Thus the code |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1623 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1624 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1625 i = 3 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1626 i, a[i] = i+1, 20 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1627 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1628 sets <code>a[3]</code> to 20, without affecting <code>a[4]</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1629 because the <code>i</code> in <code>a[i]</code> is evaluated (to 3) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1630 before it is assigned 4. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1631 Similarly, the line |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1632 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1633 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1634 x, y = y, x |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1635 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1636 exchanges the values of <code>x</code> and <code>y</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1637 and |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1638 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1639 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1640 x, y, z = y, z, x |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1641 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1642 cyclically permutes the values of <code>x</code>, <code>y</code>, and <code>z</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1643 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1644 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1645 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1646 The meaning of assignments to global variables |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1647 and table fields can be changed via metatables. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1648 An assignment to an indexed variable <code>t[i] = val</code> is equivalent to |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1649 <code>settable_event(t,i,val)</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1650 (See <a href="#2.4">§2.4</a> for a complete description of the |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1651 <code>settable_event</code> function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1652 This function is not defined or callable in Lua. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1653 We use it here only for explanatory purposes.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1654 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1655 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1656 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1657 An assignment to a global variable <code>x = val</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1658 is equivalent to the assignment |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1659 <code>_ENV.x = val</code> (see <a href="#2.2">§2.2</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1660 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1661 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1662 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1663 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1664 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1665 <h3>3.3.4 – <a name="3.3.4">Control Structures</a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1666 The control structures |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1667 <b>if</b>, <b>while</b>, and <b>repeat</b> have the usual meaning and |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1668 familiar syntax: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1669 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1670 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1671 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1672 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1673 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1674 stat ::= <b>while</b> exp <b>do</b> block <b>end</b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1675 stat ::= <b>repeat</b> block <b>until</b> exp |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1676 stat ::= <b>if</b> exp <b>then</b> block {<b>elseif</b> exp <b>then</b> block} [<b>else</b> block] <b>end</b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1677 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1678 Lua also has a <b>for</b> statement, in two flavors (see <a href="#3.3.5">§3.3.5</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1679 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1680 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1681 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1682 The condition expression of a |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1683 control structure can return any value. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1684 Both <b>false</b> and <b>nil</b> are considered false. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1685 All values different from <b>nil</b> and <b>false</b> are considered true |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1686 (in particular, the number 0 and the empty string are also true). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1687 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1688 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1689 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1690 In the <b>repeat</b>–<b>until</b> loop, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1691 the inner block does not end at the <b>until</b> keyword, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1692 but only after the condition. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1693 So, the condition can refer to local variables |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1694 declared inside the loop block. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1695 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1696 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1697 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1698 The <b>goto</b> statement transfers the program control to a label. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1699 For syntactical reasons, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1700 labels in Lua are considered statements too: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1701 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1702 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1703 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1704 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1705 stat ::= <b>goto</b> Name |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1706 stat ::= label |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1707 label ::= ‘<b>::</b>’ Name ‘<b>::</b>’ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1708 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1709 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1710 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1711 A label is visible in the entire block where it is defined, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1712 except |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1713 inside nested blocks where a label with the same name is defined and |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1714 inside nested functions. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1715 A goto may jump to any visible label as long as it does not |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1716 enter into the scope of a local variable. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1717 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1718 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1719 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1720 Labels and empty statements are called <em>void statements</em>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1721 as they perform no actions. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1722 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1723 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1724 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1725 The <b>break</b> statement terminates the execution of a |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1726 <b>while</b>, <b>repeat</b>, or <b>for</b> loop, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1727 skipping to the next statement after the loop: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1728 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1729 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1730 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1731 stat ::= <b>break</b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1732 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1733 A <b>break</b> ends the innermost enclosing loop. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1734 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1735 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1736 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1737 The <b>return</b> statement is used to return values |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1738 from a function or a chunk (which is a function in disguise). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1739 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1740 Functions can return more than one value, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1741 so the syntax for the <b>return</b> statement is |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1742 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1743 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1744 stat ::= <b>return</b> [explist] [‘<b>;</b>’] |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1745 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1746 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1747 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1748 The <b>return</b> statement can only be written |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1749 as the last statement of a block. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1750 If it is really necessary to <b>return</b> in the middle of a block, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1751 then an explicit inner block can be used, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1752 as in the idiom <code>do return end</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1753 because now <b>return</b> is the last statement in its (inner) block. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1754 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1755 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1756 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1757 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1758 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1759 <h3>3.3.5 – <a name="3.3.5">For Statement</a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1760 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1761 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1762 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1763 The <b>for</b> statement has two forms: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1764 one numeric and one generic. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1765 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1766 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1767 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1768 The numeric <b>for</b> loop repeats a block of code while a |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1769 control variable runs through an arithmetic progression. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1770 It has the following syntax: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1771 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1772 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1773 stat ::= <b>for</b> Name ‘<b>=</b>’ exp ‘<b>,</b>’ exp [‘<b>,</b>’ exp] <b>do</b> block <b>end</b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1774 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1775 The <em>block</em> is repeated for <em>name</em> starting at the value of |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1776 the first <em>exp</em>, until it passes the second <em>exp</em> by steps of the |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1777 third <em>exp</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1778 More precisely, a <b>for</b> statement like |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1779 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1780 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1781 for v = <em>e1</em>, <em>e2</em>, <em>e3</em> do <em>block</em> end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1782 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1783 is equivalent to the code: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1784 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1785 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1786 do |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1787 local <em>var</em>, <em>limit</em>, <em>step</em> = tonumber(<em>e1</em>), tonumber(<em>e2</em>), tonumber(<em>e3</em>) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1788 if not (<em>var</em> and <em>limit</em> and <em>step</em>) then error() end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1789 while (<em>step</em> > 0 and <em>var</em> <= <em>limit</em>) or (<em>step</em> <= 0 and <em>var</em> >= <em>limit</em>) do |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1790 local v = <em>var</em> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1791 <em>block</em> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1792 <em>var</em> = <em>var</em> + <em>step</em> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1793 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1794 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1795 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1796 Note the following: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1797 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1798 <ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1799 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1800 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1801 All three control expressions are evaluated only once, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1802 before the loop starts. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1803 They must all result in numbers. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1804 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1805 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1806 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1807 <code><em>var</em></code>, <code><em>limit</em></code>, and <code><em>step</em></code> are invisible variables. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1808 The names shown here are for explanatory purposes only. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1809 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1810 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1811 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1812 If the third expression (the step) is absent, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1813 then a step of 1 is used. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1814 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1815 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1816 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1817 You can use <b>break</b> to exit a <b>for</b> loop. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1818 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1819 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1820 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1821 The loop variable <code>v</code> is local to the loop; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1822 you cannot use its value after the <b>for</b> ends or is broken. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1823 If you need this value, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1824 assign it to another variable before breaking or exiting the loop. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1825 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1826 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1827 </ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1828 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1829 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1830 The generic <b>for</b> statement works over functions, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1831 called <em>iterators</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1832 On each iteration, the iterator function is called to produce a new value, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1833 stopping when this new value is <b>nil</b>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1834 The generic <b>for</b> loop has the following syntax: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1835 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1836 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1837 stat ::= <b>for</b> namelist <b>in</b> explist <b>do</b> block <b>end</b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1838 namelist ::= Name {‘<b>,</b>’ Name} |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1839 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1840 A <b>for</b> statement like |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1841 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1842 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1843 for <em>var_1</em>, ···, <em>var_n</em> in <em>explist</em> do <em>block</em> end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1844 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1845 is equivalent to the code: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1846 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1847 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1848 do |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1849 local <em>f</em>, <em>s</em>, <em>var</em> = <em>explist</em> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1850 while true do |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1851 local <em>var_1</em>, ···, <em>var_n</em> = <em>f</em>(<em>s</em>, <em>var</em>) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1852 if <em>var_1</em> == nil then break end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1853 <em>var</em> = <em>var_1</em> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1854 <em>block</em> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1855 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1856 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1857 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1858 Note the following: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1859 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1860 <ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1861 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1862 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1863 <code><em>explist</em></code> is evaluated only once. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1864 Its results are an <em>iterator</em> function, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1865 a <em>state</em>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1866 and an initial value for the first <em>iterator variable</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1867 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1868 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1869 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1870 <code><em>f</em></code>, <code><em>s</em></code>, and <code><em>var</em></code> are invisible variables. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1871 The names are here for explanatory purposes only. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1872 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1873 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1874 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1875 You can use <b>break</b> to exit a <b>for</b> loop. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1876 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1877 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1878 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1879 The loop variables <code><em>var_i</em></code> are local to the loop; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1880 you cannot use their values after the <b>for</b> ends. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1881 If you need these values, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1882 then assign them to other variables before breaking or exiting the loop. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1883 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1884 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1885 </ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1886 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1887 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1888 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1889 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1890 <h3>3.3.6 – <a name="3.3.6">Function Calls as Statements</a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1891 To allow possible side-effects, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1892 function calls can be executed as statements: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1893 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1894 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1895 stat ::= functioncall |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1896 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1897 In this case, all returned values are thrown away. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1898 Function calls are explained in <a href="#3.4.9">§3.4.9</a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1899 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1900 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1901 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1902 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1903 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1904 <h3>3.3.7 – <a name="3.3.7">Local Declarations</a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1905 Local variables can be declared anywhere inside a block. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1906 The declaration can include an initial assignment: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1907 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1908 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1909 stat ::= <b>local</b> namelist [‘<b>=</b>’ explist] |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1910 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1911 If present, an initial assignment has the same semantics |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1912 of a multiple assignment (see <a href="#3.3.3">§3.3.3</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1913 Otherwise, all variables are initialized with <b>nil</b>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1914 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1915 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1916 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1917 A chunk is also a block (see <a href="#3.3.2">§3.3.2</a>), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1918 and so local variables can be declared in a chunk outside any explicit block. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1919 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1920 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1921 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1922 The visibility rules for local variables are explained in <a href="#3.5">§3.5</a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1923 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1924 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1925 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1926 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1927 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1928 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1929 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1930 <h2>3.4 – <a name="3.4">Expressions</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1931 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1932 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1933 The basic expressions in Lua are the following: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1934 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1935 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1936 exp ::= prefixexp |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1937 exp ::= <b>nil</b> | <b>false</b> | <b>true</b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1938 exp ::= Number |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1939 exp ::= String |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1940 exp ::= functiondef |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1941 exp ::= tableconstructor |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1942 exp ::= ‘<b>...</b>’ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1943 exp ::= exp binop exp |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1944 exp ::= unop exp |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1945 prefixexp ::= var | functioncall | ‘<b>(</b>’ exp ‘<b>)</b>’ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1946 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1947 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1948 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1949 Numbers and literal strings are explained in <a href="#3.1">§3.1</a>; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1950 variables are explained in <a href="#3.2">§3.2</a>; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1951 function definitions are explained in <a href="#3.4.10">§3.4.10</a>; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1952 function calls are explained in <a href="#3.4.9">§3.4.9</a>; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1953 table constructors are explained in <a href="#3.4.8">§3.4.8</a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1954 Vararg expressions, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1955 denoted by three dots ('<code>...</code>'), can only be used when |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1956 directly inside a vararg function; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1957 they are explained in <a href="#3.4.10">§3.4.10</a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1958 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1959 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1960 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1961 Binary operators comprise arithmetic operators (see <a href="#3.4.1">§3.4.1</a>), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1962 relational operators (see <a href="#3.4.3">§3.4.3</a>), logical operators (see <a href="#3.4.4">§3.4.4</a>), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1963 and the concatenation operator (see <a href="#3.4.5">§3.4.5</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1964 Unary operators comprise the unary minus (see <a href="#3.4.1">§3.4.1</a>), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1965 the unary <b>not</b> (see <a href="#3.4.4">§3.4.4</a>), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1966 and the unary <em>length operator</em> (see <a href="#3.4.6">§3.4.6</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1967 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1968 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1969 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1970 Both function calls and vararg expressions can result in multiple values. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1971 If a function call is used as a statement (see <a href="#3.3.6">§3.3.6</a>), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1972 then its return list is adjusted to zero elements, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1973 thus discarding all returned values. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1974 If an expression is used as the last (or the only) element |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1975 of a list of expressions, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1976 then no adjustment is made |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1977 (unless the expression is enclosed in parentheses). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1978 In all other contexts, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1979 Lua adjusts the result list to one element, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1980 either discarding all values except the first one |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1981 or adding a single <b>nil</b> if there are no values. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1982 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1983 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1984 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1985 Here are some examples: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1986 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1987 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1988 f() -- adjusted to 0 results |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1989 g(f(), x) -- f() is adjusted to 1 result |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1990 g(x, f()) -- g gets x plus all results from f() |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1991 a,b,c = f(), x -- f() is adjusted to 1 result (c gets nil) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1992 a,b = ... -- a gets the first vararg parameter, b gets |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1993 -- the second (both a and b can get nil if there |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1994 -- is no corresponding vararg parameter) |
242
b5a926c481a5
Handle first h1 tag differently.
hugo.tech@gmail.com <hugo.tech@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
241
diff
changeset
|
1995 |
239
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1996 a,b,c = x, f() -- f() is adjusted to 2 results |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1997 a,b,c = f() -- f() is adjusted to 3 results |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1998 return f() -- returns all results from f() |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1999 return ... -- returns all received vararg parameters |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2000 return x,y,f() -- returns x, y, and all results from f() |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2001 {f()} -- creates a list with all results from f() |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2002 {...} -- creates a list with all vararg parameters |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2003 {f(), nil} -- f() is adjusted to 1 result |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2004 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2005 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2006 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2007 Any expression enclosed in parentheses always results in only one value. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2008 Thus, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2009 <code>(f(x,y,z))</code> is always a single value, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2010 even if <code>f</code> returns several values. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2011 (The value of <code>(f(x,y,z))</code> is the first value returned by <code>f</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2012 or <b>nil</b> if <code>f</code> does not return any values.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2013 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2014 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2015 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2016 <h3>3.4.1 – <a name="3.4.1">Arithmetic Operators</a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2017 Lua supports the usual arithmetic operators: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2018 the binary <code>+</code> (addition), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2019 <code>-</code> (subtraction), <code>*</code> (multiplication), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2020 <code>/</code> (division), <code>%</code> (modulo), and <code>^</code> (exponentiation); |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2021 and unary <code>-</code> (mathematical negation). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2022 If the operands are numbers, or strings that can be converted to |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2023 numbers (see <a href="#3.4.2">§3.4.2</a>), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2024 then all operations have the usual meaning. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2025 Exponentiation works for any exponent. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2026 For instance, <code>x^(-0.5)</code> computes the inverse of the square root of <code>x</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2027 Modulo is defined as |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2028 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2029 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2030 a % b == a - math.floor(a/b)*b |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2031 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2032 That is, it is the remainder of a division that rounds |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2033 the quotient towards minus infinity. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2034 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2035 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2036 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2037 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2038 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2039 <h3>3.4.2 – <a name="3.4.2">Coercion</a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2040 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2041 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2042 Lua provides automatic conversion between |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2043 string and number values at run time. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2044 Any arithmetic operation applied to a string tries to convert |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2045 this string to a number, following the rules of the Lua lexer. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2046 (The string may have leading and trailing spaces and a sign.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2047 Conversely, whenever a number is used where a string is expected, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2048 the number is converted to a string, in a reasonable format. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2049 For complete control over how numbers are converted to strings, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2050 use the <code>format</code> function from the string library |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2051 (see <a href="#pdf-string.format"><code>string.format</code></a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2052 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2053 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2054 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2055 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2056 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2057 <h3>3.4.3 – <a name="3.4.3">Relational Operators</a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2058 The relational operators in Lua are |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2059 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2060 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2061 == ~= < > <= >= |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2062 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2063 These operators always result in <b>false</b> or <b>true</b>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2064 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2065 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2066 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2067 Equality (<code>==</code>) first compares the type of its operands. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2068 If the types are different, then the result is <b>false</b>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2069 Otherwise, the values of the operands are compared. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2070 Numbers and strings are compared in the usual way. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2071 Tables, userdata, and threads |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2072 are compared by reference: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2073 two objects are considered equal only if they are the same object. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2074 Every time you create a new object |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2075 (a table, userdata, or thread), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2076 this new object is different from any previously existing object. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2077 Closures with the same reference are always equal. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2078 Closures with any detectable difference |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2079 (different behavior, different definition) are always different. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2080 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2081 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2082 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2083 You can change the way that Lua compares tables and userdata |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2084 by using the "eq" metamethod (see <a href="#2.4">§2.4</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2085 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2086 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2087 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2088 The conversion rules of <a href="#3.4.2">§3.4.2</a> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2089 do not apply to equality comparisons. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2090 Thus, <code>"0"==0</code> evaluates to <b>false</b>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2091 and <code>t[0]</code> and <code>t["0"]</code> denote different |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2092 entries in a table. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2093 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2094 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2095 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2096 The operator <code>~=</code> is exactly the negation of equality (<code>==</code>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2097 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2098 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2099 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2100 The order operators work as follows. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2101 If both arguments are numbers, then they are compared as such. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2102 Otherwise, if both arguments are strings, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2103 then their values are compared according to the current locale. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2104 Otherwise, Lua tries to call the "lt" or the "le" |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2105 metamethod (see <a href="#2.4">§2.4</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2106 A comparison <code>a > b</code> is translated to <code>b < a</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2107 and <code>a >= b</code> is translated to <code>b <= a</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2108 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2109 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2110 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2111 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2112 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2113 <h3>3.4.4 – <a name="3.4.4">Logical Operators</a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2114 The logical operators in Lua are |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2115 <b>and</b>, <b>or</b>, and <b>not</b>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2116 Like the control structures (see <a href="#3.3.4">§3.3.4</a>), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2117 all logical operators consider both <b>false</b> and <b>nil</b> as false |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2118 and anything else as true. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2119 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2120 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2121 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2122 The negation operator <b>not</b> always returns <b>false</b> or <b>true</b>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2123 The conjunction operator <b>and</b> returns its first argument |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2124 if this value is <b>false</b> or <b>nil</b>; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2125 otherwise, <b>and</b> returns its second argument. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2126 The disjunction operator <b>or</b> returns its first argument |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2127 if this value is different from <b>nil</b> and <b>false</b>; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2128 otherwise, <b>or</b> returns its second argument. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2129 Both <b>and</b> and <b>or</b> use short-cut evaluation; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2130 that is, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2131 the second operand is evaluated only if necessary. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2132 Here are some examples: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2133 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2134 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2135 10 or 20 --> 10 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2136 10 or error() --> 10 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2137 nil or "a" --> "a" |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2138 nil and 10 --> nil |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2139 false and error() --> false |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2140 false and nil --> false |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2141 false or nil --> nil |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2142 10 and 20 --> 20 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2143 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2144 (In this manual, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2145 <code>--></code> indicates the result of the preceding expression.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2146 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2147 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2148 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2149 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2150 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2151 <h3>3.4.5 – <a name="3.4.5">Concatenation</a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2152 The string concatenation operator in Lua is |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2153 denoted by two dots ('<code>..</code>'). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2154 If both operands are strings or numbers, then they are converted to |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2155 strings according to the rules mentioned in <a href="#3.4.2">§3.4.2</a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2156 Otherwise, the <code>__concat</code> metamethod is called (see <a href="#2.4">§2.4</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2157 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2158 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2159 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2160 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2161 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2162 <h3>3.4.6 – <a name="3.4.6">The Length Operator</a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2163 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2164 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2165 The length operator is denoted by the unary prefix operator <code>#</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2166 The length of a string is its number of bytes |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2167 (that is, the usual meaning of string length when each |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2168 character is one byte). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2169 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2170 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2171 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2172 A program can modify the behavior of the length operator for |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2173 any value but strings through the <code>__len</code> metamethod (see <a href="#2.4">§2.4</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2174 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2175 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2176 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2177 Unless a <code>__len</code> metamethod is given, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2178 the length of a table <code>t</code> is only defined if the |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2179 table is a <em>sequence</em>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2180 that is, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2181 the set of its positive numeric keys is equal to <em>{1..n}</em> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2182 for some integer <em>n</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2183 In that case, <em>n</em> is its length. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2184 Note that a table like |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2185 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2186 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2187 {10, 20, nil, 40} |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2188 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2189 is not a sequence, because it has the key <code>4</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2190 but does not have the key <code>3</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2191 (So, there is no <em>n</em> such that the set <em>{1..n}</em> is equal |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2192 to the set of positive numeric keys of that table.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2193 Note, however, that non-numeric keys do not interfere |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2194 with whether a table is a sequence. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2195 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2196 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2197 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2198 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2199 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2200 <h3>3.4.7 – <a name="3.4.7">Precedence</a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2201 Operator precedence in Lua follows the table below, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2202 from lower to higher priority: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2203 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2204 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2205 or |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2206 and |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2207 < > <= >= ~= == |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2208 .. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2209 + - |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2210 * / % |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2211 not # - (unary) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2212 ^ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2213 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2214 As usual, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2215 you can use parentheses to change the precedences of an expression. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2216 The concatenation ('<code>..</code>') and exponentiation ('<code>^</code>') |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2217 operators are right associative. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2218 All other binary operators are left associative. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2219 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2220 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2221 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2222 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2223 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2224 <h3>3.4.8 – <a name="3.4.8">Table Constructors</a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2225 Table constructors are expressions that create tables. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2226 Every time a constructor is evaluated, a new table is created. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2227 A constructor can be used to create an empty table |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2228 or to create a table and initialize some of its fields. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2229 The general syntax for constructors is |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2230 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2231 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2232 tableconstructor ::= ‘<b>{</b>’ [fieldlist] ‘<b>}</b>’ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2233 fieldlist ::= field {fieldsep field} [fieldsep] |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2234 field ::= ‘<b>[</b>’ exp ‘<b>]</b>’ ‘<b>=</b>’ exp | Name ‘<b>=</b>’ exp | exp |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2235 fieldsep ::= ‘<b>,</b>’ | ‘<b>;</b>’ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2236 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2237 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2238 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2239 Each field of the form <code>[exp1] = exp2</code> adds to the new table an entry |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2240 with key <code>exp1</code> and value <code>exp2</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2241 A field of the form <code>name = exp</code> is equivalent to |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2242 <code>["name"] = exp</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2243 Finally, fields of the form <code>exp</code> are equivalent to |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2244 <code>[i] = exp</code>, where <code>i</code> are consecutive numerical integers, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2245 starting with 1. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2246 Fields in the other formats do not affect this counting. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2247 For example, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2248 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2249 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2250 a = { [f(1)] = g; "x", "y"; x = 1, f(x), [30] = 23; 45 } |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2251 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2252 is equivalent to |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2253 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2254 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2255 do |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2256 local t = {} |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2257 t[f(1)] = g |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2258 t[1] = "x" -- 1st exp |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2259 t[2] = "y" -- 2nd exp |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2260 t.x = 1 -- t["x"] = 1 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2261 t[3] = f(x) -- 3rd exp |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2262 t[30] = 23 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2263 t[4] = 45 -- 4th exp |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2264 a = t |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2265 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2266 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2267 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2268 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2269 If the last field in the list has the form <code>exp</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2270 and the expression is a function call or a vararg expression, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2271 then all values returned by this expression enter the list consecutively |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2272 (see <a href="#3.4.9">§3.4.9</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2273 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2274 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2275 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2276 The field list can have an optional trailing separator, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2277 as a convenience for machine-generated code. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2278 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2279 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2280 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2281 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2282 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2283 <h3>3.4.9 – <a name="3.4.9">Function Calls</a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2284 A function call in Lua has the following syntax: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2285 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2286 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2287 functioncall ::= prefixexp args |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2288 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2289 In a function call, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2290 first prefixexp and args are evaluated. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2291 If the value of prefixexp has type <em>function</em>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2292 then this function is called |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2293 with the given arguments. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2294 Otherwise, the prefixexp "call" metamethod is called, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2295 having as first parameter the value of prefixexp, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2296 followed by the original call arguments |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2297 (see <a href="#2.4">§2.4</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2298 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2299 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2300 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2301 The form |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2302 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2303 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2304 functioncall ::= prefixexp ‘<b>:</b>’ Name args |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2305 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2306 can be used to call "methods". |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2307 A call <code>v:name(<em>args</em>)</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2308 is syntactic sugar for <code>v.name(v,<em>args</em>)</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2309 except that <code>v</code> is evaluated only once. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2310 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2311 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2312 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2313 Arguments have the following syntax: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2314 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2315 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2316 args ::= ‘<b>(</b>’ [explist] ‘<b>)</b>’ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2317 args ::= tableconstructor |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2318 args ::= String |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2319 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2320 All argument expressions are evaluated before the call. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2321 A call of the form <code>f{<em>fields</em>}</code> is |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2322 syntactic sugar for <code>f({<em>fields</em>})</code>; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2323 that is, the argument list is a single new table. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2324 A call of the form <code>f'<em>string</em>'</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2325 (or <code>f"<em>string</em>"</code> or <code>f[[<em>string</em>]]</code>) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2326 is syntactic sugar for <code>f('<em>string</em>')</code>; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2327 that is, the argument list is a single literal string. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2328 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2329 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2330 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2331 A call of the form <code>return <em>functioncall</em></code> is called |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2332 a <em>tail call</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2333 Lua implements <em>proper tail calls</em> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2334 (or <em>proper tail recursion</em>): |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2335 in a tail call, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2336 the called function reuses the stack entry of the calling function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2337 Therefore, there is no limit on the number of nested tail calls that |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2338 a program can execute. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2339 However, a tail call erases any debug information about the |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2340 calling function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2341 Note that a tail call only happens with a particular syntax, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2342 where the <b>return</b> has one single function call as argument; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2343 this syntax makes the calling function return exactly |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2344 the returns of the called function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2345 So, none of the following examples are tail calls: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2346 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2347 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2348 return (f(x)) -- results adjusted to 1 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2349 return 2 * f(x) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2350 return x, f(x) -- additional results |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2351 f(x); return -- results discarded |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2352 return x or f(x) -- results adjusted to 1 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2353 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2354 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2355 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2356 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2357 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2358 <h3>3.4.10 – <a name="3.4.10">Function Definitions</a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2359 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2360 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2361 The syntax for function definition is |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2362 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2363 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2364 functiondef ::= <b>function</b> funcbody |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2365 funcbody ::= ‘<b>(</b>’ [parlist] ‘<b>)</b>’ block <b>end</b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2366 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2367 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2368 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2369 The following syntactic sugar simplifies function definitions: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2370 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2371 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2372 stat ::= <b>function</b> funcname funcbody |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2373 stat ::= <b>local</b> <b>function</b> Name funcbody |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2374 funcname ::= Name {‘<b>.</b>’ Name} [‘<b>:</b>’ Name] |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2375 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2376 The statement |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2377 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2378 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2379 function f () <em>body</em> end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2380 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2381 translates to |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2382 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2383 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2384 f = function () <em>body</em> end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2385 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2386 The statement |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2387 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2388 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2389 function t.a.b.c.f () <em>body</em> end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2390 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2391 translates to |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2392 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2393 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2394 t.a.b.c.f = function () <em>body</em> end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2395 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2396 The statement |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2397 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2398 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2399 local function f () <em>body</em> end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2400 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2401 translates to |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2402 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2403 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2404 local f; f = function () <em>body</em> end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2405 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2406 not to |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2407 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2408 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2409 local f = function () <em>body</em> end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2410 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2411 (This only makes a difference when the body of the function |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2412 contains references to <code>f</code>.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2413 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2414 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2415 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2416 A function definition is an executable expression, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2417 whose value has type <em>function</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2418 When Lua precompiles a chunk, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2419 all its function bodies are precompiled too. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2420 Then, whenever Lua executes the function definition, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2421 the function is <em>instantiated</em> (or <em>closed</em>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2422 This function instance (or <em>closure</em>) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2423 is the final value of the expression. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2424 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2425 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2426 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2427 Parameters act as local variables that are |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2428 initialized with the argument values: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2429 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2430 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2431 parlist ::= namelist [‘<b>,</b>’ ‘<b>...</b>’] | ‘<b>...</b>’ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2432 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2433 When a function is called, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2434 the list of arguments is adjusted to |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2435 the length of the list of parameters, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2436 unless the function is a <em>vararg function</em>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2437 which is indicated by three dots ('<code>...</code>') |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2438 at the end of its parameter list. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2439 A vararg function does not adjust its argument list; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2440 instead, it collects all extra arguments and supplies them |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2441 to the function through a <em>vararg expression</em>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2442 which is also written as three dots. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2443 The value of this expression is a list of all actual extra arguments, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2444 similar to a function with multiple results. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2445 If a vararg expression is used inside another expression |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2446 or in the middle of a list of expressions, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2447 then its return list is adjusted to one element. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2448 If the expression is used as the last element of a list of expressions, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2449 then no adjustment is made |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2450 (unless that last expression is enclosed in parentheses). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2451 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2452 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2453 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2454 As an example, consider the following definitions: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2455 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2456 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2457 function f(a, b) end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2458 function g(a, b, ...) end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2459 function r() return 1,2,3 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2460 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2461 Then, we have the following mapping from arguments to parameters and |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2462 to the vararg expression: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2463 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2464 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2465 CALL PARAMETERS |
242
b5a926c481a5
Handle first h1 tag differently.
hugo.tech@gmail.com <hugo.tech@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
241
diff
changeset
|
2466 |
239
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2467 f(3) a=3, b=nil |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2468 f(3, 4) a=3, b=4 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2469 f(3, 4, 5) a=3, b=4 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2470 f(r(), 10) a=1, b=10 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2471 f(r()) a=1, b=2 |
242
b5a926c481a5
Handle first h1 tag differently.
hugo.tech@gmail.com <hugo.tech@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
241
diff
changeset
|
2472 |
239
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2473 g(3) a=3, b=nil, ... --> (nothing) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2474 g(3, 4) a=3, b=4, ... --> (nothing) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2475 g(3, 4, 5, 8) a=3, b=4, ... --> 5 8 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2476 g(5, r()) a=5, b=1, ... --> 2 3 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2477 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2478 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2479 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2480 Results are returned using the <b>return</b> statement (see <a href="#3.3.4">§3.3.4</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2481 If control reaches the end of a function |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2482 without encountering a <b>return</b> statement, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2483 then the function returns with no results. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2484 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2485 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2486 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2487 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2488 There is a system-dependent limit on the number of values |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2489 that a function may return. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2490 This limit is guaranteed to be larger than 1000. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2491 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2492 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2493 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2494 The <em>colon</em> syntax |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2495 is used for defining <em>methods</em>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2496 that is, functions that have an implicit extra parameter <code>self</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2497 Thus, the statement |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2498 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2499 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2500 function t.a.b.c:f (<em>params</em>) <em>body</em> end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2501 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2502 is syntactic sugar for |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2503 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2504 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2505 t.a.b.c.f = function (self, <em>params</em>) <em>body</em> end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2506 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2507 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2508 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2509 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2510 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2511 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2512 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2513 <h2>3.5 – <a name="3.5">Visibility Rules</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2514 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2515 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2516 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2517 Lua is a lexically scoped language. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2518 The scope of a local variable begins at the first statement after |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2519 its declaration and lasts until the last non-void statement |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2520 of the innermost block that includes the declaration. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2521 Consider the following example: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2522 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2523 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2524 x = 10 -- global variable |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2525 do -- new block |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2526 local x = x -- new 'x', with value 10 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2527 print(x) --> 10 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2528 x = x+1 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2529 do -- another block |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2530 local x = x+1 -- another 'x' |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2531 print(x) --> 12 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2532 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2533 print(x) --> 11 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2534 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2535 print(x) --> 10 (the global one) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2536 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2537 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2538 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2539 Notice that, in a declaration like <code>local x = x</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2540 the new <code>x</code> being declared is not in scope yet, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2541 and so the second <code>x</code> refers to the outside variable. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2542 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2543 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2544 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2545 Because of the lexical scoping rules, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2546 local variables can be freely accessed by functions |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2547 defined inside their scope. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2548 A local variable used by an inner function is called |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2549 an <em>upvalue</em>, or <em>external local variable</em>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2550 inside the inner function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2551 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2552 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2553 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2554 Notice that each execution of a <b>local</b> statement |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2555 defines new local variables. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2556 Consider the following example: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2557 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2558 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2559 a = {} |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2560 local x = 20 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2561 for i=1,10 do |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2562 local y = 0 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2563 a[i] = function () y=y+1; return x+y end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2564 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2565 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2566 The loop creates ten closures |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2567 (that is, ten instances of the anonymous function). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2568 Each of these closures uses a different <code>y</code> variable, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2569 while all of them share the same <code>x</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2570 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2571 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2572 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2573 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2574 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2575 <h1>4 – <a name="4">The Application Program Interface</a></h1> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2576 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2577 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2578 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2579 This section describes the C API for Lua, that is, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2580 the set of C functions available to the host program to communicate |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2581 with Lua. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2582 All API functions and related types and constants |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2583 are declared in the header file <a name="pdf-lua.h"><code>lua.h</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2584 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2585 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2586 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2587 Even when we use the term "function", |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2588 any facility in the API may be provided as a macro instead. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2589 Except where stated otherwise, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2590 all such macros use each of their arguments exactly once |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2591 (except for the first argument, which is always a Lua state), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2592 and so do not generate any hidden side-effects. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2593 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2594 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2595 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2596 As in most C libraries, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2597 the Lua API functions do not check their arguments for validity or consistency. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2598 However, you can change this behavior by compiling Lua |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2599 with the macro <a name="pdf-LUA_USE_APICHECK"><code>LUA_USE_APICHECK</code></a> defined. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2600 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2601 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2602 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2603 <h2>4.1 – <a name="4.1">The Stack</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2604 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2605 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2606 Lua uses a <em>virtual stack</em> to pass values to and from C. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2607 Each element in this stack represents a Lua value |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2608 (<b>nil</b>, number, string, etc.). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2609 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2610 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2611 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2612 Whenever Lua calls C, the called function gets a new stack, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2613 which is independent of previous stacks and of stacks of |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2614 C functions that are still active. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2615 This stack initially contains any arguments to the C function |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2616 and it is where the C function pushes its results |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2617 to be returned to the caller (see <a href="#lua_CFunction"><code>lua_CFunction</code></a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2618 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2619 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2620 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2621 For convenience, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2622 most query operations in the API do not follow a strict stack discipline. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2623 Instead, they can refer to any element in the stack |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2624 by using an <em>index</em>: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2625 A positive index represents an absolute stack position |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2626 (starting at 1); |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2627 a negative index represents an offset relative to the top of the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2628 More specifically, if the stack has <em>n</em> elements, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2629 then index 1 represents the first element |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2630 (that is, the element that was pushed onto the stack first) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2631 and |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2632 index <em>n</em> represents the last element; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2633 index -1 also represents the last element |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2634 (that is, the element at the top) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2635 and index <em>-n</em> represents the first element. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2636 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2637 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2638 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2639 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2640 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2641 <h2>4.2 – <a name="4.2">Stack Size</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2642 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2643 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2644 When you interact with the Lua API, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2645 you are responsible for ensuring consistency. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2646 In particular, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2647 <em>you are responsible for controlling stack overflow</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2648 You can use the function <a href="#lua_checkstack"><code>lua_checkstack</code></a> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2649 to ensure that the stack has extra slots when pushing new elements. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2650 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2651 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2652 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2653 Whenever Lua calls C, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2654 it ensures that the stack has at least <a name="pdf-LUA_MINSTACK"><code>LUA_MINSTACK</code></a> extra slots. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2655 <code>LUA_MINSTACK</code> is defined as 20, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2656 so that usually you do not have to worry about stack space |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2657 unless your code has loops pushing elements onto the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2658 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2659 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2660 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2661 When you call a Lua function |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2662 without a fixed number of results (see <a href="#lua_call"><code>lua_call</code></a>), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2663 Lua ensures that the stack has enough size for all results, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2664 but it does not ensure any extra space. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2665 So, before pushing anything in the stack after such a call |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2666 you should use <a href="#lua_checkstack"><code>lua_checkstack</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2667 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2668 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2669 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2670 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2671 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2672 <h2>4.3 – <a name="4.3">Valid and Acceptable Indices</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2673 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2674 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2675 Any function in the API that receives stack indices |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2676 works only with <em>valid indices</em> or <em>acceptable indices</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2677 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2678 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2679 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2680 A <em>valid index</em> is an index that refers to a |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2681 real position within the stack, that is, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2682 its position lies between 1 and the stack top |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2683 (<code>1 ≤ abs(index) ≤ top</code>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2684 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2685 Usually, functions that can modify the value at an index |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2686 require valid indices. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2687 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2688 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2689 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2690 Unless otherwise noted, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2691 any function that accepts valid indices also accepts <em>pseudo-indices</em>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2692 which represent some Lua values that are accessible to C code |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2693 but which are not in the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2694 Pseudo-indices are used to access the registry |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2695 and the upvalues of a C function (see <a href="#4.4">§4.4</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2696 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2697 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2698 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2699 Functions that do not need a specific stack position, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2700 but only a value in the stack (e.g., query functions), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2701 can be called with acceptable indices. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2702 An <em>acceptable index</em> can be any valid index, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2703 including the pseudo-indices, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2704 but it also can be any positive index after the stack top |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2705 within the space allocated for the stack, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2706 that is, indices up to the stack size. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2707 (Note that 0 is never an acceptable index.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2708 Except when noted otherwise, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2709 functions in the API work with acceptable indices. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2710 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2711 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2712 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2713 Acceptable indices serve to avoid extra tests |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2714 against the stack top when querying the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2715 For instance, a C function can query its third argument |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2716 without the need to first check whether there is a third argument, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2717 that is, without the need to check whether 3 is a valid index. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2718 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2719 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2720 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2721 For functions that can be called with acceptable indices, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2722 any non-valid index is treated as if it |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2723 contains a value of a virtual type <a name="pdf-LUA_TNONE"><code>LUA_TNONE</code></a>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2724 which behaves like a nil value. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2725 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2726 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2727 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2728 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2729 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2730 <h2>4.4 – <a name="4.4">C Closures</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2731 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2732 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2733 When a C function is created, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2734 it is possible to associate some values with it, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2735 thus creating a <em>C closure</em> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2736 (see <a href="#lua_pushcclosure"><code>lua_pushcclosure</code></a>); |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2737 these values are called <em>upvalues</em> and are |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2738 accessible to the function whenever it is called. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2739 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2740 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2741 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2742 Whenever a C function is called, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2743 its upvalues are located at specific pseudo-indices. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2744 These pseudo-indices are produced by the macro |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2745 <a href="#lua_upvalueindex"><code>lua_upvalueindex</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2746 The first value associated with a function is at position |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2747 <code>lua_upvalueindex(1)</code>, and so on. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2748 Any access to <code>lua_upvalueindex(<em>n</em>)</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2749 where <em>n</em> is greater than the number of upvalues of the |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2750 current function (but not greater than 256), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2751 produces an acceptable but invalid index. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2752 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2753 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2754 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2755 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2756 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2757 <h2>4.5 – <a name="4.5">Registry</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2758 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2759 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2760 Lua provides a <em>registry</em>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2761 a predefined table that can be used by any C code to |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2762 store whatever Lua values it needs to store. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2763 The registry table is always located at pseudo-index |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2764 <a name="pdf-LUA_REGISTRYINDEX"><code>LUA_REGISTRYINDEX</code></a>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2765 which is a valid index. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2766 Any C library can store data into this table, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2767 but it should take care to choose keys |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2768 that are different from those used |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2769 by other libraries, to avoid collisions. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2770 Typically, you should use as key a string containing your library name, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2771 or a light userdata with the address of a C object in your code, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2772 or any Lua object created by your code. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2773 As with global names, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2774 string keys starting with an underscore followed by |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2775 uppercase letters are reserved for Lua. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2776 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2777 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2778 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2779 The integer keys in the registry are used by the reference mechanism, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2780 implemented by the auxiliary library, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2781 and by some predefined values. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2782 Therefore, integer keys should not be used for other purposes. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2783 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2784 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2785 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2786 When you create a new Lua state, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2787 its registry comes with some predefined values. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2788 These predefined values are indexed with integer keys |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2789 defined as constants in <code>lua.h</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2790 The following constants are defined: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2791 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2792 <ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2793 <li><b><a name="pdf-LUA_RIDX_MAINTHREAD"><code>LUA_RIDX_MAINTHREAD</code></a>: </b> At this index the registry has |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2794 the main thread of the state. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2795 (The main thread is the one created together with the state.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2796 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2797 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2798 <li><b><a name="pdf-LUA_RIDX_GLOBALS"><code>LUA_RIDX_GLOBALS</code></a>: </b> At this index the registry has |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2799 the global environment. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2800 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2801 </ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2802 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2803 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2804 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2805 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2806 <h2>4.6 – <a name="4.6">Error Handling in C</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2807 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2808 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2809 Internally, Lua uses the C <code>longjmp</code> facility to handle errors. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2810 (You can also choose to use exceptions if you compile Lua as C++; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2811 search for <code>LUAI_THROW</code> in the source code.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2812 When Lua faces any error |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2813 (such as a memory allocation error, type errors, syntax errors, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2814 and runtime errors) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2815 it <em>raises</em> an error; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2816 that is, it does a long jump. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2817 A <em>protected environment</em> uses <code>setjmp</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2818 to set a recovery point; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2819 any error jumps to the most recent active recovery point. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2820 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2821 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2822 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2823 If an error happens outside any protected environment, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2824 Lua calls a <em>panic function</em> (see <a href="#lua_atpanic"><code>lua_atpanic</code></a>) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2825 and then calls <code>abort</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2826 thus exiting the host application. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2827 Your panic function can avoid this exit by |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2828 never returning |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2829 (e.g., doing a long jump to your own recovery point outside Lua). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2830 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2831 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2832 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2833 The panic function runs as if it were a message handler (see <a href="#2.3">§2.3</a>); |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2834 in particular, the error message is at the top of the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2835 However, there is no guarantees about stack space. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2836 To push anything on the stack, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2837 the panic function should first check the available space (see <a href="#4.2">§4.2</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2838 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2839 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2840 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2841 Most functions in the API can throw an error, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2842 for instance due to a memory allocation error. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2843 The documentation for each function indicates whether |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2844 it can throw errors. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2845 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2846 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2847 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2848 Inside a C function you can throw an error by calling <a href="#lua_error"><code>lua_error</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2849 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2850 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2851 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2852 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2853 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2854 <h2>4.7 – <a name="4.7">Handling Yields in C</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2855 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2856 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2857 Internally, Lua uses the C <code>longjmp</code> facility to yield a coroutine. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2858 Therefore, if a function <code>foo</code> calls an API function |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2859 and this API function yields |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2860 (directly or indirectly by calling another function that yields), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2861 Lua cannot return to <code>foo</code> any more, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2862 because the <code>longjmp</code> removes its frame from the C stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2863 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2864 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2865 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2866 To avoid this kind of problem, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2867 Lua raises an error whenever it tries to yield across an API call, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2868 except for three functions: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2869 <a href="#lua_yieldk"><code>lua_yieldk</code></a>, <a href="#lua_callk"><code>lua_callk</code></a>, and <a href="#lua_pcallk"><code>lua_pcallk</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2870 All those functions receive a <em>continuation function</em> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2871 (as a parameter called <code>k</code>) to continue execution after a yield. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2872 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2873 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2874 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2875 We need to set some terminology to explain continuations. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2876 We have a C function called from Lua which we will call |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2877 the <em>original function</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2878 This original function then calls one of those three functions in the C API, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2879 which we will call the <em>callee function</em>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2880 that then yields the current thread. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2881 (This can happen when the callee function is <a href="#lua_yieldk"><code>lua_yieldk</code></a>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2882 or when the callee function is either <a href="#lua_callk"><code>lua_callk</code></a> or <a href="#lua_pcallk"><code>lua_pcallk</code></a> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2883 and the function called by them yields.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2884 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2885 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2886 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2887 Suppose the running thread yields while executing the callee function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2888 After the thread resumes, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2889 it eventually will finish running the callee function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2890 However, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2891 the callee function cannot return to the original function, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2892 because its frame in the C stack was destroyed by the yield. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2893 Instead, Lua calls a <em>continuation function</em>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2894 which was given as an argument to the callee function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2895 As the name implies, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2896 the continuation function should continue the task |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2897 of the original function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2898 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2899 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2900 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2901 Lua treats the continuation function as if it were the original function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2902 The continuation function receives the same Lua stack |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2903 from the original function, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2904 in the same state it would be if the callee function had returned. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2905 (For instance, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2906 after a <a href="#lua_callk"><code>lua_callk</code></a> the function and its arguments are |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2907 removed from the stack and replaced by the results from the call.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2908 It also has the same upvalues. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2909 Whatever it returns is handled by Lua as if it were the return |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2910 of the original function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2911 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2912 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2913 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2914 The only difference in the Lua state between the original function |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2915 and its continuation is the result of a call to <a href="#lua_getctx"><code>lua_getctx</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2916 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2917 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2918 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2919 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2920 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2921 <h2>4.8 – <a name="4.8">Functions and Types</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2922 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2923 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2924 Here we list all functions and types from the C API in |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2925 alphabetical order. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2926 Each function has an indicator like this: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2927 <span class="apii">[-o, +p, <em>x</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2928 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2929 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2930 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2931 The first field, <code>o</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2932 is how many elements the function pops from the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2933 The second field, <code>p</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2934 is how many elements the function pushes onto the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2935 (Any function always pushes its results after popping its arguments.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2936 A field in the form <code>x|y</code> means the function can push (or pop) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2937 <code>x</code> or <code>y</code> elements, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2938 depending on the situation; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2939 an interrogation mark '<code>?</code>' means that |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2940 we cannot know how many elements the function pops/pushes |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2941 by looking only at its arguments |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2942 (e.g., they may depend on what is on the stack). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2943 The third field, <code>x</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2944 tells whether the function may throw errors: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2945 '<code>-</code>' means the function never throws any error; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2946 '<code>e</code>' means the function may throw errors; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2947 '<code>v</code>' means the function may throw an error on purpose. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2948 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2949 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2950 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2951 <hr><h3><a name="lua_absindex"><code>lua_absindex</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2952 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2953 <pre>int lua_absindex (lua_State *L, int idx);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2954 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2955 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2956 Converts the acceptable index <code>idx</code> into an absolute index |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2957 (that is, one that does not depend on the stack top). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2958 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2959 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2960 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2961 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2962 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2963 <hr><h3><a name="lua_Alloc"><code>lua_Alloc</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2964 <pre>typedef void * (*lua_Alloc) (void *ud, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2965 void *ptr, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2966 size_t osize, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2967 size_t nsize);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2968 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2969 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2970 The type of the memory-allocation function used by Lua states. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2971 The allocator function must provide a |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2972 functionality similar to <code>realloc</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2973 but not exactly the same. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2974 Its arguments are |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2975 <code>ud</code>, an opaque pointer passed to <a href="#lua_newstate"><code>lua_newstate</code></a>; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2976 <code>ptr</code>, a pointer to the block being allocated/reallocated/freed; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2977 <code>osize</code>, the original size of the block or some code about what |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2978 is being allocated; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2979 <code>nsize</code>, the new size of the block. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2980 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2981 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2982 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2983 When <code>ptr</code> is not <code>NULL</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2984 <code>osize</code> is the size of the block pointed by <code>ptr</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2985 that is, the size given when it was allocated or reallocated. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2986 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2987 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2988 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2989 When <code>ptr</code> is <code>NULL</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2990 <code>osize</code> encodes the kind of object that Lua is allocating. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2991 <code>osize</code> is any of |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2992 <a href="#pdf-LUA_TSTRING"><code>LUA_TSTRING</code></a>, <a href="#pdf-LUA_TTABLE"><code>LUA_TTABLE</code></a>, <a href="#pdf-LUA_TFUNCTION"><code>LUA_TFUNCTION</code></a>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2993 <a href="#pdf-LUA_TUSERDATA"><code>LUA_TUSERDATA</code></a>, or <a href="#pdf-LUA_TTHREAD"><code>LUA_TTHREAD</code></a> when (and only when) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2994 Lua is creating a new object of that type. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2995 When <code>osize</code> is some other value, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2996 Lua is allocating memory for something else. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2997 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2998 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2999 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3000 Lua assumes the following behavior from the allocator function: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3001 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3002 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3003 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3004 When <code>nsize</code> is zero, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3005 the allocator should behave like <code>free</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3006 and return <code>NULL</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3007 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3008 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3009 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3010 When <code>nsize</code> is not zero, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3011 the allocator should behave like <code>realloc</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3012 The allocator returns <code>NULL</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3013 if and only if it cannot fulfill the request. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3014 Lua assumes that the allocator never fails when |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3015 <code>osize >= nsize</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3016 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3017 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3018 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3019 Here is a simple implementation for the allocator function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3020 It is used in the auxiliary library by <a href="#luaL_newstate"><code>luaL_newstate</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3021 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3022 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3023 static void *l_alloc (void *ud, void *ptr, size_t osize, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3024 size_t nsize) { |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3025 (void)ud; (void)osize; /* not used */ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3026 if (nsize == 0) { |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3027 free(ptr); |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3028 return NULL; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3029 } |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3030 else |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3031 return realloc(ptr, nsize); |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3032 } |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3033 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3034 Note that Standard C ensures |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3035 that <code>free(NULL)</code> has no effect and that |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3036 <code>realloc(NULL, size)</code> is equivalent to <code>malloc(size)</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3037 This code assumes that <code>realloc</code> does not fail when shrinking a block. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3038 (Although Standard C does not ensure this behavior, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3039 it seems to be a safe assumption.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3040 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3041 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3042 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3043 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3044 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3045 <hr><h3><a name="lua_arith"><code>lua_arith</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3046 <span class="apii">[-(2|1), +1, <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3047 <pre>void lua_arith (lua_State *L, int op);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3048 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3049 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3050 Performs an arithmetic operation over the two values |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3051 (or one, in the case of negation) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3052 at the top of the stack, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3053 with the value at the top being the second operand, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3054 pops these values, and pushes the result of the operation. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3055 The function follows the semantics of the corresponding Lua operator |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3056 (that is, it may call metamethods). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3057 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3058 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3059 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3060 The value of <code>op</code> must be one of the following constants: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3061 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3062 <ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3063 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3064 <li><b><a name="pdf-LUA_OPADD"><code>LUA_OPADD</code></a>: </b> performs addition (<code>+</code>)</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3065 <li><b><a name="pdf-LUA_OPSUB"><code>LUA_OPSUB</code></a>: </b> performs subtraction (<code>-</code>)</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3066 <li><b><a name="pdf-LUA_OPMUL"><code>LUA_OPMUL</code></a>: </b> performs multiplication (<code>*</code>)</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3067 <li><b><a name="pdf-LUA_OPDIV"><code>LUA_OPDIV</code></a>: </b> performs division (<code>/</code>)</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3068 <li><b><a name="pdf-LUA_OPMOD"><code>LUA_OPMOD</code></a>: </b> performs modulo (<code>%</code>)</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3069 <li><b><a name="pdf-LUA_OPPOW"><code>LUA_OPPOW</code></a>: </b> performs exponentiation (<code>^</code>)</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3070 <li><b><a name="pdf-LUA_OPUNM"><code>LUA_OPUNM</code></a>: </b> performs mathematical negation (unary <code>-</code>)</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3071 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3072 </ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3073 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3074 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3075 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3076 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3077 <hr><h3><a name="lua_atpanic"><code>lua_atpanic</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3078 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3079 <pre>lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3080 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3081 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3082 Sets a new panic function and returns the old one (see <a href="#4.6">§4.6</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3083 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3084 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3085 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3086 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3087 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3088 <hr><h3><a name="lua_call"><code>lua_call</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3089 <span class="apii">[-(nargs+1), +nresults, <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3090 <pre>void lua_call (lua_State *L, int nargs, int nresults);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3091 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3092 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3093 Calls a function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3094 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3095 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3096 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3097 To call a function you must use the following protocol: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3098 first, the function to be called is pushed onto the stack; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3099 then, the arguments to the function are pushed |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3100 in direct order; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3101 that is, the first argument is pushed first. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3102 Finally you call <a href="#lua_call"><code>lua_call</code></a>; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3103 <code>nargs</code> is the number of arguments that you pushed onto the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3104 All arguments and the function value are popped from the stack |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3105 when the function is called. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3106 The function results are pushed onto the stack when the function returns. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3107 The number of results is adjusted to <code>nresults</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3108 unless <code>nresults</code> is <a name="pdf-LUA_MULTRET"><code>LUA_MULTRET</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3109 In this case, all results from the function are pushed. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3110 Lua takes care that the returned values fit into the stack space. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3111 The function results are pushed onto the stack in direct order |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3112 (the first result is pushed first), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3113 so that after the call the last result is on the top of the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3114 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3115 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3116 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3117 Any error inside the called function is propagated upwards |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3118 (with a <code>longjmp</code>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3119 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3120 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3121 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3122 The following example shows how the host program can do the |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3123 equivalent to this Lua code: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3124 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3125 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3126 a = f("how", t.x, 14) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3127 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3128 Here it is in C: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3129 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3130 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3131 lua_getglobal(L, "f"); /* function to be called */ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3132 lua_pushstring(L, "how"); /* 1st argument */ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3133 lua_getglobal(L, "t"); /* table to be indexed */ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3134 lua_getfield(L, -1, "x"); /* push result of t.x (2nd arg) */ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3135 lua_remove(L, -2); /* remove 't' from the stack */ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3136 lua_pushinteger(L, 14); /* 3rd argument */ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3137 lua_call(L, 3, 1); /* call 'f' with 3 arguments and 1 result */ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3138 lua_setglobal(L, "a"); /* set global 'a' */ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3139 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3140 Note that the code above is "balanced": |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3141 at its end, the stack is back to its original configuration. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3142 This is considered good programming practice. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3143 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3144 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3145 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3146 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3147 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3148 <hr><h3><a name="lua_callk"><code>lua_callk</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3149 <span class="apii">[-(nargs + 1), +nresults, <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3150 <pre>void lua_callk (lua_State *L, int nargs, int nresults, int ctx, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3151 lua_CFunction k);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3152 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3153 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3154 This function behaves exactly like <a href="#lua_call"><code>lua_call</code></a>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3155 but allows the called function to yield (see <a href="#4.7">§4.7</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3156 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3157 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3158 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3159 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3160 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3161 <hr><h3><a name="lua_CFunction"><code>lua_CFunction</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3162 <pre>typedef int (*lua_CFunction) (lua_State *L);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3163 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3164 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3165 Type for C functions. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3166 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3167 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3168 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3169 In order to communicate properly with Lua, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3170 a C function must use the following protocol, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3171 which defines the way parameters and results are passed: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3172 a C function receives its arguments from Lua in its stack |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3173 in direct order (the first argument is pushed first). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3174 So, when the function starts, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3175 <code>lua_gettop(L)</code> returns the number of arguments received by the function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3176 The first argument (if any) is at index 1 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3177 and its last argument is at index <code>lua_gettop(L)</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3178 To return values to Lua, a C function just pushes them onto the stack, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3179 in direct order (the first result is pushed first), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3180 and returns the number of results. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3181 Any other value in the stack below the results will be properly |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3182 discarded by Lua. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3183 Like a Lua function, a C function called by Lua can also return |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3184 many results. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3185 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3186 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3187 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3188 As an example, the following function receives a variable number |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3189 of numerical arguments and returns their average and sum: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3190 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3191 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3192 static int foo (lua_State *L) { |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3193 int n = lua_gettop(L); /* number of arguments */ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3194 lua_Number sum = 0; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3195 int i; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3196 for (i = 1; i <= n; i++) { |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3197 if (!lua_isnumber(L, i)) { |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3198 lua_pushstring(L, "incorrect argument"); |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3199 lua_error(L); |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3200 } |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3201 sum += lua_tonumber(L, i); |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3202 } |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3203 lua_pushnumber(L, sum/n); /* first result */ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3204 lua_pushnumber(L, sum); /* second result */ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3205 return 2; /* number of results */ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3206 } |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3207 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3208 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3209 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3210 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3211 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3212 <hr><h3><a name="lua_checkstack"><code>lua_checkstack</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3213 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3214 <pre>int lua_checkstack (lua_State *L, int extra);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3215 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3216 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3217 Ensures that there are at least <code>extra</code> free stack slots in the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3218 It returns false if it cannot fulfill the request, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3219 because it would cause the stack to be larger than a fixed maximum size |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3220 (typically at least a few thousand elements) or |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3221 because it cannot allocate memory for the new stack size. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3222 This function never shrinks the stack; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3223 if the stack is already larger than the new size, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3224 it is left unchanged. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3225 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3226 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3227 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3228 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3229 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3230 <hr><h3><a name="lua_close"><code>lua_close</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3231 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3232 <pre>void lua_close (lua_State *L);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3233 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3234 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3235 Destroys all objects in the given Lua state |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3236 (calling the corresponding garbage-collection metamethods, if any) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3237 and frees all dynamic memory used by this state. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3238 On several platforms, you may not need to call this function, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3239 because all resources are naturally released when the host program ends. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3240 On the other hand, long-running programs that create multiple states, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3241 such as daemons or web servers, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3242 might need to close states as soon as they are not needed. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3243 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3244 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3245 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3246 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3247 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3248 <hr><h3><a name="lua_compare"><code>lua_compare</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3249 <span class="apii">[-0, +0, <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3250 <pre>int lua_compare (lua_State *L, int index1, int index2, int op);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3251 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3252 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3253 Compares two Lua values. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3254 Returns 1 if the value at index <code>index1</code> satisfies <code>op</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3255 when compared with the value at index <code>index2</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3256 following the semantics of the corresponding Lua operator |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3257 (that is, it may call metamethods). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3258 Otherwise returns 0. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3259 Also returns 0 if any of the indices is non valid. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3260 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3261 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3262 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3263 The value of <code>op</code> must be one of the following constants: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3264 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3265 <ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3266 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3267 <li><b><a name="pdf-LUA_OPEQ"><code>LUA_OPEQ</code></a>: </b> compares for equality (<code>==</code>)</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3268 <li><b><a name="pdf-LUA_OPLT"><code>LUA_OPLT</code></a>: </b> compares for less than (<code><</code>)</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3269 <li><b><a name="pdf-LUA_OPLE"><code>LUA_OPLE</code></a>: </b> compares for less or equal (<code><=</code>)</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3270 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3271 </ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3272 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3273 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3274 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3275 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3276 <hr><h3><a name="lua_concat"><code>lua_concat</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3277 <span class="apii">[-n, +1, <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3278 <pre>void lua_concat (lua_State *L, int n);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3279 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3280 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3281 Concatenates the <code>n</code> values at the top of the stack, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3282 pops them, and leaves the result at the top. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3283 If <code>n</code> is 1, the result is the single value on the stack |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3284 (that is, the function does nothing); |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3285 if <code>n</code> is 0, the result is the empty string. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3286 Concatenation is performed following the usual semantics of Lua |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3287 (see <a href="#3.4.5">§3.4.5</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3288 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3289 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3290 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3291 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3292 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3293 <hr><h3><a name="lua_copy"><code>lua_copy</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3294 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3295 <pre>void lua_copy (lua_State *L, int fromidx, int toidx);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3296 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3297 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3298 Moves the element at index <code>fromidx</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3299 into the valid index <code>toidx</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3300 without shifting any element |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3301 (therefore replacing the value at that position). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3302 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3303 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3304 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3305 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3306 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3307 <hr><h3><a name="lua_createtable"><code>lua_createtable</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3308 <span class="apii">[-0, +1, <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3309 <pre>void lua_createtable (lua_State *L, int narr, int nrec);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3310 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3311 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3312 Creates a new empty table and pushes it onto the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3313 Parameter <code>narr</code> is a hint for how many elements the table |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3314 will have as a sequence; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3315 parameter <code>nrec</code> is a hint for how many other elements |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3316 the table will have. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3317 Lua may use these hints to preallocate memory for the new table. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3318 This pre-allocation is useful for performance when you know in advance |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3319 how many elements the table will have. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3320 Otherwise you can use the function <a href="#lua_newtable"><code>lua_newtable</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3321 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3322 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3323 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3324 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3325 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3326 <hr><h3><a name="lua_dump"><code>lua_dump</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3327 <span class="apii">[-0, +0, <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3328 <pre>int lua_dump (lua_State *L, lua_Writer writer, void *data);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3329 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3330 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3331 Dumps a function as a binary chunk. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3332 Receives a Lua function on the top of the stack |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3333 and produces a binary chunk that, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3334 if loaded again, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3335 results in a function equivalent to the one dumped. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3336 As it produces parts of the chunk, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3337 <a href="#lua_dump"><code>lua_dump</code></a> calls function <code>writer</code> (see <a href="#lua_Writer"><code>lua_Writer</code></a>) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3338 with the given <code>data</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3339 to write them. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3340 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3341 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3342 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3343 The value returned is the error code returned by the last |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3344 call to the writer; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3345 0 means no errors. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3346 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3347 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3348 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3349 This function does not pop the Lua function from the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3350 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3351 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3352 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3353 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3354 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3355 <hr><h3><a name="lua_error"><code>lua_error</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3356 <span class="apii">[-1, +0, <em>v</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3357 <pre>int lua_error (lua_State *L);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3358 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3359 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3360 Generates a Lua error. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3361 The error message (which can actually be a Lua value of any type) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3362 must be on the stack top. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3363 This function does a long jump, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3364 and therefore never returns |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3365 (see <a href="#luaL_error"><code>luaL_error</code></a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3366 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3367 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3368 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3369 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3370 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3371 <hr><h3><a name="lua_gc"><code>lua_gc</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3372 <span class="apii">[-0, +0, <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3373 <pre>int lua_gc (lua_State *L, int what, int data);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3374 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3375 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3376 Controls the garbage collector. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3377 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3378 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3379 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3380 This function performs several tasks, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3381 according to the value of the parameter <code>what</code>: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3382 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3383 <ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3384 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3385 <li><b><code>LUA_GCSTOP</code>: </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3386 stops the garbage collector. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3387 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3388 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3389 <li><b><code>LUA_GCRESTART</code>: </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3390 restarts the garbage collector. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3391 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3392 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3393 <li><b><code>LUA_GCCOLLECT</code>: </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3394 performs a full garbage-collection cycle. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3395 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3396 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3397 <li><b><code>LUA_GCCOUNT</code>: </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3398 returns the current amount of memory (in Kbytes) in use by Lua. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3399 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3400 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3401 <li><b><code>LUA_GCCOUNTB</code>: </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3402 returns the remainder of dividing the current amount of bytes of |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3403 memory in use by Lua by 1024. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3404 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3405 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3406 <li><b><code>LUA_GCSTEP</code>: </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3407 performs an incremental step of garbage collection. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3408 The step "size" is controlled by <code>data</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3409 (larger values mean more steps) in a non-specified way. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3410 If you want to control the step size |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3411 you must experimentally tune the value of <code>data</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3412 The function returns 1 if the step finished a |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3413 garbage-collection cycle. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3414 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3415 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3416 <li><b><code>LUA_GCSETPAUSE</code>: </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3417 sets <code>data</code> as the new value |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3418 for the <em>pause</em> of the collector (see <a href="#2.5">§2.5</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3419 The function returns the previous value of the pause. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3420 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3421 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3422 <li><b><code>LUA_GCSETSTEPMUL</code>: </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3423 sets <code>data</code> as the new value for the <em>step multiplier</em> of |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3424 the collector (see <a href="#2.5">§2.5</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3425 The function returns the previous value of the step multiplier. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3426 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3427 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3428 <li><b><code>LUA_GCISRUNNING</code>: </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3429 returns a boolean that tells whether the collector is running |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3430 (i.e., not stopped). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3431 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3432 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3433 <li><b><code>LUA_GCGEN</code>: </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3434 changes the collector to generational mode |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3435 (see <a href="#2.5">§2.5</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3436 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3437 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3438 <li><b><code>LUA_GCINC</code>: </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3439 changes the collector to incremental mode. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3440 This is the default mode. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3441 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3442 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3443 </ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3444 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3445 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3446 For more details about these options, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3447 see <a href="#pdf-collectgarbage"><code>collectgarbage</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3448 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3449 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3450 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3451 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3452 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3453 <hr><h3><a name="lua_getallocf"><code>lua_getallocf</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3454 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3455 <pre>lua_Alloc lua_getallocf (lua_State *L, void **ud);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3456 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3457 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3458 Returns the memory-allocation function of a given state. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3459 If <code>ud</code> is not <code>NULL</code>, Lua stores in <code>*ud</code> the |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3460 opaque pointer passed to <a href="#lua_newstate"><code>lua_newstate</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3461 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3462 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3463 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3464 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3465 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3466 <hr><h3><a name="lua_getctx"><code>lua_getctx</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3467 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3468 <pre>int lua_getctx (lua_State *L, int *ctx);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3469 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3470 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3471 This function is called by a continuation function (see <a href="#4.7">§4.7</a>) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3472 to retrieve the status of the thread and a context information. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3473 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3474 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3475 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3476 When called in the original function, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3477 <a href="#lua_getctx"><code>lua_getctx</code></a> always returns <a href="#pdf-LUA_OK"><code>LUA_OK</code></a> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3478 and does not change the value of its argument <code>ctx</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3479 When called inside a continuation function, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3480 <a href="#lua_getctx"><code>lua_getctx</code></a> returns <a href="#pdf-LUA_YIELD"><code>LUA_YIELD</code></a> and sets |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3481 the value of <code>ctx</code> to be the context information |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3482 (the value passed as the <code>ctx</code> argument |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3483 to the callee together with the continuation function). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3484 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3485 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3486 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3487 When the callee is <a href="#lua_pcallk"><code>lua_pcallk</code></a>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3488 Lua may also call its continuation function |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3489 to handle errors during the call. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3490 That is, upon an error in the function called by <a href="#lua_pcallk"><code>lua_pcallk</code></a>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3491 Lua may not return to the original function |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3492 but instead may call the continuation function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3493 In that case, a call to <a href="#lua_getctx"><code>lua_getctx</code></a> will return the error code |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3494 (the value that would be returned by <a href="#lua_pcallk"><code>lua_pcallk</code></a>); |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3495 the value of <code>ctx</code> will be set to the context information, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3496 as in the case of a yield. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3497 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3498 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3499 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3500 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3501 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3502 <hr><h3><a name="lua_getfield"><code>lua_getfield</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3503 <span class="apii">[-0, +1, <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3504 <pre>void lua_getfield (lua_State *L, int index, const char *k);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3505 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3506 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3507 Pushes onto the stack the value <code>t[k]</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3508 where <code>t</code> is the value at the given index. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3509 As in Lua, this function may trigger a metamethod |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3510 for the "index" event (see <a href="#2.4">§2.4</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3511 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3512 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3513 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3514 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3515 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3516 <hr><h3><a name="lua_getglobal"><code>lua_getglobal</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3517 <span class="apii">[-0, +1, <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3518 <pre>void lua_getglobal (lua_State *L, const char *name);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3519 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3520 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3521 Pushes onto the stack the value of the global <code>name</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3522 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3523 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3524 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3525 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3526 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3527 <hr><h3><a name="lua_getmetatable"><code>lua_getmetatable</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3528 <span class="apii">[-0, +(0|1), –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3529 <pre>int lua_getmetatable (lua_State *L, int index);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3530 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3531 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3532 Pushes onto the stack the metatable of the value at the given index. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3533 If the value does not have a metatable, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3534 the function returns 0 and pushes nothing on the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3535 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3536 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3537 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3538 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3539 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3540 <hr><h3><a name="lua_gettable"><code>lua_gettable</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3541 <span class="apii">[-1, +1, <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3542 <pre>void lua_gettable (lua_State *L, int index);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3543 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3544 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3545 Pushes onto the stack the value <code>t[k]</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3546 where <code>t</code> is the value at the given index |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3547 and <code>k</code> is the value at the top of the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3548 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3549 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3550 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3551 This function pops the key from the stack |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3552 (putting the resulting value in its place). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3553 As in Lua, this function may trigger a metamethod |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3554 for the "index" event (see <a href="#2.4">§2.4</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3555 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3556 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3557 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3558 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3559 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3560 <hr><h3><a name="lua_gettop"><code>lua_gettop</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3561 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3562 <pre>int lua_gettop (lua_State *L);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3563 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3564 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3565 Returns the index of the top element in the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3566 Because indices start at 1, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3567 this result is equal to the number of elements in the stack |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3568 (and so 0 means an empty stack). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3569 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3570 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3571 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3572 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3573 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3574 <hr><h3><a name="lua_getuservalue"><code>lua_getuservalue</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3575 <span class="apii">[-0, +1, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3576 <pre>void lua_getuservalue (lua_State *L, int index);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3577 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3578 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3579 Pushes onto the stack the Lua value associated with the userdata |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3580 at the given index. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3581 This Lua value must be a table or <b>nil</b>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3582 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3583 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3584 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3585 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3586 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3587 <hr><h3><a name="lua_insert"><code>lua_insert</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3588 <span class="apii">[-1, +1, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3589 <pre>void lua_insert (lua_State *L, int index);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3590 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3591 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3592 Moves the top element into the given valid index, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3593 shifting up the elements above this index to open space. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3594 This function cannot be called with a pseudo-index, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3595 because a pseudo-index is not an actual stack position. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3596 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3597 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3598 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3599 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3600 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3601 <hr><h3><a name="lua_Integer"><code>lua_Integer</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3602 <pre>typedef ptrdiff_t lua_Integer;</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3603 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3604 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3605 The type used by the Lua API to represent signed integral values. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3606 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3607 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3608 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3609 By default it is a <code>ptrdiff_t</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3610 which is usually the largest signed integral type the machine handles |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3611 "comfortably". |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3612 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3613 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3614 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3615 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3616 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3617 <hr><h3><a name="lua_isboolean"><code>lua_isboolean</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3618 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3619 <pre>int lua_isboolean (lua_State *L, int index);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3620 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3621 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3622 Returns 1 if the value at the given index is a boolean, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3623 and 0 otherwise. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3624 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3625 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3626 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3627 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3628 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3629 <hr><h3><a name="lua_iscfunction"><code>lua_iscfunction</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3630 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3631 <pre>int lua_iscfunction (lua_State *L, int index);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3632 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3633 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3634 Returns 1 if the value at the given index is a C function, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3635 and 0 otherwise. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3636 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3637 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3638 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3639 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3640 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3641 <hr><h3><a name="lua_isfunction"><code>lua_isfunction</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3642 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3643 <pre>int lua_isfunction (lua_State *L, int index);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3644 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3645 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3646 Returns 1 if the value at the given index is a function |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3647 (either C or Lua), and 0 otherwise. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3648 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3649 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3650 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3651 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3652 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3653 <hr><h3><a name="lua_islightuserdata"><code>lua_islightuserdata</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3654 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3655 <pre>int lua_islightuserdata (lua_State *L, int index);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3656 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3657 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3658 Returns 1 if the value at the given index is a light userdata, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3659 and 0 otherwise. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3660 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3661 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3662 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3663 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3664 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3665 <hr><h3><a name="lua_isnil"><code>lua_isnil</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3666 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3667 <pre>int lua_isnil (lua_State *L, int index);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3668 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3669 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3670 Returns 1 if the value at the given index is <b>nil</b>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3671 and 0 otherwise. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3672 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3673 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3674 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3675 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3676 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3677 <hr><h3><a name="lua_isnone"><code>lua_isnone</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3678 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3679 <pre>int lua_isnone (lua_State *L, int index);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3680 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3681 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3682 Returns 1 if the given index is not valid, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3683 and 0 otherwise. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3684 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3685 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3686 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3687 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3688 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3689 <hr><h3><a name="lua_isnoneornil"><code>lua_isnoneornil</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3690 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3691 <pre>int lua_isnoneornil (lua_State *L, int index);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3692 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3693 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3694 Returns 1 if the given index is not valid |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3695 or if the value at this index is <b>nil</b>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3696 and 0 otherwise. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3697 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3698 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3699 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3700 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3701 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3702 <hr><h3><a name="lua_isnumber"><code>lua_isnumber</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3703 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3704 <pre>int lua_isnumber (lua_State *L, int index);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3705 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3706 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3707 Returns 1 if the value at the given index is a number |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3708 or a string convertible to a number, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3709 and 0 otherwise. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3710 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3711 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3712 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3713 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3714 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3715 <hr><h3><a name="lua_isstring"><code>lua_isstring</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3716 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3717 <pre>int lua_isstring (lua_State *L, int index);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3718 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3719 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3720 Returns 1 if the value at the given index is a string |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3721 or a number (which is always convertible to a string), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3722 and 0 otherwise. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3723 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3724 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3725 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3726 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3727 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3728 <hr><h3><a name="lua_istable"><code>lua_istable</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3729 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3730 <pre>int lua_istable (lua_State *L, int index);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3731 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3732 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3733 Returns 1 if the value at the given index is a table, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3734 and 0 otherwise. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3735 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3736 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3737 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3738 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3739 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3740 <hr><h3><a name="lua_isthread"><code>lua_isthread</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3741 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3742 <pre>int lua_isthread (lua_State *L, int index);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3743 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3744 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3745 Returns 1 if the value at the given index is a thread, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3746 and 0 otherwise. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3747 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3748 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3749 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3750 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3751 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3752 <hr><h3><a name="lua_isuserdata"><code>lua_isuserdata</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3753 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3754 <pre>int lua_isuserdata (lua_State *L, int index);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3755 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3756 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3757 Returns 1 if the value at the given index is a userdata |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3758 (either full or light), and 0 otherwise. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3759 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3760 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3761 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3762 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3763 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3764 <hr><h3><a name="lua_len"><code>lua_len</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3765 <span class="apii">[-0, +1, <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3766 <pre>void lua_len (lua_State *L, int index);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3767 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3768 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3769 Returns the "length" of the value at the given index; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3770 it is equivalent to the '<code>#</code>' operator in Lua (see <a href="#3.4.6">§3.4.6</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3771 The result is pushed on the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3772 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3773 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3774 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3775 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3776 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3777 <hr><h3><a name="lua_load"><code>lua_load</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3778 <span class="apii">[-0, +1, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3779 <pre>int lua_load (lua_State *L, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3780 lua_Reader reader, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3781 void *data, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3782 const char *source, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3783 const char *mode);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3784 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3785 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3786 Loads a Lua chunk (without running it). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3787 If there are no errors, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3788 <code>lua_load</code> pushes the compiled chunk as a Lua |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3789 function on top of the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3790 Otherwise, it pushes an error message. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3791 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3792 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3793 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3794 The return values of <code>lua_load</code> are: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3795 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3796 <ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3797 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3798 <li><b><a href="#pdf-LUA_OK"><code>LUA_OK</code></a>: </b> no errors;</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3799 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3800 <li><b><a name="pdf-LUA_ERRSYNTAX"><code>LUA_ERRSYNTAX</code></a>: </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3801 syntax error during precompilation;</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3802 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3803 <li><b><a href="#pdf-LUA_ERRMEM"><code>LUA_ERRMEM</code></a>: </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3804 memory allocation error;</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3805 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3806 <li><b><a href="#pdf-LUA_ERRGCMM"><code>LUA_ERRGCMM</code></a>: </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3807 error while running a <code>__gc</code> metamethod. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3808 (This error has no relation with the chunk being loaded. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3809 It is generated by the garbage collector.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3810 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3811 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3812 </ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3813 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3814 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3815 The <code>lua_load</code> function uses a user-supplied <code>reader</code> function |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3816 to read the chunk (see <a href="#lua_Reader"><code>lua_Reader</code></a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3817 The <code>data</code> argument is an opaque value passed to the reader function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3818 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3819 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3820 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3821 The <code>source</code> argument gives a name to the chunk, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3822 which is used for error messages and in debug information (see <a href="#4.9">§4.9</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3823 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3824 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3825 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3826 <code>lua_load</code> automatically detects whether the chunk is text or binary |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3827 and loads it accordingly (see program <code>luac</code>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3828 The string <code>mode</code> works as in function <a href="#pdf-load"><code>load</code></a>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3829 with the addition that |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3830 a <code>NULL</code> value is equivalent to the string "<code>bt</code>". |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3831 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3832 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3833 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3834 <code>lua_load</code> uses the stack internally, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3835 so the reader function should always leave the stack |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3836 unmodified when returning. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3837 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3838 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3839 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3840 If the resulting function has one upvalue, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3841 this upvalue is set to the value of the global environment |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3842 stored at index <code>LUA_RIDX_GLOBALS</code> in the registry (see <a href="#4.5">§4.5</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3843 When loading main chunks, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3844 this upvalue will be the <code>_ENV</code> variable (see <a href="#2.2">§2.2</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3845 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3846 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3847 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3848 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3849 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3850 <hr><h3><a name="lua_newstate"><code>lua_newstate</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3851 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3852 <pre>lua_State *lua_newstate (lua_Alloc f, void *ud);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3853 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3854 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3855 Creates a new thread running in a new, independent state. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3856 Returns <code>NULL</code> if cannot create the thread or the state |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3857 (due to lack of memory). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3858 The argument <code>f</code> is the allocator function; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3859 Lua does all memory allocation for this state through this function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3860 The second argument, <code>ud</code>, is an opaque pointer that Lua |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3861 passes to the allocator in every call. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3862 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3863 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3864 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3865 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3866 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3867 <hr><h3><a name="lua_newtable"><code>lua_newtable</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3868 <span class="apii">[-0, +1, <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3869 <pre>void lua_newtable (lua_State *L);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3870 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3871 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3872 Creates a new empty table and pushes it onto the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3873 It is equivalent to <code>lua_createtable(L, 0, 0)</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3874 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3875 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3876 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3877 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3878 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3879 <hr><h3><a name="lua_newthread"><code>lua_newthread</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3880 <span class="apii">[-0, +1, <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3881 <pre>lua_State *lua_newthread (lua_State *L);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3882 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3883 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3884 Creates a new thread, pushes it on the stack, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3885 and returns a pointer to a <a href="#lua_State"><code>lua_State</code></a> that represents this new thread. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3886 The new thread returned by this function shares with the original thread |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3887 its global environment, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3888 but has an independent execution stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3889 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3890 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3891 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3892 There is no explicit function to close or to destroy a thread. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3893 Threads are subject to garbage collection, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3894 like any Lua object. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3895 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3896 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3897 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3898 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3899 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3900 <hr><h3><a name="lua_newuserdata"><code>lua_newuserdata</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3901 <span class="apii">[-0, +1, <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3902 <pre>void *lua_newuserdata (lua_State *L, size_t size);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3903 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3904 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3905 This function allocates a new block of memory with the given size, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3906 pushes onto the stack a new full userdata with the block address, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3907 and returns this address. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3908 The host program can freely use this memory. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3909 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3910 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3911 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3912 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3913 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3914 <hr><h3><a name="lua_next"><code>lua_next</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3915 <span class="apii">[-1, +(2|0), <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3916 <pre>int lua_next (lua_State *L, int index);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3917 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3918 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3919 Pops a key from the stack, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3920 and pushes a key–value pair from the table at the given index |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3921 (the "next" pair after the given key). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3922 If there are no more elements in the table, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3923 then <a href="#lua_next"><code>lua_next</code></a> returns 0 (and pushes nothing). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3924 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3925 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3926 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3927 A typical traversal looks like this: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3928 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3929 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3930 /* table is in the stack at index 't' */ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3931 lua_pushnil(L); /* first key */ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3932 while (lua_next(L, t) != 0) { |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3933 /* uses 'key' (at index -2) and 'value' (at index -1) */ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3934 printf("%s - %s\n", |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3935 lua_typename(L, lua_type(L, -2)), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3936 lua_typename(L, lua_type(L, -1))); |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3937 /* removes 'value'; keeps 'key' for next iteration */ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3938 lua_pop(L, 1); |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3939 } |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3940 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3941 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3942 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3943 While traversing a table, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3944 do not call <a href="#lua_tolstring"><code>lua_tolstring</code></a> directly on a key, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3945 unless you know that the key is actually a string. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3946 Recall that <a href="#lua_tolstring"><code>lua_tolstring</code></a> may change |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3947 the value at the given index; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3948 this confuses the next call to <a href="#lua_next"><code>lua_next</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3949 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3950 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3951 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3952 See function <a href="#pdf-next"><code>next</code></a> for the caveats of modifying |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3953 the table during its traversal. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3954 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3955 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3956 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3957 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3958 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3959 <hr><h3><a name="lua_Number"><code>lua_Number</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3960 <pre>typedef double lua_Number;</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3961 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3962 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3963 The type of numbers in Lua. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3964 By default, it is double, but that can be changed in <code>luaconf.h</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3965 Through this configuration file you can change |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3966 Lua to operate with another type for numbers (e.g., float or long). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3967 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3968 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3969 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3970 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3971 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3972 <hr><h3><a name="lua_pcall"><code>lua_pcall</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3973 <span class="apii">[-(nargs + 1), +(nresults|1), –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3974 <pre>int lua_pcall (lua_State *L, int nargs, int nresults, int msgh);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3975 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3976 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3977 Calls a function in protected mode. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3978 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3979 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3980 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3981 Both <code>nargs</code> and <code>nresults</code> have the same meaning as |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3982 in <a href="#lua_call"><code>lua_call</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3983 If there are no errors during the call, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3984 <a href="#lua_pcall"><code>lua_pcall</code></a> behaves exactly like <a href="#lua_call"><code>lua_call</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3985 However, if there is any error, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3986 <a href="#lua_pcall"><code>lua_pcall</code></a> catches it, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3987 pushes a single value on the stack (the error message), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3988 and returns an error code. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3989 Like <a href="#lua_call"><code>lua_call</code></a>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3990 <a href="#lua_pcall"><code>lua_pcall</code></a> always removes the function |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3991 and its arguments from the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3992 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3993 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3994 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3995 If <code>msgh</code> is 0, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3996 then the error message returned on the stack |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3997 is exactly the original error message. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3998 Otherwise, <code>msgh</code> is the stack index of a |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3999 <em>message handler</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4000 (In the current implementation, this index cannot be a pseudo-index.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4001 In case of runtime errors, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4002 this function will be called with the error message |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4003 and its return value will be the message |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4004 returned on the stack by <a href="#lua_pcall"><code>lua_pcall</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4005 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4006 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4007 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4008 Typically, the message handler is used to add more debug |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4009 information to the error message, such as a stack traceback. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4010 Such information cannot be gathered after the return of <a href="#lua_pcall"><code>lua_pcall</code></a>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4011 since by then the stack has unwound. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4012 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4013 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4014 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4015 The <a href="#lua_pcall"><code>lua_pcall</code></a> function returns one of the following codes |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4016 (defined in <code>lua.h</code>): |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4017 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4018 <ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4019 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4020 <li><b><a name="pdf-LUA_OK"><code>LUA_OK</code></a> (0): </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4021 success.</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4022 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4023 <li><b><a name="pdf-LUA_ERRRUN"><code>LUA_ERRRUN</code></a>: </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4024 a runtime error. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4025 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4026 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4027 <li><b><a name="pdf-LUA_ERRMEM"><code>LUA_ERRMEM</code></a>: </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4028 memory allocation error. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4029 For such errors, Lua does not call the message handler. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4030 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4031 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4032 <li><b><a name="pdf-LUA_ERRERR"><code>LUA_ERRERR</code></a>: </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4033 error while running the message handler. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4034 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4035 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4036 <li><b><a name="pdf-LUA_ERRGCMM"><code>LUA_ERRGCMM</code></a>: </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4037 error while running a <code>__gc</code> metamethod. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4038 (This error typically has no relation with the function being called. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4039 It is generated by the garbage collector.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4040 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4041 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4042 </ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4043 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4044 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4045 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4046 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4047 <hr><h3><a name="lua_pcallk"><code>lua_pcallk</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4048 <span class="apii">[-(nargs + 1), +(nresults|1), –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4049 <pre>int lua_pcallk (lua_State *L, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4050 int nargs, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4051 int nresults, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4052 int errfunc, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4053 int ctx, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4054 lua_CFunction k);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4055 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4056 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4057 This function behaves exactly like <a href="#lua_pcall"><code>lua_pcall</code></a>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4058 but allows the called function to yield (see <a href="#4.7">§4.7</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4059 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4060 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4061 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4062 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4063 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4064 <hr><h3><a name="lua_pop"><code>lua_pop</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4065 <span class="apii">[-n, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4066 <pre>void lua_pop (lua_State *L, int n);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4067 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4068 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4069 Pops <code>n</code> elements from the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4070 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4071 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4072 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4073 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4074 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4075 <hr><h3><a name="lua_pushboolean"><code>lua_pushboolean</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4076 <span class="apii">[-0, +1, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4077 <pre>void lua_pushboolean (lua_State *L, int b);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4078 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4079 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4080 Pushes a boolean value with value <code>b</code> onto the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4081 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4082 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4083 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4084 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4085 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4086 <hr><h3><a name="lua_pushcclosure"><code>lua_pushcclosure</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4087 <span class="apii">[-n, +1, <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4088 <pre>void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4089 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4090 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4091 Pushes a new C closure onto the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4092 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4093 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4094 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4095 When a C function is created, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4096 it is possible to associate some values with it, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4097 thus creating a C closure (see <a href="#4.4">§4.4</a>); |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4098 these values are then accessible to the function whenever it is called. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4099 To associate values with a C function, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4100 first these values should be pushed onto the stack |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4101 (when there are multiple values, the first value is pushed first). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4102 Then <a href="#lua_pushcclosure"><code>lua_pushcclosure</code></a> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4103 is called to create and push the C function onto the stack, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4104 with the argument <code>n</code> telling how many values should be |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4105 associated with the function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4106 <a href="#lua_pushcclosure"><code>lua_pushcclosure</code></a> also pops these values from the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4107 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4108 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4109 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4110 The maximum value for <code>n</code> is 255. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4111 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4112 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4113 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4114 When <code>n</code> is zero, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4115 this function creates a <em>light C function</em>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4116 which is just a pointer to the C function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4117 In that case, it never throws a memory error. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4118 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4119 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4120 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4121 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4122 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4123 <hr><h3><a name="lua_pushcfunction"><code>lua_pushcfunction</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4124 <span class="apii">[-0, +1, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4125 <pre>void lua_pushcfunction (lua_State *L, lua_CFunction f);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4126 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4127 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4128 Pushes a C function onto the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4129 This function receives a pointer to a C function |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4130 and pushes onto the stack a Lua value of type <code>function</code> that, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4131 when called, invokes the corresponding C function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4132 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4133 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4134 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4135 Any function to be registered in Lua must |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4136 follow the correct protocol to receive its parameters |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4137 and return its results (see <a href="#lua_CFunction"><code>lua_CFunction</code></a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4138 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4139 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4140 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4141 <code>lua_pushcfunction</code> is defined as a macro: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4142 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4143 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4144 #define lua_pushcfunction(L,f) lua_pushcclosure(L,f,0) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4145 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4146 Note that <code>f</code> is used twice. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4147 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4148 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4149 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4150 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4151 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4152 <hr><h3><a name="lua_pushfstring"><code>lua_pushfstring</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4153 <span class="apii">[-0, +1, <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4154 <pre>const char *lua_pushfstring (lua_State *L, const char *fmt, ...);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4155 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4156 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4157 Pushes onto the stack a formatted string |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4158 and returns a pointer to this string. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4159 It is similar to the ANSI C function <code>sprintf</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4160 but has some important differences: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4161 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4162 <ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4163 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4164 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4165 You do not have to allocate space for the result: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4166 the result is a Lua string and Lua takes care of memory allocation |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4167 (and deallocation, through garbage collection). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4168 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4169 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4170 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4171 The conversion specifiers are quite restricted. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4172 There are no flags, widths, or precisions. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4173 The conversion specifiers can only be |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4174 '<code>%%</code>' (inserts a '<code>%</code>' in the string), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4175 '<code>%s</code>' (inserts a zero-terminated string, with no size restrictions), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4176 '<code>%f</code>' (inserts a <a href="#lua_Number"><code>lua_Number</code></a>), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4177 '<code>%p</code>' (inserts a pointer as a hexadecimal numeral), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4178 '<code>%d</code>' (inserts an <code>int</code>), and |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4179 '<code>%c</code>' (inserts an <code>int</code> as a byte). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4180 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4181 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4182 </ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4183 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4184 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4185 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4186 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4187 <hr><h3><a name="lua_pushglobaltable"><code>lua_pushglobaltable</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4188 <span class="apii">[-0, +1, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4189 <pre>void lua_pushglobaltable (lua_State *L);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4190 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4191 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4192 Pushes the global environment onto the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4193 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4194 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4195 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4196 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4197 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4198 <hr><h3><a name="lua_pushinteger"><code>lua_pushinteger</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4199 <span class="apii">[-0, +1, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4200 <pre>void lua_pushinteger (lua_State *L, lua_Integer n);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4201 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4202 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4203 Pushes a number with value <code>n</code> onto the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4204 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4205 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4206 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4207 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4208 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4209 <hr><h3><a name="lua_pushlightuserdata"><code>lua_pushlightuserdata</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4210 <span class="apii">[-0, +1, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4211 <pre>void lua_pushlightuserdata (lua_State *L, void *p);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4212 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4213 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4214 Pushes a light userdata onto the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4215 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4216 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4217 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4218 Userdata represent C values in Lua. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4219 A <em>light userdata</em> represents a pointer, a <code>void*</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4220 It is a value (like a number): |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4221 you do not create it, it has no individual metatable, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4222 and it is not collected (as it was never created). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4223 A light userdata is equal to "any" |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4224 light userdata with the same C address. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4225 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4226 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4227 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4228 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4229 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4230 <hr><h3><a name="lua_pushliteral"><code>lua_pushliteral</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4231 <span class="apii">[-0, +1, <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4232 <pre>const char *lua_pushliteral (lua_State *L, const char *s);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4233 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4234 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4235 This macro is equivalent to <a href="#lua_pushlstring"><code>lua_pushlstring</code></a>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4236 but can be used only when <code>s</code> is a literal string. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4237 It automatically provides the string length. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4238 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4239 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4240 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4241 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4242 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4243 <hr><h3><a name="lua_pushlstring"><code>lua_pushlstring</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4244 <span class="apii">[-0, +1, <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4245 <pre>const char *lua_pushlstring (lua_State *L, const char *s, size_t len);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4246 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4247 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4248 Pushes the string pointed to by <code>s</code> with size <code>len</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4249 onto the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4250 Lua makes (or reuses) an internal copy of the given string, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4251 so the memory at <code>s</code> can be freed or reused immediately after |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4252 the function returns. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4253 The string can contain any binary data, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4254 including embedded zeros. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4255 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4256 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4257 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4258 Returns a pointer to the internal copy of the string. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4259 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4260 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4261 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4262 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4263 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4264 <hr><h3><a name="lua_pushnil"><code>lua_pushnil</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4265 <span class="apii">[-0, +1, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4266 <pre>void lua_pushnil (lua_State *L);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4267 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4268 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4269 Pushes a nil value onto the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4270 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4271 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4272 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4273 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4274 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4275 <hr><h3><a name="lua_pushnumber"><code>lua_pushnumber</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4276 <span class="apii">[-0, +1, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4277 <pre>void lua_pushnumber (lua_State *L, lua_Number n);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4278 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4279 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4280 Pushes a number with value <code>n</code> onto the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4281 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4282 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4283 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4284 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4285 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4286 <hr><h3><a name="lua_pushstring"><code>lua_pushstring</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4287 <span class="apii">[-0, +1, <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4288 <pre>const char *lua_pushstring (lua_State *L, const char *s);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4289 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4290 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4291 Pushes the zero-terminated string pointed to by <code>s</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4292 onto the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4293 Lua makes (or reuses) an internal copy of the given string, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4294 so the memory at <code>s</code> can be freed or reused immediately after |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4295 the function returns. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4296 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4297 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4298 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4299 Returns a pointer to the internal copy of the string. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4300 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4301 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4302 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4303 If <code>s</code> is <code>NULL</code>, pushes <b>nil</b> and returns <code>NULL</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4304 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4305 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4306 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4307 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4308 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4309 <hr><h3><a name="lua_pushthread"><code>lua_pushthread</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4310 <span class="apii">[-0, +1, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4311 <pre>int lua_pushthread (lua_State *L);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4312 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4313 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4314 Pushes the thread represented by <code>L</code> onto the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4315 Returns 1 if this thread is the main thread of its state. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4316 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4317 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4318 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4319 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4320 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4321 <hr><h3><a name="lua_pushunsigned"><code>lua_pushunsigned</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4322 <span class="apii">[-0, +1, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4323 <pre>void lua_pushunsigned (lua_State *L, lua_Unsigned n);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4324 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4325 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4326 Pushes a number with value <code>n</code> onto the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4327 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4328 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4329 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4330 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4331 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4332 <hr><h3><a name="lua_pushvalue"><code>lua_pushvalue</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4333 <span class="apii">[-0, +1, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4334 <pre>void lua_pushvalue (lua_State *L, int index);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4335 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4336 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4337 Pushes a copy of the element at the given index |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4338 onto the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4339 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4340 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4341 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4342 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4343 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4344 <hr><h3><a name="lua_pushvfstring"><code>lua_pushvfstring</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4345 <span class="apii">[-0, +1, <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4346 <pre>const char *lua_pushvfstring (lua_State *L, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4347 const char *fmt, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4348 va_list argp);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4349 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4350 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4351 Equivalent to <a href="#lua_pushfstring"><code>lua_pushfstring</code></a>, except that it receives a <code>va_list</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4352 instead of a variable number of arguments. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4353 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4354 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4355 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4356 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4357 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4358 <hr><h3><a name="lua_rawequal"><code>lua_rawequal</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4359 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4360 <pre>int lua_rawequal (lua_State *L, int index1, int index2);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4361 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4362 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4363 Returns 1 if the two values in indices <code>index1</code> and |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4364 <code>index2</code> are primitively equal |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4365 (that is, without calling metamethods). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4366 Otherwise returns 0. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4367 Also returns 0 if any of the indices are non valid. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4368 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4369 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4370 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4371 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4372 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4373 <hr><h3><a name="lua_rawget"><code>lua_rawget</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4374 <span class="apii">[-1, +1, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4375 <pre>void lua_rawget (lua_State *L, int index);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4376 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4377 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4378 Similar to <a href="#lua_gettable"><code>lua_gettable</code></a>, but does a raw access |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4379 (i.e., without metamethods). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4380 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4381 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4382 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4383 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4384 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4385 <hr><h3><a name="lua_rawgeti"><code>lua_rawgeti</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4386 <span class="apii">[-0, +1, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4387 <pre>void lua_rawgeti (lua_State *L, int index, int n);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4388 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4389 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4390 Pushes onto the stack the value <code>t[n]</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4391 where <code>t</code> is the table at the given index. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4392 The access is raw; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4393 that is, it does not invoke metamethods. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4394 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4395 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4396 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4397 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4398 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4399 <hr><h3><a name="lua_rawgetp"><code>lua_rawgetp</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4400 <span class="apii">[-0, +1, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4401 <pre>void lua_rawgetp (lua_State *L, int index, const void *p);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4402 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4403 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4404 Pushes onto the stack the value <code>t[k]</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4405 where <code>t</code> is the table at the given index and |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4406 <code>k</code> is the pointer <code>p</code> represented as a light userdata. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4407 The access is raw; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4408 that is, it does not invoke metamethods. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4409 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4410 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4411 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4412 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4413 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4414 <hr><h3><a name="lua_rawlen"><code>lua_rawlen</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4415 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4416 <pre>size_t lua_rawlen (lua_State *L, int index);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4417 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4418 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4419 Returns the raw "length" of the value at the given index: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4420 for strings, this is the string length; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4421 for tables, this is the result of the length operator ('<code>#</code>') |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4422 with no metamethods; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4423 for userdata, this is the size of the block of memory allocated |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4424 for the userdata; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4425 for other values, it is 0. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4426 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4427 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4428 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4429 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4430 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4431 <hr><h3><a name="lua_rawset"><code>lua_rawset</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4432 <span class="apii">[-2, +0, <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4433 <pre>void lua_rawset (lua_State *L, int index);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4434 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4435 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4436 Similar to <a href="#lua_settable"><code>lua_settable</code></a>, but does a raw assignment |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4437 (i.e., without metamethods). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4438 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4439 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4440 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4441 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4442 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4443 <hr><h3><a name="lua_rawseti"><code>lua_rawseti</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4444 <span class="apii">[-1, +0, <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4445 <pre>void lua_rawseti (lua_State *L, int index, int n);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4446 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4447 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4448 Does the equivalent of <code>t[n] = v</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4449 where <code>t</code> is the table at the given index |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4450 and <code>v</code> is the value at the top of the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4451 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4452 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4453 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4454 This function pops the value from the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4455 The assignment is raw; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4456 that is, it does not invoke metamethods. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4457 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4458 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4459 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4460 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4461 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4462 <hr><h3><a name="lua_rawsetp"><code>lua_rawsetp</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4463 <span class="apii">[-1, +0, <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4464 <pre>void lua_rawsetp (lua_State *L, int index, const void *p);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4465 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4466 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4467 Does the equivalent of <code>t[k] = v</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4468 where <code>t</code> is the table at the given index, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4469 <code>k</code> is the pointer <code>p</code> represented as a light userdata, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4470 and <code>v</code> is the value at the top of the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4471 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4472 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4473 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4474 This function pops the value from the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4475 The assignment is raw; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4476 that is, it does not invoke metamethods. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4477 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4478 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4479 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4480 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4481 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4482 <hr><h3><a name="lua_Reader"><code>lua_Reader</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4483 <pre>typedef const char * (*lua_Reader) (lua_State *L, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4484 void *data, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4485 size_t *size);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4486 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4487 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4488 The reader function used by <a href="#lua_load"><code>lua_load</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4489 Every time it needs another piece of the chunk, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4490 <a href="#lua_load"><code>lua_load</code></a> calls the reader, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4491 passing along its <code>data</code> parameter. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4492 The reader must return a pointer to a block of memory |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4493 with a new piece of the chunk |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4494 and set <code>size</code> to the block size. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4495 The block must exist until the reader function is called again. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4496 To signal the end of the chunk, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4497 the reader must return <code>NULL</code> or set <code>size</code> to zero. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4498 The reader function may return pieces of any size greater than zero. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4499 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4500 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4501 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4502 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4503 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4504 <hr><h3><a name="lua_register"><code>lua_register</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4505 <span class="apii">[-0, +0, <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4506 <pre>void lua_register (lua_State *L, const char *name, lua_CFunction f);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4507 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4508 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4509 Sets the C function <code>f</code> as the new value of global <code>name</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4510 It is defined as a macro: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4511 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4512 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4513 #define lua_register(L,n,f) \ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4514 (lua_pushcfunction(L, f), lua_setglobal(L, n)) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4515 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4516 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4517 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4518 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4519 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4520 <hr><h3><a name="lua_remove"><code>lua_remove</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4521 <span class="apii">[-1, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4522 <pre>void lua_remove (lua_State *L, int index);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4523 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4524 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4525 Removes the element at the given valid index, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4526 shifting down the elements above this index to fill the gap. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4527 This function cannot be called with a pseudo-index, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4528 because a pseudo-index is not an actual stack position. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4529 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4530 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4531 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4532 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4533 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4534 <hr><h3><a name="lua_replace"><code>lua_replace</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4535 <span class="apii">[-1, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4536 <pre>void lua_replace (lua_State *L, int index);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4537 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4538 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4539 Moves the top element into the given valid index |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4540 without shifting any element |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4541 (therefore replacing the value at the given index), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4542 and then pops the top element. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4543 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4544 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4545 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4546 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4547 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4548 <hr><h3><a name="lua_resume"><code>lua_resume</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4549 <span class="apii">[-?, +?, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4550 <pre>int lua_resume (lua_State *L, lua_State *from, int nargs);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4551 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4552 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4553 Starts and resumes a coroutine in a given thread. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4554 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4555 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4556 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4557 To start a coroutine, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4558 you push onto the thread stack the main function plus any arguments; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4559 then you call <a href="#lua_resume"><code>lua_resume</code></a>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4560 with <code>nargs</code> being the number of arguments. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4561 This call returns when the coroutine suspends or finishes its execution. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4562 When it returns, the stack contains all values passed to <a href="#lua_yield"><code>lua_yield</code></a>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4563 or all values returned by the body function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4564 <a href="#lua_resume"><code>lua_resume</code></a> returns |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4565 <a href="#pdf-LUA_YIELD"><code>LUA_YIELD</code></a> if the coroutine yields, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4566 <a href="#pdf-LUA_OK"><code>LUA_OK</code></a> if the coroutine finishes its execution |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4567 without errors, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4568 or an error code in case of errors (see <a href="#lua_pcall"><code>lua_pcall</code></a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4569 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4570 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4571 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4572 In case of errors, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4573 the stack is not unwound, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4574 so you can use the debug API over it. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4575 The error message is on the top of the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4576 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4577 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4578 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4579 To resume a coroutine, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4580 you remove any results from the last <a href="#lua_yield"><code>lua_yield</code></a>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4581 put on its stack only the values to |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4582 be passed as results from <code>yield</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4583 and then call <a href="#lua_resume"><code>lua_resume</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4584 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4585 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4586 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4587 The parameter <code>from</code> represents the coroutine that is resuming <code>L</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4588 If there is no such coroutine, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4589 this parameter can be <code>NULL</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4590 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4591 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4592 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4593 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4594 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4595 <hr><h3><a name="lua_setallocf"><code>lua_setallocf</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4596 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4597 <pre>void lua_setallocf (lua_State *L, lua_Alloc f, void *ud);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4598 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4599 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4600 Changes the allocator function of a given state to <code>f</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4601 with user data <code>ud</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4602 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4603 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4604 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4605 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4606 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4607 <hr><h3><a name="lua_setfield"><code>lua_setfield</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4608 <span class="apii">[-1, +0, <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4609 <pre>void lua_setfield (lua_State *L, int index, const char *k);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4610 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4611 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4612 Does the equivalent to <code>t[k] = v</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4613 where <code>t</code> is the value at the given index |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4614 and <code>v</code> is the value at the top of the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4615 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4616 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4617 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4618 This function pops the value from the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4619 As in Lua, this function may trigger a metamethod |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4620 for the "newindex" event (see <a href="#2.4">§2.4</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4621 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4622 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4623 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4624 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4625 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4626 <hr><h3><a name="lua_setglobal"><code>lua_setglobal</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4627 <span class="apii">[-1, +0, <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4628 <pre>void lua_setglobal (lua_State *L, const char *name);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4629 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4630 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4631 Pops a value from the stack and |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4632 sets it as the new value of global <code>name</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4633 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4634 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4635 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4636 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4637 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4638 <hr><h3><a name="lua_setmetatable"><code>lua_setmetatable</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4639 <span class="apii">[-1, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4640 <pre>void lua_setmetatable (lua_State *L, int index);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4641 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4642 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4643 Pops a table from the stack and |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4644 sets it as the new metatable for the value at the given index. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4645 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4646 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4647 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4648 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4649 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4650 <hr><h3><a name="lua_settable"><code>lua_settable</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4651 <span class="apii">[-2, +0, <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4652 <pre>void lua_settable (lua_State *L, int index);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4653 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4654 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4655 Does the equivalent to <code>t[k] = v</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4656 where <code>t</code> is the value at the given index, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4657 <code>v</code> is the value at the top of the stack, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4658 and <code>k</code> is the value just below the top. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4659 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4660 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4661 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4662 This function pops both the key and the value from the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4663 As in Lua, this function may trigger a metamethod |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4664 for the "newindex" event (see <a href="#2.4">§2.4</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4665 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4666 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4667 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4668 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4669 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4670 <hr><h3><a name="lua_settop"><code>lua_settop</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4671 <span class="apii">[-?, +?, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4672 <pre>void lua_settop (lua_State *L, int index);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4673 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4674 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4675 Accepts any index, or 0, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4676 and sets the stack top to this index. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4677 If the new top is larger than the old one, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4678 then the new elements are filled with <b>nil</b>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4679 If <code>index</code> is 0, then all stack elements are removed. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4680 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4681 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4682 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4683 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4684 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4685 <hr><h3><a name="lua_setuservalue"><code>lua_setuservalue</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4686 <span class="apii">[-1, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4687 <pre>void lua_setuservalue (lua_State *L, int index);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4688 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4689 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4690 Pops a table or <b>nil</b> from the stack and sets it as |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4691 the new value associated to the userdata at the given index. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4692 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4693 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4694 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4695 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4696 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4697 <hr><h3><a name="lua_State"><code>lua_State</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4698 <pre>typedef struct lua_State lua_State;</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4699 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4700 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4701 An opaque structure that points to a thread and indirectly |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4702 (through the thread) to the whole state of a Lua interpreter. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4703 The Lua library is fully reentrant: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4704 it has no global variables. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4705 All information about a state is accessible through this structure. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4706 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4707 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4708 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4709 A pointer to this structure must be passed as the first argument to |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4710 every function in the library, except to <a href="#lua_newstate"><code>lua_newstate</code></a>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4711 which creates a Lua state from scratch. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4712 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4713 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4714 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4715 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4716 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4717 <hr><h3><a name="lua_status"><code>lua_status</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4718 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4719 <pre>int lua_status (lua_State *L);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4720 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4721 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4722 Returns the status of the thread <code>L</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4723 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4724 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4725 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4726 The status can be 0 (<a href="#pdf-LUA_OK"><code>LUA_OK</code></a>) for a normal thread, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4727 an error code if the thread finished the execution |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4728 of a <a href="#lua_resume"><code>lua_resume</code></a> with an error, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4729 or <a name="pdf-LUA_YIELD"><code>LUA_YIELD</code></a> if the thread is suspended. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4730 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4731 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4732 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4733 You can only call functions in threads with status <a href="#pdf-LUA_OK"><code>LUA_OK</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4734 You can resume threads with status <a href="#pdf-LUA_OK"><code>LUA_OK</code></a> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4735 (to start a new coroutine) or <a href="#pdf-LUA_YIELD"><code>LUA_YIELD</code></a> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4736 (to resume a coroutine). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4737 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4738 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4739 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4740 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4741 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4742 <hr><h3><a name="lua_toboolean"><code>lua_toboolean</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4743 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4744 <pre>int lua_toboolean (lua_State *L, int index);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4745 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4746 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4747 Converts the Lua value at the given index to a C boolean |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4748 value (0 or 1). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4749 Like all tests in Lua, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4750 <a href="#lua_toboolean"><code>lua_toboolean</code></a> returns true for any Lua value |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4751 different from <b>false</b> and <b>nil</b>; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4752 otherwise it returns false. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4753 (If you want to accept only actual boolean values, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4754 use <a href="#lua_isboolean"><code>lua_isboolean</code></a> to test the value's type.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4755 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4756 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4757 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4758 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4759 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4760 <hr><h3><a name="lua_tocfunction"><code>lua_tocfunction</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4761 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4762 <pre>lua_CFunction lua_tocfunction (lua_State *L, int index);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4763 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4764 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4765 Converts a value at the given index to a C function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4766 That value must be a C function; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4767 otherwise, returns <code>NULL</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4768 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4769 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4770 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4771 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4772 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4773 <hr><h3><a name="lua_tointeger"><code>lua_tointeger</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4774 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4775 <pre>lua_Integer lua_tointeger (lua_State *L, int index);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4776 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4777 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4778 Equivalent to <a href="#lua_tointegerx"><code>lua_tointegerx</code></a> with <code>isnum</code> equal to <code>NULL</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4779 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4780 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4781 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4782 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4783 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4784 <hr><h3><a name="lua_tointegerx"><code>lua_tointegerx</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4785 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4786 <pre>lua_Integer lua_tointegerx (lua_State *L, int index, int *isnum);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4787 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4788 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4789 Converts the Lua value at the given index |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4790 to the signed integral type <a href="#lua_Integer"><code>lua_Integer</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4791 The Lua value must be a number or a string convertible to a number |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4792 (see <a href="#3.4.2">§3.4.2</a>); |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4793 otherwise, <code>lua_tointegerx</code> returns 0. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4794 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4795 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4796 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4797 If the number is not an integer, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4798 it is truncated in some non-specified way. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4799 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4800 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4801 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4802 If <code>isnum</code> is not <code>NULL</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4803 its referent is assigned a boolean value that |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4804 indicates whether the operation succeeded. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4805 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4806 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4807 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4808 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4809 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4810 <hr><h3><a name="lua_tolstring"><code>lua_tolstring</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4811 <span class="apii">[-0, +0, <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4812 <pre>const char *lua_tolstring (lua_State *L, int index, size_t *len);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4813 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4814 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4815 Converts the Lua value at the given index to a C string. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4816 If <code>len</code> is not <code>NULL</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4817 it also sets <code>*len</code> with the string length. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4818 The Lua value must be a string or a number; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4819 otherwise, the function returns <code>NULL</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4820 If the value is a number, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4821 then <code>lua_tolstring</code> also |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4822 <em>changes the actual value in the stack to a string</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4823 (This change confuses <a href="#lua_next"><code>lua_next</code></a> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4824 when <code>lua_tolstring</code> is applied to keys during a table traversal.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4825 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4826 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4827 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4828 <code>lua_tolstring</code> returns a fully aligned pointer |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4829 to a string inside the Lua state. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4830 This string always has a zero ('<code>\0</code>') |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4831 after its last character (as in C), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4832 but can contain other zeros in its body. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4833 Because Lua has garbage collection, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4834 there is no guarantee that the pointer returned by <code>lua_tolstring</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4835 will be valid after the corresponding value is removed from the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4836 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4837 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4838 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4839 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4840 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4841 <hr><h3><a name="lua_tonumber"><code>lua_tonumber</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4842 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4843 <pre>lua_Number lua_tonumber (lua_State *L, int index);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4844 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4845 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4846 Equivalent to <a href="#lua_tonumberx"><code>lua_tonumberx</code></a> with <code>isnum</code> equal to <code>NULL</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4847 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4848 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4849 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4850 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4851 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4852 <hr><h3><a name="lua_tonumberx"><code>lua_tonumberx</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4853 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4854 <pre>lua_Number lua_tonumberx (lua_State *L, int index, int *isnum);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4855 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4856 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4857 Converts the Lua value at the given index |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4858 to the C type <a href="#lua_Number"><code>lua_Number</code></a> (see <a href="#lua_Number"><code>lua_Number</code></a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4859 The Lua value must be a number or a string convertible to a number |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4860 (see <a href="#3.4.2">§3.4.2</a>); |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4861 otherwise, <a href="#lua_tonumberx"><code>lua_tonumberx</code></a> returns 0. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4862 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4863 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4864 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4865 If <code>isnum</code> is not <code>NULL</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4866 its referent is assigned a boolean value that |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4867 indicates whether the operation succeeded. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4868 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4869 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4870 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4871 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4872 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4873 <hr><h3><a name="lua_topointer"><code>lua_topointer</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4874 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4875 <pre>const void *lua_topointer (lua_State *L, int index);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4876 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4877 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4878 Converts the value at the given index to a generic |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4879 C pointer (<code>void*</code>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4880 The value can be a userdata, a table, a thread, or a function; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4881 otherwise, <code>lua_topointer</code> returns <code>NULL</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4882 Different objects will give different pointers. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4883 There is no way to convert the pointer back to its original value. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4884 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4885 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4886 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4887 Typically this function is used only for debug information. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4888 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4889 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4890 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4891 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4892 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4893 <hr><h3><a name="lua_tostring"><code>lua_tostring</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4894 <span class="apii">[-0, +0, <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4895 <pre>const char *lua_tostring (lua_State *L, int index);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4896 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4897 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4898 Equivalent to <a href="#lua_tolstring"><code>lua_tolstring</code></a> with <code>len</code> equal to <code>NULL</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4899 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4900 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4901 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4902 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4903 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4904 <hr><h3><a name="lua_tothread"><code>lua_tothread</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4905 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4906 <pre>lua_State *lua_tothread (lua_State *L, int index);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4907 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4908 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4909 Converts the value at the given index to a Lua thread |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4910 (represented as <code>lua_State*</code>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4911 This value must be a thread; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4912 otherwise, the function returns <code>NULL</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4913 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4914 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4915 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4916 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4917 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4918 <hr><h3><a name="lua_tounsigned"><code>lua_tounsigned</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4919 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4920 <pre>lua_Unsigned lua_tounsigned (lua_State *L, int index);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4921 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4922 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4923 Equivalent to <a href="#lua_tounsignedx"><code>lua_tounsignedx</code></a> with <code>isnum</code> equal to <code>NULL</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4924 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4925 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4926 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4927 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4928 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4929 <hr><h3><a name="lua_tounsignedx"><code>lua_tounsignedx</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4930 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4931 <pre>lua_Unsigned lua_tounsignedx (lua_State *L, int index, int *isnum);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4932 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4933 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4934 Converts the Lua value at the given index |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4935 to the unsigned integral type <a href="#lua_Unsigned"><code>lua_Unsigned</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4936 The Lua value must be a number or a string convertible to a number |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4937 (see <a href="#3.4.2">§3.4.2</a>); |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4938 otherwise, <code>lua_tounsignedx</code> returns 0. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4939 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4940 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4941 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4942 If the number is not an integer, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4943 it is truncated in some non-specified way. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4944 If the number is outside the range of representable values, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4945 it is normalized to the remainder of its division by |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4946 one more than the maximum representable value. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4947 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4948 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4949 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4950 If <code>isnum</code> is not <code>NULL</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4951 its referent is assigned a boolean value that |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4952 indicates whether the operation succeeded. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4953 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4954 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4955 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4956 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4957 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4958 <hr><h3><a name="lua_touserdata"><code>lua_touserdata</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4959 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4960 <pre>void *lua_touserdata (lua_State *L, int index);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4961 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4962 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4963 If the value at the given index is a full userdata, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4964 returns its block address. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4965 If the value is a light userdata, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4966 returns its pointer. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4967 Otherwise, returns <code>NULL</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4968 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4969 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4970 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4971 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4972 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4973 <hr><h3><a name="lua_type"><code>lua_type</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4974 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4975 <pre>int lua_type (lua_State *L, int index);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4976 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4977 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4978 Returns the type of the value in the given valid index, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4979 or <code>LUA_TNONE</code> for a non-valid (but acceptable) index. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4980 The types returned by <a href="#lua_type"><code>lua_type</code></a> are coded by the following constants |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4981 defined in <code>lua.h</code>: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4982 <a name="pdf-LUA_TNIL"><code>LUA_TNIL</code></a>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4983 <a name="pdf-LUA_TNUMBER"><code>LUA_TNUMBER</code></a>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4984 <a name="pdf-LUA_TBOOLEAN"><code>LUA_TBOOLEAN</code></a>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4985 <a name="pdf-LUA_TSTRING"><code>LUA_TSTRING</code></a>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4986 <a name="pdf-LUA_TTABLE"><code>LUA_TTABLE</code></a>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4987 <a name="pdf-LUA_TFUNCTION"><code>LUA_TFUNCTION</code></a>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4988 <a name="pdf-LUA_TUSERDATA"><code>LUA_TUSERDATA</code></a>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4989 <a name="pdf-LUA_TTHREAD"><code>LUA_TTHREAD</code></a>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4990 and |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4991 <a name="pdf-LUA_TLIGHTUSERDATA"><code>LUA_TLIGHTUSERDATA</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4992 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4993 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4994 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4995 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4996 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4997 <hr><h3><a name="lua_typename"><code>lua_typename</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4998 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4999 <pre>const char *lua_typename (lua_State *L, int tp);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5000 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5001 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5002 Returns the name of the type encoded by the value <code>tp</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5003 which must be one the values returned by <a href="#lua_type"><code>lua_type</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5004 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5005 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5006 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5007 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5008 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5009 <hr><h3><a name="lua_Unsigned"><code>lua_Unsigned</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5010 <pre>typedef unsigned long lua_Unsigned;</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5011 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5012 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5013 The type used by the Lua API to represent unsigned integral values. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5014 It must have at least 32 bits. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5015 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5016 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5017 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5018 By default it is an <code>unsigned int</code> or an <code>unsigned long</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5019 whichever can hold 32-bit values. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5020 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5021 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5022 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5023 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5024 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5025 <hr><h3><a name="lua_upvalueindex"><code>lua_upvalueindex</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5026 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5027 <pre>int lua_upvalueindex (int i);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5028 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5029 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5030 Returns the pseudo-index that represents the <code>i</code>-th upvalue of |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5031 the running function (see <a href="#4.4">§4.4</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5032 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5033 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5034 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5035 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5036 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5037 <hr><h3><a name="lua_version"><code>lua_version</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5038 <span class="apii">[-0, +0, <em>v</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5039 <pre>const lua_Number *lua_version (lua_State *L);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5040 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5041 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5042 Returns the address of the version number stored in the Lua core. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5043 When called with a valid <a href="#lua_State"><code>lua_State</code></a>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5044 returns the address of the version used to create that state. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5045 When called with <code>NULL</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5046 returns the address of the version running the call. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5047 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5048 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5049 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5050 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5051 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5052 <hr><h3><a name="lua_Writer"><code>lua_Writer</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5053 <pre>typedef int (*lua_Writer) (lua_State *L, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5054 const void* p, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5055 size_t sz, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5056 void* ud);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5057 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5058 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5059 The type of the writer function used by <a href="#lua_dump"><code>lua_dump</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5060 Every time it produces another piece of chunk, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5061 <a href="#lua_dump"><code>lua_dump</code></a> calls the writer, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5062 passing along the buffer to be written (<code>p</code>), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5063 its size (<code>sz</code>), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5064 and the <code>data</code> parameter supplied to <a href="#lua_dump"><code>lua_dump</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5065 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5066 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5067 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5068 The writer returns an error code: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5069 0 means no errors; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5070 any other value means an error and stops <a href="#lua_dump"><code>lua_dump</code></a> from |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5071 calling the writer again. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5072 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5073 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5074 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5075 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5076 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5077 <hr><h3><a name="lua_xmove"><code>lua_xmove</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5078 <span class="apii">[-?, +?, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5079 <pre>void lua_xmove (lua_State *from, lua_State *to, int n);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5080 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5081 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5082 Exchange values between different threads of the same state. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5083 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5084 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5085 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5086 This function pops <code>n</code> values from the stack <code>from</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5087 and pushes them onto the stack <code>to</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5088 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5089 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5090 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5091 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5092 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5093 <hr><h3><a name="lua_yield"><code>lua_yield</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5094 <span class="apii">[-?, +?, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5095 <pre>int lua_yield (lua_State *L, int nresults);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5096 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5097 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5098 This function is equivalent to <a href="#lua_yieldk"><code>lua_yieldk</code></a>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5099 but it has no continuation (see <a href="#4.7">§4.7</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5100 Therefore, when the thread resumes, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5101 it returns to the function that called |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5102 the function calling <code>lua_yield</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5103 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5104 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5105 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5106 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5107 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5108 <hr><h3><a name="lua_yieldk"><code>lua_yieldk</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5109 <span class="apii">[-?, +?, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5110 <pre>int lua_yieldk (lua_State *L, int nresults, int ctx, lua_CFunction k);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5111 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5112 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5113 Yields a coroutine. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5114 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5115 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5116 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5117 This function should only be called as the |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5118 return expression of a C function, as follows: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5119 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5120 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5121 return lua_yieldk (L, n, i, k); |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5122 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5123 When a C function calls <a href="#lua_yieldk"><code>lua_yieldk</code></a> in that way, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5124 the running coroutine suspends its execution, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5125 and the call to <a href="#lua_resume"><code>lua_resume</code></a> that started this coroutine returns. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5126 The parameter <code>nresults</code> is the number of values from the stack |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5127 that are passed as results to <a href="#lua_resume"><code>lua_resume</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5128 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5129 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5130 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5131 When the coroutine is resumed again, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5132 Lua calls the given continuation function <code>k</code> to continue |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5133 the execution of the C function that yielded (see <a href="#4.7">§4.7</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5134 This continuation function receives the same stack |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5135 from the previous function, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5136 with the results removed and |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5137 replaced by the arguments passed to <a href="#lua_resume"><code>lua_resume</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5138 Moreover, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5139 the continuation function may access the value <code>ctx</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5140 by calling <a href="#lua_getctx"><code>lua_getctx</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5141 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5142 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5143 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5144 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5145 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5146 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5147 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5148 <h2>4.9 – <a name="4.9">The Debug Interface</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5149 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5150 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5151 Lua has no built-in debugging facilities. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5152 Instead, it offers a special interface |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5153 by means of functions and <em>hooks</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5154 This interface allows the construction of different |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5155 kinds of debuggers, profilers, and other tools |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5156 that need "inside information" from the interpreter. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5157 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5158 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5159 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5160 <hr><h3><a name="lua_Debug"><code>lua_Debug</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5161 <pre>typedef struct lua_Debug { |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5162 int event; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5163 const char *name; /* (n) */ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5164 const char *namewhat; /* (n) */ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5165 const char *what; /* (S) */ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5166 const char *source; /* (S) */ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5167 int currentline; /* (l) */ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5168 int linedefined; /* (S) */ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5169 int lastlinedefined; /* (S) */ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5170 unsigned char nups; /* (u) number of upvalues */ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5171 unsigned char nparams; /* (u) number of parameters */ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5172 char isvararg; /* (u) */ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5173 char istailcall; /* (t) */ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5174 char short_src[LUA_IDSIZE]; /* (S) */ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5175 /* private part */ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5176 <em>other fields</em> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5177 } lua_Debug;</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5178 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5179 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5180 A structure used to carry different pieces of |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5181 information about a function or an activation record. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5182 <a href="#lua_getstack"><code>lua_getstack</code></a> fills only the private part |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5183 of this structure, for later use. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5184 To fill the other fields of <a href="#lua_Debug"><code>lua_Debug</code></a> with useful information, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5185 call <a href="#lua_getinfo"><code>lua_getinfo</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5186 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5187 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5188 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5189 The fields of <a href="#lua_Debug"><code>lua_Debug</code></a> have the following meaning: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5190 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5191 <ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5192 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5193 <li><b><code>source</code>: </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5194 the source of the chunk that created the function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5195 If <code>source</code> starts with a '<code>@</code>', |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5196 it means that the function was defined in a file where |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5197 the file name follows the '<code>@</code>'. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5198 If <code>source</code> starts with a '<code>=</code>', |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5199 the remainder of its contents describe the source in a user-dependent manner. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5200 Otherwise, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5201 the function was defined in a string where |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5202 <code>source</code> is that string. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5203 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5204 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5205 <li><b><code>short_src</code>: </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5206 a "printable" version of <code>source</code>, to be used in error messages. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5207 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5208 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5209 <li><b><code>linedefined</code>: </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5210 the line number where the definition of the function starts. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5211 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5212 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5213 <li><b><code>lastlinedefined</code>: </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5214 the line number where the definition of the function ends. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5215 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5216 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5217 <li><b><code>what</code>: </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5218 the string <code>"Lua"</code> if the function is a Lua function, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5219 <code>"C"</code> if it is a C function, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5220 <code>"main"</code> if it is the main part of a chunk. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5221 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5222 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5223 <li><b><code>currentline</code>: </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5224 the current line where the given function is executing. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5225 When no line information is available, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5226 <code>currentline</code> is set to -1. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5227 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5228 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5229 <li><b><code>name</code>: </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5230 a reasonable name for the given function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5231 Because functions in Lua are first-class values, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5232 they do not have a fixed name: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5233 some functions can be the value of multiple global variables, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5234 while others can be stored only in a table field. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5235 The <code>lua_getinfo</code> function checks how the function was |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5236 called to find a suitable name. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5237 If it cannot find a name, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5238 then <code>name</code> is set to <code>NULL</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5239 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5240 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5241 <li><b><code>namewhat</code>: </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5242 explains the <code>name</code> field. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5243 The value of <code>namewhat</code> can be |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5244 <code>"global"</code>, <code>"local"</code>, <code>"method"</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5245 <code>"field"</code>, <code>"upvalue"</code>, or <code>""</code> (the empty string), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5246 according to how the function was called. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5247 (Lua uses the empty string when no other option seems to apply.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5248 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5249 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5250 <li><b><code>istailcall</code>: </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5251 true if this function invocation was called by a tail call. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5252 In this case, the caller of this level is not in the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5253 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5254 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5255 <li><b><code>nups</code>: </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5256 the number of upvalues of the function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5257 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5258 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5259 <li><b><code>nparams</code>: </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5260 the number of fixed parameters of the function |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5261 (always 0 for C functions). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5262 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5263 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5264 <li><b><code>isvararg</code>: </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5265 true if the function is a vararg function |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5266 (always true for C functions). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5267 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5268 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5269 </ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5270 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5271 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5272 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5273 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5274 <hr><h3><a name="lua_gethook"><code>lua_gethook</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5275 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5276 <pre>lua_Hook lua_gethook (lua_State *L);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5277 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5278 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5279 Returns the current hook function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5280 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5281 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5282 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5283 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5284 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5285 <hr><h3><a name="lua_gethookcount"><code>lua_gethookcount</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5286 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5287 <pre>int lua_gethookcount (lua_State *L);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5288 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5289 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5290 Returns the current hook count. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5291 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5292 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5293 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5294 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5295 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5296 <hr><h3><a name="lua_gethookmask"><code>lua_gethookmask</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5297 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5298 <pre>int lua_gethookmask (lua_State *L);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5299 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5300 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5301 Returns the current hook mask. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5302 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5303 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5304 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5305 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5306 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5307 <hr><h3><a name="lua_getinfo"><code>lua_getinfo</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5308 <span class="apii">[-(0|1), +(0|1|2), <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5309 <pre>int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5310 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5311 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5312 Gets information about a specific function or function invocation. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5313 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5314 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5315 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5316 To get information about a function invocation, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5317 the parameter <code>ar</code> must be a valid activation record that was |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5318 filled by a previous call to <a href="#lua_getstack"><code>lua_getstack</code></a> or |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5319 given as argument to a hook (see <a href="#lua_Hook"><code>lua_Hook</code></a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5320 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5321 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5322 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5323 To get information about a function you push it onto the stack |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5324 and start the <code>what</code> string with the character '<code>></code>'. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5325 (In that case, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5326 <code>lua_getinfo</code> pops the function from the top of the stack.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5327 For instance, to know in which line a function <code>f</code> was defined, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5328 you can write the following code: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5329 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5330 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5331 lua_Debug ar; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5332 lua_getglobal(L, "f"); /* get global 'f' */ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5333 lua_getinfo(L, ">S", &ar); |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5334 printf("%d\n", ar.linedefined); |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5335 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5336 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5337 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5338 Each character in the string <code>what</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5339 selects some fields of the structure <code>ar</code> to be filled or |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5340 a value to be pushed on the stack: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5341 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5342 <ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5343 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5344 <li><b>'<code>n</code>': </b> fills in the field <code>name</code> and <code>namewhat</code>; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5345 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5346 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5347 <li><b>'<code>S</code>': </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5348 fills in the fields <code>source</code>, <code>short_src</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5349 <code>linedefined</code>, <code>lastlinedefined</code>, and <code>what</code>; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5350 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5351 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5352 <li><b>'<code>l</code>': </b> fills in the field <code>currentline</code>; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5353 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5354 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5355 <li><b>'<code>t</code>': </b> fills in the field <code>istailcall</code>; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5356 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5357 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5358 <li><b>'<code>u</code>': </b> fills in the fields |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5359 <code>nups</code>, <code>nparams</code>, and <code>isvararg</code>; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5360 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5361 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5362 <li><b>'<code>f</code>': </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5363 pushes onto the stack the function that is |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5364 running at the given level; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5365 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5366 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5367 <li><b>'<code>L</code>': </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5368 pushes onto the stack a table whose indices are the |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5369 numbers of the lines that are valid on the function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5370 (A <em>valid line</em> is a line with some associated code, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5371 that is, a line where you can put a break point. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5372 Non-valid lines include empty lines and comments.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5373 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5374 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5375 </ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5376 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5377 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5378 This function returns 0 on error |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5379 (for instance, an invalid option in <code>what</code>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5380 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5381 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5382 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5383 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5384 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5385 <hr><h3><a name="lua_getlocal"><code>lua_getlocal</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5386 <span class="apii">[-0, +(0|1), –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5387 <pre>const char *lua_getlocal (lua_State *L, lua_Debug *ar, int n);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5388 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5389 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5390 Gets information about a local variable of |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5391 a given activation record or a given function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5392 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5393 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5394 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5395 In the first case, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5396 the parameter <code>ar</code> must be a valid activation record that was |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5397 filled by a previous call to <a href="#lua_getstack"><code>lua_getstack</code></a> or |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5398 given as argument to a hook (see <a href="#lua_Hook"><code>lua_Hook</code></a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5399 The index <code>n</code> selects which local variable to inspect; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5400 see <a href="#pdf-debug.getlocal"><code>debug.getlocal</code></a> for details about variable indices |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5401 and names. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5402 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5403 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5404 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5405 <a href="#lua_getlocal"><code>lua_getlocal</code></a> pushes the variable's value onto the stack |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5406 and returns its name. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5407 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5408 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5409 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5410 In the second case, <code>ar</code> should be <code>NULL</code> and the function |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5411 to be inspected must be at the top of the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5412 In this case, only parameters of Lua functions are visible |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5413 (as there is no information about what variables are active) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5414 and no values are pushed onto the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5415 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5416 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5417 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5418 Returns <code>NULL</code> (and pushes nothing) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5419 when the index is greater than |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5420 the number of active local variables. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5421 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5422 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5423 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5424 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5425 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5426 <hr><h3><a name="lua_getstack"><code>lua_getstack</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5427 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5428 <pre>int lua_getstack (lua_State *L, int level, lua_Debug *ar);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5429 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5430 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5431 Gets information about the interpreter runtime stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5432 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5433 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5434 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5435 This function fills parts of a <a href="#lua_Debug"><code>lua_Debug</code></a> structure with |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5436 an identification of the <em>activation record</em> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5437 of the function executing at a given level. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5438 Level 0 is the current running function, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5439 whereas level <em>n+1</em> is the function that has called level <em>n</em> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5440 (except for tail calls, which do not count on the stack). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5441 When there are no errors, <a href="#lua_getstack"><code>lua_getstack</code></a> returns 1; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5442 when called with a level greater than the stack depth, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5443 it returns 0. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5444 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5445 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5446 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5447 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5448 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5449 <hr><h3><a name="lua_getupvalue"><code>lua_getupvalue</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5450 <span class="apii">[-0, +(0|1), –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5451 <pre>const char *lua_getupvalue (lua_State *L, int funcindex, int n);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5452 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5453 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5454 Gets information about a closure's upvalue. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5455 (For Lua functions, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5456 upvalues are the external local variables that the function uses, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5457 and that are consequently included in its closure.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5458 <a href="#lua_getupvalue"><code>lua_getupvalue</code></a> gets the index <code>n</code> of an upvalue, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5459 pushes the upvalue's value onto the stack, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5460 and returns its name. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5461 <code>funcindex</code> points to the closure in the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5462 (Upvalues have no particular order, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5463 as they are active through the whole function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5464 So, they are numbered in an arbitrary order.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5465 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5466 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5467 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5468 Returns <code>NULL</code> (and pushes nothing) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5469 when the index is greater than the number of upvalues. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5470 For C functions, this function uses the empty string <code>""</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5471 as a name for all upvalues. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5472 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5473 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5474 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5475 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5476 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5477 <hr><h3><a name="lua_Hook"><code>lua_Hook</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5478 <pre>typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5479 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5480 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5481 Type for debugging hook functions. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5482 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5483 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5484 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5485 Whenever a hook is called, its <code>ar</code> argument has its field |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5486 <code>event</code> set to the specific event that triggered the hook. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5487 Lua identifies these events with the following constants: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5488 <a name="pdf-LUA_HOOKCALL"><code>LUA_HOOKCALL</code></a>, <a name="pdf-LUA_HOOKRET"><code>LUA_HOOKRET</code></a>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5489 <a name="pdf-LUA_HOOKTAILCALL"><code>LUA_HOOKTAILCALL</code></a>, <a name="pdf-LUA_HOOKLINE"><code>LUA_HOOKLINE</code></a>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5490 and <a name="pdf-LUA_HOOKCOUNT"><code>LUA_HOOKCOUNT</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5491 Moreover, for line events, the field <code>currentline</code> is also set. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5492 To get the value of any other field in <code>ar</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5493 the hook must call <a href="#lua_getinfo"><code>lua_getinfo</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5494 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5495 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5496 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5497 For call events, <code>event</code> can be <code>LUA_HOOKCALL</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5498 the normal value, or <code>LUA_HOOKTAILCALL</code>, for a tail call; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5499 in this case, there will be no corresponding return event. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5500 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5501 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5502 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5503 While Lua is running a hook, it disables other calls to hooks. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5504 Therefore, if a hook calls back Lua to execute a function or a chunk, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5505 this execution occurs without any calls to hooks. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5506 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5507 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5508 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5509 Hook functions cannot have continuations, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5510 that is, they cannot call <a href="#lua_yieldk"><code>lua_yieldk</code></a>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5511 <a href="#lua_pcallk"><code>lua_pcallk</code></a>, or <a href="#lua_callk"><code>lua_callk</code></a> with a non-null <code>k</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5512 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5513 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5514 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5515 Hook functions can yield under the following conditions: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5516 Only count and line events can yield |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5517 and they cannot yield any value; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5518 to yield a hook function must finish its execution |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5519 calling <a href="#lua_yield"><code>lua_yield</code></a> with <code>nresults</code> equal to zero. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5520 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5521 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5522 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5523 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5524 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5525 <hr><h3><a name="lua_sethook"><code>lua_sethook</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5526 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5527 <pre>int lua_sethook (lua_State *L, lua_Hook f, int mask, int count);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5528 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5529 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5530 Sets the debugging hook function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5531 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5532 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5533 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5534 Argument <code>f</code> is the hook function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5535 <code>mask</code> specifies on which events the hook will be called: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5536 it is formed by a bitwise or of the constants |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5537 <a name="pdf-LUA_MASKCALL"><code>LUA_MASKCALL</code></a>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5538 <a name="pdf-LUA_MASKRET"><code>LUA_MASKRET</code></a>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5539 <a name="pdf-LUA_MASKLINE"><code>LUA_MASKLINE</code></a>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5540 and <a name="pdf-LUA_MASKCOUNT"><code>LUA_MASKCOUNT</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5541 The <code>count</code> argument is only meaningful when the mask |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5542 includes <code>LUA_MASKCOUNT</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5543 For each event, the hook is called as explained below: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5544 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5545 <ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5546 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5547 <li><b>The call hook: </b> is called when the interpreter calls a function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5548 The hook is called just after Lua enters the new function, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5549 before the function gets its arguments. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5550 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5551 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5552 <li><b>The return hook: </b> is called when the interpreter returns from a function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5553 The hook is called just before Lua leaves the function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5554 There is no standard way to access the values |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5555 to be returned by the function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5556 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5557 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5558 <li><b>The line hook: </b> is called when the interpreter is about to |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5559 start the execution of a new line of code, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5560 or when it jumps back in the code (even to the same line). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5561 (This event only happens while Lua is executing a Lua function.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5562 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5563 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5564 <li><b>The count hook: </b> is called after the interpreter executes every |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5565 <code>count</code> instructions. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5566 (This event only happens while Lua is executing a Lua function.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5567 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5568 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5569 </ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5570 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5571 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5572 A hook is disabled by setting <code>mask</code> to zero. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5573 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5574 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5575 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5576 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5577 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5578 <hr><h3><a name="lua_setlocal"><code>lua_setlocal</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5579 <span class="apii">[-(0|1), +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5580 <pre>const char *lua_setlocal (lua_State *L, lua_Debug *ar, int n);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5581 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5582 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5583 Sets the value of a local variable of a given activation record. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5584 Parameters <code>ar</code> and <code>n</code> are as in <a href="#lua_getlocal"><code>lua_getlocal</code></a> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5585 (see <a href="#lua_getlocal"><code>lua_getlocal</code></a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5586 <a href="#lua_setlocal"><code>lua_setlocal</code></a> assigns the value at the top of the stack |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5587 to the variable and returns its name. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5588 It also pops the value from the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5589 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5590 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5591 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5592 Returns <code>NULL</code> (and pops nothing) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5593 when the index is greater than |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5594 the number of active local variables. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5595 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5596 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5597 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5598 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5599 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5600 <hr><h3><a name="lua_setupvalue"><code>lua_setupvalue</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5601 <span class="apii">[-(0|1), +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5602 <pre>const char *lua_setupvalue (lua_State *L, int funcindex, int n);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5603 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5604 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5605 Sets the value of a closure's upvalue. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5606 It assigns the value at the top of the stack |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5607 to the upvalue and returns its name. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5608 It also pops the value from the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5609 Parameters <code>funcindex</code> and <code>n</code> are as in the <a href="#lua_getupvalue"><code>lua_getupvalue</code></a> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5610 (see <a href="#lua_getupvalue"><code>lua_getupvalue</code></a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5611 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5612 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5613 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5614 Returns <code>NULL</code> (and pops nothing) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5615 when the index is greater than the number of upvalues. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5616 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5617 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5618 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5619 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5620 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5621 <hr><h3><a name="lua_upvalueid"><code>lua_upvalueid</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5622 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5623 <pre>void *lua_upvalueid (lua_State *L, int funcindex, int n);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5624 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5625 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5626 Returns an unique identifier for the upvalue numbered <code>n</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5627 from the closure at index <code>funcindex</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5628 Parameters <code>funcindex</code> and <code>n</code> are as in the <a href="#lua_getupvalue"><code>lua_getupvalue</code></a> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5629 (see <a href="#lua_getupvalue"><code>lua_getupvalue</code></a>) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5630 (but <code>n</code> cannot be greater than the number of upvalues). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5631 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5632 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5633 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5634 These unique identifiers allow a program to check whether different |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5635 closures share upvalues. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5636 Lua closures that share an upvalue |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5637 (that is, that access a same external local variable) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5638 will return identical ids for those upvalue indices. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5639 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5640 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5641 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5642 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5643 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5644 <hr><h3><a name="lua_upvaluejoin"><code>lua_upvaluejoin</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5645 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5646 <pre>void lua_upvaluejoin (lua_State *L, int funcindex1, int n1, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5647 int funcindex2, int n2);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5648 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5649 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5650 Make the <code>n1</code>-th upvalue of the Lua closure at index <code>funcindex1</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5651 refer to the <code>n2</code>-th upvalue of the Lua closure at index <code>funcindex2</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5652 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5653 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5654 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5655 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5656 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5657 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5658 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5659 <h1>5 – <a name="5">The Auxiliary Library</a></h1> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5660 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5661 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5662 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5663 The <em>auxiliary library</em> provides several convenient functions |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5664 to interface C with Lua. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5665 While the basic API provides the primitive functions for all |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5666 interactions between C and Lua, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5667 the auxiliary library provides higher-level functions for some |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5668 common tasks. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5669 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5670 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5671 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5672 All functions and types from the auxiliary library |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5673 are defined in header file <code>lauxlib.h</code> and |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5674 have a prefix <code>luaL_</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5675 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5676 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5677 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5678 All functions in the auxiliary library are built on |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5679 top of the basic API, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5680 and so they provide nothing that cannot be done with that API. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5681 Nevertheless, the use of the auxiliary library ensures |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5682 more consistency to your code. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5683 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5684 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5685 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5686 Several functions in the auxiliary library use internally some |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5687 extra stack slots. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5688 When a function in the auxiliary library uses less than five slots, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5689 it does not check the stack size; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5690 it simply assumes that there are enough slots. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5691 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5692 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5693 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5694 Several functions in the auxiliary library are used to |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5695 check C function arguments. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5696 Because the error message is formatted for arguments |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5697 (e.g., "<code>bad argument #1</code>"), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5698 you should not use these functions for other stack values. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5699 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5700 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5701 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5702 Functions called <code>luaL_check*</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5703 always throw an error if the check is not satisfied. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5704 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5705 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5706 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5707 <h2>5.1 – <a name="5.1">Functions and Types</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5708 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5709 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5710 Here we list all functions and types from the auxiliary library |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5711 in alphabetical order. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5712 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5713 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5714 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5715 <hr><h3><a name="luaL_addchar"><code>luaL_addchar</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5716 <span class="apii">[-?, +?, <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5717 <pre>void luaL_addchar (luaL_Buffer *B, char c);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5718 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5719 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5720 Adds the byte <code>c</code> to the buffer <code>B</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5721 (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5722 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5723 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5724 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5725 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5726 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5727 <hr><h3><a name="luaL_addlstring"><code>luaL_addlstring</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5728 <span class="apii">[-?, +?, <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5729 <pre>void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5730 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5731 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5732 Adds the string pointed to by <code>s</code> with length <code>l</code> to |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5733 the buffer <code>B</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5734 (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5735 The string can contain embedded zeros. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5736 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5737 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5738 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5739 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5740 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5741 <hr><h3><a name="luaL_addsize"><code>luaL_addsize</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5742 <span class="apii">[-?, +?, <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5743 <pre>void luaL_addsize (luaL_Buffer *B, size_t n);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5744 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5745 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5746 Adds to the buffer <code>B</code> (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5747 a string of length <code>n</code> previously copied to the |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5748 buffer area (see <a href="#luaL_prepbuffer"><code>luaL_prepbuffer</code></a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5749 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5750 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5751 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5752 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5753 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5754 <hr><h3><a name="luaL_addstring"><code>luaL_addstring</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5755 <span class="apii">[-?, +?, <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5756 <pre>void luaL_addstring (luaL_Buffer *B, const char *s);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5757 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5758 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5759 Adds the zero-terminated string pointed to by <code>s</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5760 to the buffer <code>B</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5761 (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5762 The string cannot contain embedded zeros. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5763 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5764 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5765 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5766 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5767 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5768 <hr><h3><a name="luaL_addvalue"><code>luaL_addvalue</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5769 <span class="apii">[-1, +?, <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5770 <pre>void luaL_addvalue (luaL_Buffer *B);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5771 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5772 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5773 Adds the value at the top of the stack |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5774 to the buffer <code>B</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5775 (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5776 Pops the value. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5777 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5778 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5779 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5780 This is the only function on string buffers that can (and must) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5781 be called with an extra element on the stack, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5782 which is the value to be added to the buffer. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5783 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5784 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5785 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5786 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5787 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5788 <hr><h3><a name="luaL_argcheck"><code>luaL_argcheck</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5789 <span class="apii">[-0, +0, <em>v</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5790 <pre>void luaL_argcheck (lua_State *L, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5791 int cond, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5792 int arg, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5793 const char *extramsg);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5794 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5795 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5796 Checks whether <code>cond</code> is true. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5797 If not, raises an error with a standard message. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5798 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5799 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5800 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5801 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5802 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5803 <hr><h3><a name="luaL_argerror"><code>luaL_argerror</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5804 <span class="apii">[-0, +0, <em>v</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5805 <pre>int luaL_argerror (lua_State *L, int arg, const char *extramsg);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5806 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5807 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5808 Raises an error with a standard message |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5809 that includes <code>extramsg</code> as a comment. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5810 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5811 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5812 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5813 This function never returns, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5814 but it is an idiom to use it in C functions |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5815 as <code>return luaL_argerror(<em>args</em>)</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5816 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5817 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5818 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5819 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5820 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5821 <hr><h3><a name="luaL_Buffer"><code>luaL_Buffer</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5822 <pre>typedef struct luaL_Buffer luaL_Buffer;</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5823 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5824 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5825 Type for a <em>string buffer</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5826 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5827 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5828 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5829 A string buffer allows C code to build Lua strings piecemeal. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5830 Its pattern of use is as follows: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5831 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5832 <ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5833 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5834 <li>First declare a variable <code>b</code> of type <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>.</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5835 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5836 <li>Then initialize it with a call <code>luaL_buffinit(L, &b)</code>.</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5837 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5838 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5839 Then add string pieces to the buffer calling any of |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5840 the <code>luaL_add*</code> functions. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5841 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5842 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5843 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5844 Finish by calling <code>luaL_pushresult(&b)</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5845 This call leaves the final string on the top of the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5846 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5847 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5848 </ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5849 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5850 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5851 If you know beforehand the total size of the resulting string, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5852 you can use the buffer like this: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5853 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5854 <ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5855 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5856 <li>First declare a variable <code>b</code> of type <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>.</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5857 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5858 <li>Then initialize it and preallocate a space of |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5859 size <code>sz</code> with a call <code>luaL_buffinitsize(L, &b, sz)</code>.</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5860 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5861 <li>Then copy the string into that space.</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5862 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5863 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5864 Finish by calling <code>luaL_pushresultsize(&b, sz)</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5865 where <code>sz</code> is the total size of the resulting string |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5866 copied into that space. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5867 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5868 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5869 </ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5870 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5871 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5872 During its normal operation, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5873 a string buffer uses a variable number of stack slots. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5874 So, while using a buffer, you cannot assume that you know where |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5875 the top of the stack is. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5876 You can use the stack between successive calls to buffer operations |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5877 as long as that use is balanced; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5878 that is, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5879 when you call a buffer operation, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5880 the stack is at the same level |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5881 it was immediately after the previous buffer operation. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5882 (The only exception to this rule is <a href="#luaL_addvalue"><code>luaL_addvalue</code></a>.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5883 After calling <a href="#luaL_pushresult"><code>luaL_pushresult</code></a> the stack is back to its |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5884 level when the buffer was initialized, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5885 plus the final string on its top. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5886 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5887 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5888 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5889 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5890 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5891 <hr><h3><a name="luaL_buffinit"><code>luaL_buffinit</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5892 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5893 <pre>void luaL_buffinit (lua_State *L, luaL_Buffer *B);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5894 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5895 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5896 Initializes a buffer <code>B</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5897 This function does not allocate any space; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5898 the buffer must be declared as a variable |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5899 (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5900 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5901 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5902 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5903 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5904 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5905 <hr><h3><a name="luaL_buffinitsize"><code>luaL_buffinitsize</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5906 <span class="apii">[-?, +?, <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5907 <pre>char *luaL_buffinitsize (lua_State *L, luaL_Buffer *B, size_t sz);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5908 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5909 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5910 Equivalent to the sequence |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5911 <a href="#luaL_buffinit"><code>luaL_buffinit</code></a>, <a href="#luaL_prepbuffsize"><code>luaL_prepbuffsize</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5912 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5913 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5914 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5915 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5916 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5917 <hr><h3><a name="luaL_callmeta"><code>luaL_callmeta</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5918 <span class="apii">[-0, +(0|1), <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5919 <pre>int luaL_callmeta (lua_State *L, int obj, const char *e);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5920 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5921 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5922 Calls a metamethod. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5923 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5924 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5925 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5926 If the object at index <code>obj</code> has a metatable and this |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5927 metatable has a field <code>e</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5928 this function calls this field passing the object as its only argument. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5929 In this case this function returns true and pushes onto the |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5930 stack the value returned by the call. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5931 If there is no metatable or no metamethod, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5932 this function returns false (without pushing any value on the stack). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5933 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5934 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5935 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5936 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5937 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5938 <hr><h3><a name="luaL_checkany"><code>luaL_checkany</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5939 <span class="apii">[-0, +0, <em>v</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5940 <pre>void luaL_checkany (lua_State *L, int arg);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5941 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5942 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5943 Checks whether the function has an argument |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5944 of any type (including <b>nil</b>) at position <code>arg</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5945 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5946 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5947 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5948 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5949 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5950 <hr><h3><a name="luaL_checkint"><code>luaL_checkint</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5951 <span class="apii">[-0, +0, <em>v</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5952 <pre>int luaL_checkint (lua_State *L, int arg);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5953 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5954 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5955 Checks whether the function argument <code>arg</code> is a number |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5956 and returns this number cast to an <code>int</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5957 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5958 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5959 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5960 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5961 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5962 <hr><h3><a name="luaL_checkinteger"><code>luaL_checkinteger</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5963 <span class="apii">[-0, +0, <em>v</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5964 <pre>lua_Integer luaL_checkinteger (lua_State *L, int arg);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5965 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5966 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5967 Checks whether the function argument <code>arg</code> is a number |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5968 and returns this number cast to a <a href="#lua_Integer"><code>lua_Integer</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5969 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5970 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5971 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5972 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5973 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5974 <hr><h3><a name="luaL_checklong"><code>luaL_checklong</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5975 <span class="apii">[-0, +0, <em>v</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5976 <pre>long luaL_checklong (lua_State *L, int arg);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5977 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5978 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5979 Checks whether the function argument <code>arg</code> is a number |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5980 and returns this number cast to a <code>long</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5981 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5982 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5983 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5984 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5985 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5986 <hr><h3><a name="luaL_checklstring"><code>luaL_checklstring</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5987 <span class="apii">[-0, +0, <em>v</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5988 <pre>const char *luaL_checklstring (lua_State *L, int arg, size_t *l);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5989 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5990 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5991 Checks whether the function argument <code>arg</code> is a string |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5992 and returns this string; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5993 if <code>l</code> is not <code>NULL</code> fills <code>*l</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5994 with the string's length. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5995 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5996 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5997 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5998 This function uses <a href="#lua_tolstring"><code>lua_tolstring</code></a> to get its result, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5999 so all conversions and caveats of that function apply here. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6000 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6001 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6002 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6003 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6004 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6005 <hr><h3><a name="luaL_checknumber"><code>luaL_checknumber</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6006 <span class="apii">[-0, +0, <em>v</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6007 <pre>lua_Number luaL_checknumber (lua_State *L, int arg);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6008 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6009 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6010 Checks whether the function argument <code>arg</code> is a number |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6011 and returns this number. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6012 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6013 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6014 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6015 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6016 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6017 <hr><h3><a name="luaL_checkoption"><code>luaL_checkoption</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6018 <span class="apii">[-0, +0, <em>v</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6019 <pre>int luaL_checkoption (lua_State *L, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6020 int arg, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6021 const char *def, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6022 const char *const lst[]);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6023 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6024 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6025 Checks whether the function argument <code>arg</code> is a string and |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6026 searches for this string in the array <code>lst</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6027 (which must be NULL-terminated). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6028 Returns the index in the array where the string was found. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6029 Raises an error if the argument is not a string or |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6030 if the string cannot be found. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6031 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6032 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6033 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6034 If <code>def</code> is not <code>NULL</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6035 the function uses <code>def</code> as a default value when |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6036 there is no argument <code>arg</code> or when this argument is <b>nil</b>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6037 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6038 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6039 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6040 This is a useful function for mapping strings to C enums. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6041 (The usual convention in Lua libraries is |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6042 to use strings instead of numbers to select options.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6043 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6044 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6045 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6046 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6047 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6048 <hr><h3><a name="luaL_checkstack"><code>luaL_checkstack</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6049 <span class="apii">[-0, +0, <em>v</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6050 <pre>void luaL_checkstack (lua_State *L, int sz, const char *msg);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6051 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6052 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6053 Grows the stack size to <code>top + sz</code> elements, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6054 raising an error if the stack cannot grow to that size. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6055 <code>msg</code> is an additional text to go into the error message |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6056 (or <code>NULL</code> for no additional text). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6057 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6058 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6059 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6060 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6061 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6062 <hr><h3><a name="luaL_checkstring"><code>luaL_checkstring</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6063 <span class="apii">[-0, +0, <em>v</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6064 <pre>const char *luaL_checkstring (lua_State *L, int arg);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6065 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6066 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6067 Checks whether the function argument <code>arg</code> is a string |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6068 and returns this string. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6069 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6070 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6071 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6072 This function uses <a href="#lua_tolstring"><code>lua_tolstring</code></a> to get its result, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6073 so all conversions and caveats of that function apply here. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6074 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6075 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6076 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6077 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6078 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6079 <hr><h3><a name="luaL_checktype"><code>luaL_checktype</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6080 <span class="apii">[-0, +0, <em>v</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6081 <pre>void luaL_checktype (lua_State *L, int arg, int t);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6082 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6083 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6084 Checks whether the function argument <code>arg</code> has type <code>t</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6085 See <a href="#lua_type"><code>lua_type</code></a> for the encoding of types for <code>t</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6086 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6087 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6088 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6089 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6090 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6091 <hr><h3><a name="luaL_checkudata"><code>luaL_checkudata</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6092 <span class="apii">[-0, +0, <em>v</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6093 <pre>void *luaL_checkudata (lua_State *L, int arg, const char *tname);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6094 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6095 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6096 Checks whether the function argument <code>arg</code> is a userdata |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6097 of the type <code>tname</code> (see <a href="#luaL_newmetatable"><code>luaL_newmetatable</code></a>) and |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6098 returns the userdata address (see <a href="#lua_touserdata"><code>lua_touserdata</code></a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6099 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6100 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6101 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6102 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6103 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6104 <hr><h3><a name="luaL_checkunsigned"><code>luaL_checkunsigned</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6105 <span class="apii">[-0, +0, <em>v</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6106 <pre>lua_Unsigned luaL_checkunsigned (lua_State *L, int arg);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6107 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6108 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6109 Checks whether the function argument <code>arg</code> is a number |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6110 and returns this number cast to a <a href="#lua_Unsigned"><code>lua_Unsigned</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6111 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6112 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6113 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6114 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6115 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6116 <hr><h3><a name="luaL_checkversion"><code>luaL_checkversion</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6117 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6118 <pre>void luaL_checkversion (lua_State *L);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6119 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6120 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6121 Checks whether the core running the call, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6122 the core that created the Lua state, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6123 and the code making the call are all using the same version of Lua. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6124 Also checks whether the core running the call |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6125 and the core that created the Lua state |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6126 are using the same address space. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6127 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6128 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6129 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6130 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6131 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6132 <hr><h3><a name="luaL_dofile"><code>luaL_dofile</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6133 <span class="apii">[-0, +?, <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6134 <pre>int luaL_dofile (lua_State *L, const char *filename);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6135 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6136 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6137 Loads and runs the given file. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6138 It is defined as the following macro: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6139 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6140 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6141 (luaL_loadfile(L, filename) || lua_pcall(L, 0, LUA_MULTRET, 0)) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6142 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6143 It returns false if there are no errors |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6144 or true in case of errors. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6145 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6146 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6147 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6148 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6149 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6150 <hr><h3><a name="luaL_dostring"><code>luaL_dostring</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6151 <span class="apii">[-0, +?, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6152 <pre>int luaL_dostring (lua_State *L, const char *str);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6153 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6154 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6155 Loads and runs the given string. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6156 It is defined as the following macro: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6157 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6158 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6159 (luaL_loadstring(L, str) || lua_pcall(L, 0, LUA_MULTRET, 0)) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6160 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6161 It returns false if there are no errors |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6162 or true in case of errors. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6163 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6164 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6165 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6166 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6167 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6168 <hr><h3><a name="luaL_error"><code>luaL_error</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6169 <span class="apii">[-0, +0, <em>v</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6170 <pre>int luaL_error (lua_State *L, const char *fmt, ...);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6171 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6172 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6173 Raises an error. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6174 The error message format is given by <code>fmt</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6175 plus any extra arguments, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6176 following the same rules of <a href="#lua_pushfstring"><code>lua_pushfstring</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6177 It also adds at the beginning of the message the file name and |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6178 the line number where the error occurred, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6179 if this information is available. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6180 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6181 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6182 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6183 This function never returns, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6184 but it is an idiom to use it in C functions |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6185 as <code>return luaL_error(<em>args</em>)</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6186 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6187 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6188 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6189 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6190 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6191 <hr><h3><a name="luaL_execresult"><code>luaL_execresult</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6192 <span class="apii">[-0, +3, <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6193 <pre>int luaL_execresult (lua_State *L, int stat);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6194 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6195 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6196 This function produces the return values for |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6197 process-related functions in the standard library |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6198 (<a href="#pdf-os.execute"><code>os.execute</code></a> and <a href="#pdf-io.close"><code>io.close</code></a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6199 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6200 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6201 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6202 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6203 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6204 <hr><h3><a name="luaL_fileresult"><code>luaL_fileresult</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6205 <span class="apii">[-0, +(1|3), <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6206 <pre>int luaL_fileresult (lua_State *L, int stat, const char *fname);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6207 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6208 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6209 This function produces the return values for |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6210 file-related functions in the standard library |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6211 (<a href="#pdf-io.open"><code>io.open</code></a>, <a href="#pdf-os.rename"><code>os.rename</code></a>, <a href="#pdf-file:seek"><code>file:seek</code></a>, etc.). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6212 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6213 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6214 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6215 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6216 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6217 <hr><h3><a name="luaL_getmetafield"><code>luaL_getmetafield</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6218 <span class="apii">[-0, +(0|1), <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6219 <pre>int luaL_getmetafield (lua_State *L, int obj, const char *e);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6220 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6221 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6222 Pushes onto the stack the field <code>e</code> from the metatable |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6223 of the object at index <code>obj</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6224 If the object does not have a metatable, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6225 or if the metatable does not have this field, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6226 returns false and pushes nothing. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6227 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6228 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6229 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6230 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6231 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6232 <hr><h3><a name="luaL_getmetatable"><code>luaL_getmetatable</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6233 <span class="apii">[-0, +1, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6234 <pre>void luaL_getmetatable (lua_State *L, const char *tname);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6235 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6236 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6237 Pushes onto the stack the metatable associated with name <code>tname</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6238 in the registry (see <a href="#luaL_newmetatable"><code>luaL_newmetatable</code></a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6239 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6240 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6241 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6242 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6243 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6244 <hr><h3><a name="luaL_getsubtable"><code>luaL_getsubtable</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6245 <span class="apii">[-0, +1, <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6246 <pre>int luaL_getsubtable (lua_State *L, int idx, const char *fname);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6247 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6248 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6249 Ensures that the value <code>t[fname]</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6250 where <code>t</code> is the value at index <code>idx</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6251 is a table, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6252 and pushes that table onto the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6253 Returns true if it finds a previous table there |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6254 and false if it creates a new table. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6255 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6256 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6257 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6258 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6259 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6260 <hr><h3><a name="luaL_gsub"><code>luaL_gsub</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6261 <span class="apii">[-0, +1, <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6262 <pre>const char *luaL_gsub (lua_State *L, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6263 const char *s, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6264 const char *p, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6265 const char *r);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6266 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6267 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6268 Creates a copy of string <code>s</code> by replacing |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6269 any occurrence of the string <code>p</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6270 with the string <code>r</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6271 Pushes the resulting string on the stack and returns it. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6272 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6273 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6274 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6275 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6276 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6277 <hr><h3><a name="luaL_len"><code>luaL_len</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6278 <span class="apii">[-0, +0, <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6279 <pre>int luaL_len (lua_State *L, int index);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6280 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6281 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6282 Returns the "length" of the value at the given index |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6283 as a number; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6284 it is equivalent to the '<code>#</code>' operator in Lua (see <a href="#3.4.6">§3.4.6</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6285 Raises an error if the result of the operation is not a number. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6286 (This case only can happen through metamethods.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6287 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6288 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6289 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6290 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6291 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6292 <hr><h3><a name="luaL_loadbuffer"><code>luaL_loadbuffer</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6293 <span class="apii">[-0, +1, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6294 <pre>int luaL_loadbuffer (lua_State *L, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6295 const char *buff, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6296 size_t sz, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6297 const char *name);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6298 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6299 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6300 Equivalent to <a href="#luaL_loadbufferx"><code>luaL_loadbufferx</code></a> with <code>mode</code> equal to <code>NULL</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6301 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6302 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6303 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6304 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6305 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6306 <hr><h3><a name="luaL_loadbufferx"><code>luaL_loadbufferx</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6307 <span class="apii">[-0, +1, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6308 <pre>int luaL_loadbufferx (lua_State *L, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6309 const char *buff, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6310 size_t sz, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6311 const char *name, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6312 const char *mode);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6313 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6314 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6315 Loads a buffer as a Lua chunk. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6316 This function uses <a href="#lua_load"><code>lua_load</code></a> to load the chunk in the |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6317 buffer pointed to by <code>buff</code> with size <code>sz</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6318 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6319 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6320 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6321 This function returns the same results as <a href="#lua_load"><code>lua_load</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6322 <code>name</code> is the chunk name, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6323 used for debug information and error messages. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6324 The string <code>mode</code> works as in function <a href="#lua_load"><code>lua_load</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6325 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6326 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6327 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6328 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6329 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6330 <hr><h3><a name="luaL_loadfile"><code>luaL_loadfile</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6331 <span class="apii">[-0, +1, <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6332 <pre>int luaL_loadfile (lua_State *L, const char *filename);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6333 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6334 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6335 Equivalent to <a href="#luaL_loadfilex"><code>luaL_loadfilex</code></a> with <code>mode</code> equal to <code>NULL</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6336 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6337 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6338 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6339 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6340 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6341 <hr><h3><a name="luaL_loadfilex"><code>luaL_loadfilex</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6342 <span class="apii">[-0, +1, <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6343 <pre>int luaL_loadfilex (lua_State *L, const char *filename, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6344 const char *mode);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6345 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6346 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6347 Loads a file as a Lua chunk. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6348 This function uses <a href="#lua_load"><code>lua_load</code></a> to load the chunk in the file |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6349 named <code>filename</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6350 If <code>filename</code> is <code>NULL</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6351 then it loads from the standard input. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6352 The first line in the file is ignored if it starts with a <code>#</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6353 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6354 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6355 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6356 The string <code>mode</code> works as in function <a href="#lua_load"><code>lua_load</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6357 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6358 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6359 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6360 This function returns the same results as <a href="#lua_load"><code>lua_load</code></a>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6361 but it has an extra error code <a name="pdf-LUA_ERRFILE"><code>LUA_ERRFILE</code></a> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6362 if it cannot open/read the file or the file has a wrong mode. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6363 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6364 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6365 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6366 As <a href="#lua_load"><code>lua_load</code></a>, this function only loads the chunk; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6367 it does not run it. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6368 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6369 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6370 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6371 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6372 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6373 <hr><h3><a name="luaL_loadstring"><code>luaL_loadstring</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6374 <span class="apii">[-0, +1, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6375 <pre>int luaL_loadstring (lua_State *L, const char *s);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6376 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6377 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6378 Loads a string as a Lua chunk. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6379 This function uses <a href="#lua_load"><code>lua_load</code></a> to load the chunk in |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6380 the zero-terminated string <code>s</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6381 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6382 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6383 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6384 This function returns the same results as <a href="#lua_load"><code>lua_load</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6385 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6386 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6387 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6388 Also as <a href="#lua_load"><code>lua_load</code></a>, this function only loads the chunk; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6389 it does not run it. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6390 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6391 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6392 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6393 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6394 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6395 <hr><h3><a name="luaL_newlib"><code>luaL_newlib</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6396 <span class="apii">[-0, +1, <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6397 <pre>void luaL_newlib (lua_State *L, const luaL_Reg *l);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6398 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6399 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6400 Creates a new table and registers there |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6401 the functions in list <code>l</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6402 It is implemented as the following macro: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6403 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6404 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6405 (luaL_newlibtable(L,l), luaL_setfuncs(L,l,0)) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6406 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6407 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6408 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6409 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6410 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6411 <hr><h3><a name="luaL_newlibtable"><code>luaL_newlibtable</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6412 <span class="apii">[-0, +1, <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6413 <pre>void luaL_newlibtable (lua_State *L, const luaL_Reg l[]);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6414 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6415 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6416 Creates a new table with a size optimized |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6417 to store all entries in the array <code>l</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6418 (but does not actually store them). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6419 It is intended to be used in conjunction with <a href="#luaL_setfuncs"><code>luaL_setfuncs</code></a> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6420 (see <a href="#luaL_newlib"><code>luaL_newlib</code></a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6421 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6422 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6423 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6424 It is implemented as a macro. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6425 The array <code>l</code> must be the actual array, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6426 not a pointer to it. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6427 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6428 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6429 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6430 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6431 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6432 <hr><h3><a name="luaL_newmetatable"><code>luaL_newmetatable</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6433 <span class="apii">[-0, +1, <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6434 <pre>int luaL_newmetatable (lua_State *L, const char *tname);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6435 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6436 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6437 If the registry already has the key <code>tname</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6438 returns 0. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6439 Otherwise, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6440 creates a new table to be used as a metatable for userdata, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6441 adds it to the registry with key <code>tname</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6442 and returns 1. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6443 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6444 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6445 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6446 In both cases pushes onto the stack the final value associated |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6447 with <code>tname</code> in the registry. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6448 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6449 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6450 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6451 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6452 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6453 <hr><h3><a name="luaL_newstate"><code>luaL_newstate</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6454 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6455 <pre>lua_State *luaL_newstate (void);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6456 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6457 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6458 Creates a new Lua state. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6459 It calls <a href="#lua_newstate"><code>lua_newstate</code></a> with an |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6460 allocator based on the standard C <code>realloc</code> function |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6461 and then sets a panic function (see <a href="#4.6">§4.6</a>) that prints |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6462 an error message to the standard error output in case of fatal |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6463 errors. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6464 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6465 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6466 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6467 Returns the new state, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6468 or <code>NULL</code> if there is a memory allocation error. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6469 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6470 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6471 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6472 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6473 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6474 <hr><h3><a name="luaL_openlibs"><code>luaL_openlibs</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6475 <span class="apii">[-0, +0, <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6476 <pre>void luaL_openlibs (lua_State *L);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6477 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6478 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6479 Opens all standard Lua libraries into the given state. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6480 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6481 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6482 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6483 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6484 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6485 <hr><h3><a name="luaL_optint"><code>luaL_optint</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6486 <span class="apii">[-0, +0, <em>v</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6487 <pre>int luaL_optint (lua_State *L, int arg, int d);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6488 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6489 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6490 If the function argument <code>arg</code> is a number, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6491 returns this number cast to an <code>int</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6492 If this argument is absent or is <b>nil</b>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6493 returns <code>d</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6494 Otherwise, raises an error. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6495 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6496 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6497 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6498 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6499 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6500 <hr><h3><a name="luaL_optinteger"><code>luaL_optinteger</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6501 <span class="apii">[-0, +0, <em>v</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6502 <pre>lua_Integer luaL_optinteger (lua_State *L, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6503 int arg, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6504 lua_Integer d);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6505 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6506 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6507 If the function argument <code>arg</code> is a number, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6508 returns this number cast to a <a href="#lua_Integer"><code>lua_Integer</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6509 If this argument is absent or is <b>nil</b>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6510 returns <code>d</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6511 Otherwise, raises an error. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6512 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6513 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6514 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6515 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6516 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6517 <hr><h3><a name="luaL_optlong"><code>luaL_optlong</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6518 <span class="apii">[-0, +0, <em>v</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6519 <pre>long luaL_optlong (lua_State *L, int arg, long d);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6520 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6521 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6522 If the function argument <code>arg</code> is a number, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6523 returns this number cast to a <code>long</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6524 If this argument is absent or is <b>nil</b>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6525 returns <code>d</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6526 Otherwise, raises an error. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6527 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6528 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6529 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6530 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6531 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6532 <hr><h3><a name="luaL_optlstring"><code>luaL_optlstring</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6533 <span class="apii">[-0, +0, <em>v</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6534 <pre>const char *luaL_optlstring (lua_State *L, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6535 int arg, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6536 const char *d, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6537 size_t *l);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6538 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6539 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6540 If the function argument <code>arg</code> is a string, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6541 returns this string. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6542 If this argument is absent or is <b>nil</b>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6543 returns <code>d</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6544 Otherwise, raises an error. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6545 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6546 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6547 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6548 If <code>l</code> is not <code>NULL</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6549 fills the position <code>*l</code> with the result's length. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6550 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6551 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6552 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6553 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6554 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6555 <hr><h3><a name="luaL_optnumber"><code>luaL_optnumber</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6556 <span class="apii">[-0, +0, <em>v</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6557 <pre>lua_Number luaL_optnumber (lua_State *L, int arg, lua_Number d);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6558 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6559 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6560 If the function argument <code>arg</code> is a number, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6561 returns this number. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6562 If this argument is absent or is <b>nil</b>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6563 returns <code>d</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6564 Otherwise, raises an error. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6565 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6566 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6567 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6568 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6569 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6570 <hr><h3><a name="luaL_optstring"><code>luaL_optstring</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6571 <span class="apii">[-0, +0, <em>v</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6572 <pre>const char *luaL_optstring (lua_State *L, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6573 int arg, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6574 const char *d);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6575 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6576 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6577 If the function argument <code>arg</code> is a string, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6578 returns this string. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6579 If this argument is absent or is <b>nil</b>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6580 returns <code>d</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6581 Otherwise, raises an error. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6582 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6583 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6584 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6585 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6586 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6587 <hr><h3><a name="luaL_optunsigned"><code>luaL_optunsigned</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6588 <span class="apii">[-0, +0, <em>v</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6589 <pre>lua_Unsigned luaL_optunsigned (lua_State *L, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6590 int arg, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6591 lua_Unsigned u);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6592 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6593 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6594 If the function argument <code>arg</code> is a number, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6595 returns this number cast to a <a href="#lua_Unsigned"><code>lua_Unsigned</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6596 If this argument is absent or is <b>nil</b>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6597 returns <code>u</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6598 Otherwise, raises an error. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6599 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6600 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6601 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6602 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6603 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6604 <hr><h3><a name="luaL_prepbuffer"><code>luaL_prepbuffer</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6605 <span class="apii">[-?, +?, <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6606 <pre>char *luaL_prepbuffer (luaL_Buffer *B);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6607 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6608 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6609 Equivalent to <a href="#luaL_prepbuffsize"><code>luaL_prepbuffsize</code></a> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6610 with the predefined size <a name="pdf-LUAL_BUFFERSIZE"><code>LUAL_BUFFERSIZE</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6611 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6612 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6613 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6614 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6615 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6616 <hr><h3><a name="luaL_prepbuffsize"><code>luaL_prepbuffsize</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6617 <span class="apii">[-?, +?, <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6618 <pre>char *luaL_prepbuffsize (luaL_Buffer *B, size_t sz);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6619 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6620 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6621 Returns an address to a space of size <code>sz</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6622 where you can copy a string to be added to buffer <code>B</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6623 (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6624 After copying the string into this space you must call |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6625 <a href="#luaL_addsize"><code>luaL_addsize</code></a> with the size of the string to actually add |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6626 it to the buffer. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6627 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6628 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6629 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6630 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6631 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6632 <hr><h3><a name="luaL_pushresult"><code>luaL_pushresult</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6633 <span class="apii">[-?, +1, <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6634 <pre>void luaL_pushresult (luaL_Buffer *B);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6635 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6636 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6637 Finishes the use of buffer <code>B</code> leaving the final string on |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6638 the top of the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6639 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6640 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6641 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6642 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6643 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6644 <hr><h3><a name="luaL_pushresultsize"><code>luaL_pushresultsize</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6645 <span class="apii">[-?, +1, <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6646 <pre>void luaL_pushresultsize (luaL_Buffer *B, size_t sz);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6647 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6648 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6649 Equivalent to the sequence <a href="#luaL_addsize"><code>luaL_addsize</code></a>, <a href="#luaL_pushresult"><code>luaL_pushresult</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6650 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6651 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6652 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6653 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6654 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6655 <hr><h3><a name="luaL_ref"><code>luaL_ref</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6656 <span class="apii">[-1, +0, <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6657 <pre>int luaL_ref (lua_State *L, int t);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6658 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6659 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6660 Creates and returns a <em>reference</em>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6661 in the table at index <code>t</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6662 for the object at the top of the stack (and pops the object). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6663 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6664 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6665 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6666 A reference is a unique integer key. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6667 As long as you do not manually add integer keys into table <code>t</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6668 <a href="#luaL_ref"><code>luaL_ref</code></a> ensures the uniqueness of the key it returns. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6669 You can retrieve an object referred by reference <code>r</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6670 by calling <code>lua_rawgeti(L, t, r)</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6671 Function <a href="#luaL_unref"><code>luaL_unref</code></a> frees a reference and its associated object. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6672 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6673 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6674 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6675 If the object at the top of the stack is <b>nil</b>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6676 <a href="#luaL_ref"><code>luaL_ref</code></a> returns the constant <a name="pdf-LUA_REFNIL"><code>LUA_REFNIL</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6677 The constant <a name="pdf-LUA_NOREF"><code>LUA_NOREF</code></a> is guaranteed to be different |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6678 from any reference returned by <a href="#luaL_ref"><code>luaL_ref</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6679 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6680 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6681 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6682 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6683 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6684 <hr><h3><a name="luaL_Reg"><code>luaL_Reg</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6685 <pre>typedef struct luaL_Reg { |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6686 const char *name; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6687 lua_CFunction func; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6688 } luaL_Reg;</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6689 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6690 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6691 Type for arrays of functions to be registered by |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6692 <a href="#luaL_setfuncs"><code>luaL_setfuncs</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6693 <code>name</code> is the function name and <code>func</code> is a pointer to |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6694 the function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6695 Any array of <a href="#luaL_Reg"><code>luaL_Reg</code></a> must end with an sentinel entry |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6696 in which both <code>name</code> and <code>func</code> are <code>NULL</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6697 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6698 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6699 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6700 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6701 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6702 <hr><h3><a name="luaL_requiref"><code>luaL_requiref</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6703 <span class="apii">[-0, +1, <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6704 <pre>void luaL_requiref (lua_State *L, const char *modname, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6705 lua_CFunction openf, int glb);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6706 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6707 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6708 Calls function <code>openf</code> with string <code>modname</code> as an argument |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6709 and sets the call result in <code>package.loaded[modname]</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6710 as if that function has been called through <a href="#pdf-require"><code>require</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6711 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6712 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6713 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6714 If <code>glb</code> is true, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6715 also stores the result into global <code>modname</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6716 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6717 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6718 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6719 Leaves a copy of that result on the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6720 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6721 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6722 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6723 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6724 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6725 <hr><h3><a name="luaL_setfuncs"><code>luaL_setfuncs</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6726 <span class="apii">[-nup, +0, <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6727 <pre>void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6728 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6729 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6730 Registers all functions in the array <code>l</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6731 (see <a href="#luaL_Reg"><code>luaL_Reg</code></a>) into the table on the top of the stack |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6732 (below optional upvalues, see next). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6733 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6734 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6735 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6736 When <code>nup</code> is not zero, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6737 all functions are created sharing <code>nup</code> upvalues, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6738 which must be previously pushed on the stack |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6739 on top of the library table. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6740 These values are popped from the stack after the registration. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6741 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6742 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6743 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6744 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6745 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6746 <hr><h3><a name="luaL_setmetatable"><code>luaL_setmetatable</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6747 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6748 <pre>void luaL_setmetatable (lua_State *L, const char *tname);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6749 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6750 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6751 Sets the metatable of the object at the top of the stack |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6752 as the metatable associated with name <code>tname</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6753 in the registry (see <a href="#luaL_newmetatable"><code>luaL_newmetatable</code></a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6754 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6755 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6756 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6757 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6758 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6759 <hr><h3><a name="luaL_testudata"><code>luaL_testudata</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6760 <span class="apii">[-0, +0, <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6761 <pre>void *luaL_testudata (lua_State *L, int arg, const char *tname);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6762 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6763 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6764 This function works like <a href="#luaL_checkudata"><code>luaL_checkudata</code></a>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6765 except that, when the test fails, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6766 it returns <code>NULL</code> instead of throwing an error. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6767 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6768 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6769 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6770 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6771 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6772 <hr><h3><a name="luaL_tolstring"><code>luaL_tolstring</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6773 <span class="apii">[-0, +1, <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6774 <pre>const char *luaL_tolstring (lua_State *L, int idx, size_t *len);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6775 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6776 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6777 Converts any Lua value at the given index to a C string |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6778 in a reasonable format. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6779 The resulting string is pushed onto the stack and also |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6780 returned by the function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6781 If <code>len</code> is not <code>NULL</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6782 the function also sets <code>*len</code> with the string length. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6783 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6784 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6785 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6786 If the value has a metatable with a <code>"__tostring"</code> field, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6787 then <code>luaL_tolstring</code> calls the corresponding metamethod |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6788 with the value as argument, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6789 and uses the result of the call as its result. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6790 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6791 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6792 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6793 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6794 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6795 <hr><h3><a name="luaL_traceback"><code>luaL_traceback</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6796 <span class="apii">[-0, +1, <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6797 <pre>void luaL_traceback (lua_State *L, lua_State *L1, const char *msg, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6798 int level);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6799 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6800 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6801 Creates and pushes a traceback of the stack <code>L1</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6802 If <code>msg</code> is not <code>NULL</code> it is appended |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6803 at the beginning of the traceback. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6804 The <code>level</code> parameter tells at which level |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6805 to start the traceback. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6806 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6807 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6808 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6809 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6810 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6811 <hr><h3><a name="luaL_typename"><code>luaL_typename</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6812 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6813 <pre>const char *luaL_typename (lua_State *L, int index);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6814 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6815 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6816 Returns the name of the type of the value at the given index. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6817 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6818 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6819 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6820 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6821 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6822 <hr><h3><a name="luaL_unref"><code>luaL_unref</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6823 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6824 <pre>void luaL_unref (lua_State *L, int t, int ref);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6825 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6826 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6827 Releases reference <code>ref</code> from the table at index <code>t</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6828 (see <a href="#luaL_ref"><code>luaL_ref</code></a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6829 The entry is removed from the table, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6830 so that the referred object can be collected. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6831 The reference <code>ref</code> is also freed to be used again. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6832 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6833 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6834 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6835 If <code>ref</code> is <a href="#pdf-LUA_NOREF"><code>LUA_NOREF</code></a> or <a href="#pdf-LUA_REFNIL"><code>LUA_REFNIL</code></a>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6836 <a href="#luaL_unref"><code>luaL_unref</code></a> does nothing. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6837 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6838 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6839 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6840 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6841 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6842 <hr><h3><a name="luaL_where"><code>luaL_where</code></a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6843 <span class="apii">[-0, +1, <em>e</em>]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6844 <pre>void luaL_where (lua_State *L, int lvl);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6845 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6846 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6847 Pushes onto the stack a string identifying the current position |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6848 of the control at level <code>lvl</code> in the call stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6849 Typically this string has the following format: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6850 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6851 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6852 <em>chunkname</em>:<em>currentline</em>: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6853 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6854 Level 0 is the running function, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6855 level 1 is the function that called the running function, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6856 etc. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6857 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6858 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6859 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6860 This function is used to build a prefix for error messages. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6861 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6862 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6863 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6864 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6865 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6866 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6867 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6868 <h1>6 – <a name="6">Standard Libraries</a></h1> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6869 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6870 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6871 The standard Lua libraries provide useful functions |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6872 that are implemented directly through the C API. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6873 Some of these functions provide essential services to the language |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6874 (e.g., <a href="#pdf-type"><code>type</code></a> and <a href="#pdf-getmetatable"><code>getmetatable</code></a>); |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6875 others provide access to "outside" services (e.g., I/O); |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6876 and others could be implemented in Lua itself, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6877 but are quite useful or have critical performance requirements that |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6878 deserve an implementation in C (e.g., <a href="#pdf-table.sort"><code>table.sort</code></a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6879 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6880 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6881 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6882 All libraries are implemented through the official C API |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6883 and are provided as separate C modules. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6884 Currently, Lua has the following standard libraries: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6885 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6886 <ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6887 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6888 <li>basic library (<a href="#6.1">§6.1</a>);</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6889 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6890 <li>coroutine library (<a href="#6.2">§6.2</a>);</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6891 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6892 <li>package library (<a href="#6.3">§6.3</a>);</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6893 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6894 <li>string manipulation (<a href="#6.4">§6.4</a>);</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6895 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6896 <li>table manipulation (<a href="#6.5">§6.5</a>);</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6897 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6898 <li>mathematical functions (<a href="#6.6">§6.6</a>) (sin, log, etc.);</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6899 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6900 <li>bitwise operations (<a href="#6.7">§6.7</a>);</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6901 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6902 <li>input and output (<a href="#6.8">§6.8</a>);</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6903 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6904 <li>operating system facilities (<a href="#6.9">§6.9</a>);</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6905 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6906 <li>debug facilities (<a href="#6.10">§6.10</a>).</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6907 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6908 </ul><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6909 Except for the basic and the package libraries, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6910 each library provides all its functions as fields of a global table |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6911 or as methods of its objects. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6912 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6913 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6914 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6915 To have access to these libraries, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6916 the C host program should call the <a href="#luaL_openlibs"><code>luaL_openlibs</code></a> function, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6917 which opens all standard libraries. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6918 Alternatively, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6919 the host program can open them individually by using |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6920 <a href="#luaL_requiref"><code>luaL_requiref</code></a> to call |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6921 <a name="pdf-luaopen_base"><code>luaopen_base</code></a> (for the basic library), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6922 <a name="pdf-luaopen_package"><code>luaopen_package</code></a> (for the package library), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6923 <a name="pdf-luaopen_coroutine"><code>luaopen_coroutine</code></a> (for the coroutine library), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6924 <a name="pdf-luaopen_string"><code>luaopen_string</code></a> (for the string library), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6925 <a name="pdf-luaopen_table"><code>luaopen_table</code></a> (for the table library), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6926 <a name="pdf-luaopen_math"><code>luaopen_math</code></a> (for the mathematical library), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6927 <a name="pdf-luaopen_bit32"><code>luaopen_bit32</code></a> (for the bit library), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6928 <a name="pdf-luaopen_io"><code>luaopen_io</code></a> (for the I/O library), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6929 <a name="pdf-luaopen_os"><code>luaopen_os</code></a> (for the Operating System library), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6930 and <a name="pdf-luaopen_debug"><code>luaopen_debug</code></a> (for the debug library). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6931 These functions are declared in <a name="pdf-lualib.h"><code>lualib.h</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6932 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6933 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6934 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6935 <h2>6.1 – <a name="6.1">Basic Functions</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6936 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6937 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6938 The basic library provides core functions to Lua. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6939 If you do not include this library in your application, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6940 you should check carefully whether you need to provide |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6941 implementations for some of its facilities. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6942 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6943 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6944 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6945 <hr><h3><a name="pdf-assert"><code>assert (v [, message])</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6946 Issues an error when |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6947 the value of its argument <code>v</code> is false (i.e., <b>nil</b> or <b>false</b>); |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6948 otherwise, returns all its arguments. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6949 <code>message</code> is an error message; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6950 when absent, it defaults to "assertion failed!" |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6951 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6952 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6953 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6954 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6955 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6956 <hr><h3><a name="pdf-collectgarbage"><code>collectgarbage ([opt [, arg]])</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6957 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6958 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6959 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6960 This function is a generic interface to the garbage collector. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6961 It performs different functions according to its first argument, <code>opt</code>: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6962 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6963 <ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6964 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6965 <li><b>"<code>collect</code>": </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6966 performs a full garbage-collection cycle. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6967 This is the default option. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6968 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6969 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6970 <li><b>"<code>stop</code>": </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6971 stops automatic execution of the garbage collector. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6972 The collector will run only when explicitly invoked, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6973 until a call to restart it. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6974 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6975 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6976 <li><b>"<code>restart</code>": </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6977 restarts automatic execution of the garbage collector. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6978 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6979 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6980 <li><b>"<code>count</code>": </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6981 returns the total memory in use by Lua (in Kbytes) and |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6982 a second value with the total memory in bytes modulo 1024. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6983 The first value has a fractional part, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6984 so the following equality is always true: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6985 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6986 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6987 k, b = collectgarbage("count") |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6988 assert(k*1024 == math.floor(k)*1024 + b) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6989 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6990 (The second result is useful when Lua is compiled |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6991 with a non floating-point type for numbers.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6992 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6993 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6994 <li><b>"<code>step</code>": </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6995 performs a garbage-collection step. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6996 The step "size" is controlled by <code>arg</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6997 (larger values mean more steps) in a non-specified way. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6998 If you want to control the step size |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6999 you must experimentally tune the value of <code>arg</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7000 Returns <b>true</b> if the step finished a collection cycle. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7001 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7002 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7003 <li><b>"<code>setpause</code>": </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7004 sets <code>arg</code> as the new value for the <em>pause</em> of |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7005 the collector (see <a href="#2.5">§2.5</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7006 Returns the previous value for <em>pause</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7007 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7008 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7009 <li><b>"<code>setstepmul</code>": </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7010 sets <code>arg</code> as the new value for the <em>step multiplier</em> of |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7011 the collector (see <a href="#2.5">§2.5</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7012 Returns the previous value for <em>step</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7013 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7014 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7015 <li><b>"<code>isrunning</code>": </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7016 returns a boolean that tells whether the collector is running |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7017 (i.e., not stopped). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7018 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7019 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7020 <li><b>"<code>generational</code>": </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7021 changes the collector to generational mode. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7022 This is an experimental feature (see <a href="#2.5">§2.5</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7023 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7024 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7025 <li><b>"<code>incremental</code>": </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7026 changes the collector to incremental mode. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7027 This is the default mode. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7028 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7029 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7030 </ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7031 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7032 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7033 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7034 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7035 <hr><h3><a name="pdf-dofile"><code>dofile ([filename])</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7036 Opens the named file and executes its contents as a Lua chunk. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7037 When called without arguments, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7038 <code>dofile</code> executes the contents of the standard input (<code>stdin</code>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7039 Returns all values returned by the chunk. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7040 In case of errors, <code>dofile</code> propagates the error |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7041 to its caller (that is, <code>dofile</code> does not run in protected mode). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7042 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7043 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7044 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7045 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7046 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7047 <hr><h3><a name="pdf-error"><code>error (message [, level])</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7048 Terminates the last protected function called |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7049 and returns <code>message</code> as the error message. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7050 Function <code>error</code> never returns. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7051 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7052 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7053 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7054 Usually, <code>error</code> adds some information about the error position |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7055 at the beginning of the message, if the message is a string. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7056 The <code>level</code> argument specifies how to get the error position. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7057 With level 1 (the default), the error position is where the |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7058 <code>error</code> function was called. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7059 Level 2 points the error to where the function |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7060 that called <code>error</code> was called; and so on. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7061 Passing a level 0 avoids the addition of error position information |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7062 to the message. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7063 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7064 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7065 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7066 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7067 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7068 <hr><h3><a name="pdf-_G"><code>_G</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7069 A global variable (not a function) that |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7070 holds the global environment (see <a href="#2.2">§2.2</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7071 Lua itself does not use this variable; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7072 changing its value does not affect any environment, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7073 nor vice-versa. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7074 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7075 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7076 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7077 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7078 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7079 <hr><h3><a name="pdf-getmetatable"><code>getmetatable (object)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7080 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7081 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7082 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7083 If <code>object</code> does not have a metatable, returns <b>nil</b>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7084 Otherwise, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7085 if the object's metatable has a <code>"__metatable"</code> field, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7086 returns the associated value. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7087 Otherwise, returns the metatable of the given object. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7088 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7089 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7090 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7091 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7092 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7093 <hr><h3><a name="pdf-ipairs"><code>ipairs (t)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7094 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7095 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7096 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7097 If <code>t</code> has a metamethod <code>__ipairs</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7098 calls it with <code>t</code> as argument and returns the first three |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7099 results from the call. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7100 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7101 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7102 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7103 Otherwise, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7104 returns three values: an iterator function, the table <code>t</code>, and 0, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7105 so that the construction |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7106 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7107 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7108 for i,v in ipairs(t) do <em>body</em> end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7109 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7110 will iterate over the pairs (<code>1,t[1]</code>), (<code>2,t[2]</code>), ..., |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7111 up to the first integer key absent from the table. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7112 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7113 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7114 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7115 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7116 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7117 <hr><h3><a name="pdf-load"><code>load (ld [, source [, mode [, env]]])</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7118 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7119 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7120 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7121 Loads a chunk. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7122 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7123 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7124 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7125 If <code>ld</code> is a string, the chunk is this string. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7126 If <code>ld</code> is a function, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7127 <code>load</code> calls it repeatedly to get the chunk pieces. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7128 Each call to <code>ld</code> must return a string that concatenates |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7129 with previous results. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7130 A return of an empty string, <b>nil</b>, or no value signals the end of the chunk. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7131 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7132 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7133 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7134 If there are no syntactic errors, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7135 returns the compiled chunk as a function; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7136 otherwise, returns <b>nil</b> plus the error message. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7137 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7138 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7139 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7140 If the resulting function has upvalues, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7141 the first upvalue is set to the value of <code>env</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7142 if that parameter is given, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7143 or to the value of the global environment. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7144 (When you load a main chunk, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7145 the resulting function will always have exactly one upvalue, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7146 the <code>_ENV</code> variable (see <a href="#2.2">§2.2</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7147 When you load a binary chunk created from a function (see <a href="#pdf-string.dump"><code>string.dump</code></a>), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7148 the resulting function can have arbitrary upvalues.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7149 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7150 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7151 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7152 <code>source</code> is used as the source of the chunk for error messages |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7153 and debug information (see <a href="#4.9">§4.9</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7154 When absent, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7155 it defaults to <code>ld</code>, if <code>ld</code> is a string, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7156 or to "<code>=(load)</code>" otherwise. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7157 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7158 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7159 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7160 The string <code>mode</code> controls whether the chunk can be text or binary |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7161 (that is, a precompiled chunk). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7162 It may be the string "<code>b</code>" (only binary chunks), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7163 "<code>t</code>" (only text chunks), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7164 or "<code>bt</code>" (both binary and text). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7165 The default is "<code>bt</code>". |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7166 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7167 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7168 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7169 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7170 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7171 <hr><h3><a name="pdf-loadfile"><code>loadfile ([filename [, mode [, env]]])</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7172 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7173 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7174 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7175 Similar to <a href="#pdf-load"><code>load</code></a>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7176 but gets the chunk from file <code>filename</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7177 or from the standard input, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7178 if no file name is given. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7179 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7180 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7181 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7182 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7183 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7184 <hr><h3><a name="pdf-next"><code>next (table [, index])</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7185 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7186 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7187 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7188 Allows a program to traverse all fields of a table. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7189 Its first argument is a table and its second argument |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7190 is an index in this table. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7191 <code>next</code> returns the next index of the table |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7192 and its associated value. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7193 When called with <b>nil</b> as its second argument, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7194 <code>next</code> returns an initial index |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7195 and its associated value. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7196 When called with the last index, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7197 or with <b>nil</b> in an empty table, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7198 <code>next</code> returns <b>nil</b>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7199 If the second argument is absent, then it is interpreted as <b>nil</b>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7200 In particular, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7201 you can use <code>next(t)</code> to check whether a table is empty. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7202 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7203 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7204 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7205 The order in which the indices are enumerated is not specified, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7206 <em>even for numeric indices</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7207 (To traverse a table in numeric order, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7208 use a numerical <b>for</b>.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7209 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7210 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7211 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7212 The behavior of <code>next</code> is undefined if, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7213 during the traversal, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7214 you assign any value to a non-existent field in the table. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7215 You may however modify existing fields. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7216 In particular, you may clear existing fields. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7217 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7218 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7219 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7220 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7221 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7222 <hr><h3><a name="pdf-pairs"><code>pairs (t)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7223 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7224 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7225 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7226 If <code>t</code> has a metamethod <code>__pairs</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7227 calls it with <code>t</code> as argument and returns the first three |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7228 results from the call. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7229 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7230 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7231 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7232 Otherwise, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7233 returns three values: the <a href="#pdf-next"><code>next</code></a> function, the table <code>t</code>, and <b>nil</b>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7234 so that the construction |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7235 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7236 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7237 for k,v in pairs(t) do <em>body</em> end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7238 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7239 will iterate over all key–value pairs of table <code>t</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7240 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7241 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7242 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7243 See function <a href="#pdf-next"><code>next</code></a> for the caveats of modifying |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7244 the table during its traversal. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7245 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7246 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7247 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7248 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7249 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7250 <hr><h3><a name="pdf-pcall"><code>pcall (f [, arg1, ···])</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7251 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7252 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7253 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7254 Calls function <code>f</code> with |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7255 the given arguments in <em>protected mode</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7256 This means that any error inside <code>f</code> is not propagated; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7257 instead, <code>pcall</code> catches the error |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7258 and returns a status code. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7259 Its first result is the status code (a boolean), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7260 which is true if the call succeeds without errors. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7261 In such case, <code>pcall</code> also returns all results from the call, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7262 after this first result. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7263 In case of any error, <code>pcall</code> returns <b>false</b> plus the error message. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7264 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7265 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7266 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7267 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7268 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7269 <hr><h3><a name="pdf-print"><code>print (···)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7270 Receives any number of arguments |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7271 and prints their values to <code>stdout</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7272 using the <a href="#pdf-tostring"><code>tostring</code></a> function to convert each argument to a string. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7273 <code>print</code> is not intended for formatted output, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7274 but only as a quick way to show a value, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7275 for instance for debugging. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7276 For complete control over the output, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7277 use <a href="#pdf-string.format"><code>string.format</code></a> and <a href="#pdf-io.write"><code>io.write</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7278 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7279 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7280 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7281 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7282 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7283 <hr><h3><a name="pdf-rawequal"><code>rawequal (v1, v2)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7284 Checks whether <code>v1</code> is equal to <code>v2</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7285 without invoking any metamethod. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7286 Returns a boolean. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7287 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7288 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7289 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7290 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7291 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7292 <hr><h3><a name="pdf-rawget"><code>rawget (table, index)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7293 Gets the real value of <code>table[index]</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7294 without invoking any metamethod. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7295 <code>table</code> must be a table; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7296 <code>index</code> may be any value. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7297 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7298 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7299 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7300 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7301 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7302 <hr><h3><a name="pdf-rawlen"><code>rawlen (v)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7303 Returns the length of the object <code>v</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7304 which must be a table or a string, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7305 without invoking any metamethod. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7306 Returns an integer number. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7307 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7308 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7309 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7310 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7311 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7312 <hr><h3><a name="pdf-rawset"><code>rawset (table, index, value)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7313 Sets the real value of <code>table[index]</code> to <code>value</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7314 without invoking any metamethod. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7315 <code>table</code> must be a table, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7316 <code>index</code> any value different from <b>nil</b> and NaN, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7317 and <code>value</code> any Lua value. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7318 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7319 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7320 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7321 This function returns <code>table</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7322 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7323 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7324 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7325 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7326 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7327 <hr><h3><a name="pdf-select"><code>select (index, ···)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7328 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7329 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7330 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7331 If <code>index</code> is a number, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7332 returns all arguments after argument number <code>index</code>; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7333 a negative number indexes from the end (-1 is the last argument). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7334 Otherwise, <code>index</code> must be the string <code>"#"</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7335 and <code>select</code> returns the total number of extra arguments it received. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7336 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7337 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7338 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7339 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7340 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7341 <hr><h3><a name="pdf-setmetatable"><code>setmetatable (table, metatable)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7342 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7343 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7344 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7345 Sets the metatable for the given table. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7346 (You cannot change the metatable of other types from Lua, only from C.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7347 If <code>metatable</code> is <b>nil</b>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7348 removes the metatable of the given table. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7349 If the original metatable has a <code>"__metatable"</code> field, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7350 raises an error. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7351 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7352 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7353 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7354 This function returns <code>table</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7355 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7356 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7357 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7358 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7359 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7360 <hr><h3><a name="pdf-tonumber"><code>tonumber (e [, base])</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7361 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7362 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7363 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7364 When called with no <code>base</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7365 <code>tonumber</code> tries to convert its argument to a number. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7366 If the argument is already a number or |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7367 a string convertible to a number (see <a href="#3.4.2">§3.4.2</a>), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7368 then <code>tonumber</code> returns this number; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7369 otherwise, it returns <b>nil</b>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7370 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7371 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7372 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7373 When called with <code>base</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7374 then <code>e</code> should be a string to be interpreted as |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7375 an integer numeral in that base. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7376 The base may be any integer between 2 and 36, inclusive. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7377 In bases above 10, the letter '<code>A</code>' (in either upper or lower case) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7378 represents 10, '<code>B</code>' represents 11, and so forth, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7379 with '<code>Z</code>' representing 35. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7380 If the string <code>e</code> is not a valid numeral in the given base, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7381 the function returns <b>nil</b>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7382 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7383 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7384 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7385 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7386 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7387 <hr><h3><a name="pdf-tostring"><code>tostring (v)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7388 Receives a value of any type and |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7389 converts it to a string in a reasonable format. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7390 (For complete control of how numbers are converted, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7391 use <a href="#pdf-string.format"><code>string.format</code></a>.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7392 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7393 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7394 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7395 If the metatable of <code>v</code> has a <code>"__tostring"</code> field, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7396 then <code>tostring</code> calls the corresponding value |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7397 with <code>v</code> as argument, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7398 and uses the result of the call as its result. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7399 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7400 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7401 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7402 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7403 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7404 <hr><h3><a name="pdf-type"><code>type (v)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7405 Returns the type of its only argument, coded as a string. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7406 The possible results of this function are |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7407 "<code>nil</code>" (a string, not the value <b>nil</b>), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7408 "<code>number</code>", |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7409 "<code>string</code>", |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7410 "<code>boolean</code>", |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7411 "<code>table</code>", |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7412 "<code>function</code>", |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7413 "<code>thread</code>", |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7414 and "<code>userdata</code>". |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7415 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7416 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7417 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7418 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7419 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7420 <hr><h3><a name="pdf-_VERSION"><code>_VERSION</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7421 A global variable (not a function) that |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7422 holds a string containing the current interpreter version. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7423 The current contents of this variable is "<code>Lua 5.2</code>". |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7424 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7425 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7426 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7427 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7428 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7429 <hr><h3><a name="pdf-xpcall"><code>xpcall (f, msgh [, arg1, ···])</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7430 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7431 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7432 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7433 This function is similar to <a href="#pdf-pcall"><code>pcall</code></a>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7434 except that it sets a new message handler <code>msgh</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7435 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7436 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7437 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7438 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7439 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7440 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7441 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7442 <h2>6.2 – <a name="6.2">Coroutine Manipulation</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7443 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7444 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7445 The operations related to coroutines comprise a sub-library of |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7446 the basic library and come inside the table <a name="pdf-coroutine"><code>coroutine</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7447 See <a href="#2.6">§2.6</a> for a general description of coroutines. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7448 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7449 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7450 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7451 <hr><h3><a name="pdf-coroutine.create"><code>coroutine.create (f)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7452 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7453 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7454 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7455 Creates a new coroutine, with body <code>f</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7456 <code>f</code> must be a Lua function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7457 Returns this new coroutine, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7458 an object with type <code>"thread"</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7459 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7460 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7461 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7462 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7463 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7464 <hr><h3><a name="pdf-coroutine.resume"><code>coroutine.resume (co [, val1, ···])</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7465 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7466 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7467 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7468 Starts or continues the execution of coroutine <code>co</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7469 The first time you resume a coroutine, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7470 it starts running its body. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7471 The values <code>val1</code>, ... are passed |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7472 as the arguments to the body function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7473 If the coroutine has yielded, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7474 <code>resume</code> restarts it; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7475 the values <code>val1</code>, ... are passed |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7476 as the results from the yield. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7477 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7478 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7479 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7480 If the coroutine runs without any errors, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7481 <code>resume</code> returns <b>true</b> plus any values passed to <code>yield</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7482 (if the coroutine yields) or any values returned by the body function |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7483 (if the coroutine terminates). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7484 If there is any error, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7485 <code>resume</code> returns <b>false</b> plus the error message. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7486 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7487 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7488 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7489 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7490 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7491 <hr><h3><a name="pdf-coroutine.running"><code>coroutine.running ()</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7492 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7493 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7494 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7495 Returns the running coroutine plus a boolean, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7496 true when the running coroutine is the main one. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7497 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7498 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7499 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7500 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7501 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7502 <hr><h3><a name="pdf-coroutine.status"><code>coroutine.status (co)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7503 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7504 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7505 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7506 Returns the status of coroutine <code>co</code>, as a string: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7507 <code>"running"</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7508 if the coroutine is running (that is, it called <code>status</code>); |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7509 <code>"suspended"</code>, if the coroutine is suspended in a call to <code>yield</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7510 or if it has not started running yet; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7511 <code>"normal"</code> if the coroutine is active but not running |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7512 (that is, it has resumed another coroutine); |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7513 and <code>"dead"</code> if the coroutine has finished its body function, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7514 or if it has stopped with an error. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7515 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7516 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7517 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7518 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7519 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7520 <hr><h3><a name="pdf-coroutine.wrap"><code>coroutine.wrap (f)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7521 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7522 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7523 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7524 Creates a new coroutine, with body <code>f</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7525 <code>f</code> must be a Lua function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7526 Returns a function that resumes the coroutine each time it is called. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7527 Any arguments passed to the function behave as the |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7528 extra arguments to <code>resume</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7529 Returns the same values returned by <code>resume</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7530 except the first boolean. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7531 In case of error, propagates the error. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7532 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7533 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7534 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7535 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7536 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7537 <hr><h3><a name="pdf-coroutine.yield"><code>coroutine.yield (···)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7538 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7539 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7540 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7541 Suspends the execution of the calling coroutine. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7542 Any arguments to <code>yield</code> are passed as extra results to <code>resume</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7543 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7544 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7545 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7546 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7547 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7548 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7549 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7550 <h2>6.3 – <a name="6.3">Modules</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7551 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7552 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7553 The package library provides basic |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7554 facilities for loading modules in Lua. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7555 It exports one function directly in the global environment: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7556 <a href="#pdf-require"><code>require</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7557 Everything else is exported in a table <a name="pdf-package"><code>package</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7558 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7559 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7560 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7561 <hr><h3><a name="pdf-require"><code>require (modname)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7562 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7563 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7564 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7565 Loads the given module. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7566 The function starts by looking into the <a href="#pdf-package.loaded"><code>package.loaded</code></a> table |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7567 to determine whether <code>modname</code> is already loaded. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7568 If it is, then <code>require</code> returns the value stored |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7569 at <code>package.loaded[modname]</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7570 Otherwise, it tries to find a <em>loader</em> for the module. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7571 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7572 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7573 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7574 To find a loader, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7575 <code>require</code> is guided by the <a href="#pdf-package.searchers"><code>package.searchers</code></a> sequence. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7576 By changing this sequence, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7577 we can change how <code>require</code> looks for a module. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7578 The following explanation is based on the default configuration |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7579 for <a href="#pdf-package.searchers"><code>package.searchers</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7580 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7581 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7582 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7583 First <code>require</code> queries <code>package.preload[modname]</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7584 If it has a value, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7585 this value (which should be a function) is the loader. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7586 Otherwise <code>require</code> searches for a Lua loader using the |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7587 path stored in <a href="#pdf-package.path"><code>package.path</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7588 If that also fails, it searches for a C loader using the |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7589 path stored in <a href="#pdf-package.cpath"><code>package.cpath</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7590 If that also fails, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7591 it tries an <em>all-in-one</em> loader (see <a href="#pdf-package.searchers"><code>package.searchers</code></a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7592 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7593 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7594 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7595 Once a loader is found, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7596 <code>require</code> calls the loader with two arguments: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7597 <code>modname</code> and an extra value dependent on how it got the loader. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7598 (If the loader came from a file, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7599 this extra value is the file name.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7600 If the loader returns any non-nil value, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7601 <code>require</code> assigns the returned value to <code>package.loaded[modname]</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7602 If the loader does not return a non-nil value and |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7603 has not assigned any value to <code>package.loaded[modname]</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7604 then <code>require</code> assigns <b>true</b> to this entry. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7605 In any case, <code>require</code> returns the |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7606 final value of <code>package.loaded[modname]</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7607 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7608 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7609 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7610 If there is any error loading or running the module, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7611 or if it cannot find any loader for the module, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7612 then <code>require</code> raises an error. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7613 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7614 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7615 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7616 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7617 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7618 <hr><h3><a name="pdf-package.config"><code>package.config</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7619 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7620 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7621 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7622 A string describing some compile-time configurations for packages. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7623 This string is a sequence of lines: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7624 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7625 <ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7626 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7627 <li>The first line is the directory separator string. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7628 Default is '<code>\</code>' for Windows and '<code>/</code>' for all other systems.</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7629 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7630 <li>The second line is the character that separates templates in a path. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7631 Default is '<code>;</code>'.</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7632 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7633 <li>The third line is the string that marks the |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7634 substitution points in a template. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7635 Default is '<code>?</code>'.</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7636 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7637 <li>The fourth line is a string that, in a path in Windows, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7638 is replaced by the executable's directory. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7639 Default is '<code>!</code>'.</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7640 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7641 <li>The fifth line is a mark to ignore all text before it |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7642 when building the <code>luaopen_</code> function name. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7643 Default is '<code>-</code>'.</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7644 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7645 </ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7646 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7647 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7648 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7649 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7650 <hr><h3><a name="pdf-package.cpath"><code>package.cpath</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7651 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7652 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7653 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7654 The path used by <a href="#pdf-require"><code>require</code></a> to search for a C loader. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7655 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7656 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7657 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7658 Lua initializes the C path <a href="#pdf-package.cpath"><code>package.cpath</code></a> in the same way |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7659 it initializes the Lua path <a href="#pdf-package.path"><code>package.path</code></a>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7660 using the environment variable <a name="pdf-LUA_CPATH_5_2"><code>LUA_CPATH_5_2</code></a> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7661 or the environment variable <a name="pdf-LUA_CPATH"><code>LUA_CPATH</code></a> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7662 or a default path defined in <code>luaconf.h</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7663 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7664 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7665 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7666 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7667 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7668 <hr><h3><a name="pdf-package.loaded"><code>package.loaded</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7669 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7670 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7671 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7672 A table used by <a href="#pdf-require"><code>require</code></a> to control which |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7673 modules are already loaded. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7674 When you require a module <code>modname</code> and |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7675 <code>package.loaded[modname]</code> is not false, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7676 <a href="#pdf-require"><code>require</code></a> simply returns the value stored there. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7677 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7678 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7679 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7680 This variable is only a reference to the real table; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7681 assignments to this variable do not change the |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7682 table used by <a href="#pdf-require"><code>require</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7683 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7684 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7685 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7686 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7687 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7688 <hr><h3><a name="pdf-package.loadlib"><code>package.loadlib (libname, funcname)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7689 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7690 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7691 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7692 Dynamically links the host program with the C library <code>libname</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7693 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7694 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7695 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7696 If <code>funcname</code> is "<code>*</code>", |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7697 then it only links with the library, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7698 making the symbols exported by the library |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7699 available to other dynamically linked libraries. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7700 Otherwise, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7701 it looks for a function <code>funcname</code> inside the library |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7702 and returns this function as a C function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7703 So, <code>funcname</code> must follow the <a href="#lua_CFunction"><code>lua_CFunction</code></a> prototype |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7704 (see <a href="#lua_CFunction"><code>lua_CFunction</code></a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7705 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7706 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7707 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7708 This is a low-level function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7709 It completely bypasses the package and module system. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7710 Unlike <a href="#pdf-require"><code>require</code></a>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7711 it does not perform any path searching and |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7712 does not automatically adds extensions. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7713 <code>libname</code> must be the complete file name of the C library, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7714 including if necessary a path and an extension. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7715 <code>funcname</code> must be the exact name exported by the C library |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7716 (which may depend on the C compiler and linker used). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7717 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7718 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7719 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7720 This function is not supported by Standard C. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7721 As such, it is only available on some platforms |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7722 (Windows, Linux, Mac OS X, Solaris, BSD, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7723 plus other Unix systems that support the <code>dlfcn</code> standard). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7724 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7725 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7726 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7727 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7728 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7729 <hr><h3><a name="pdf-package.path"><code>package.path</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7730 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7731 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7732 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7733 The path used by <a href="#pdf-require"><code>require</code></a> to search for a Lua loader. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7734 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7735 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7736 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7737 At start-up, Lua initializes this variable with |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7738 the value of the environment variable <a name="pdf-LUA_PATH_5_2"><code>LUA_PATH_5_2</code></a> or |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7739 the environment variable <a name="pdf-LUA_PATH"><code>LUA_PATH</code></a> or |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7740 with a default path defined in <code>luaconf.h</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7741 if those environment variables are not defined. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7742 Any "<code>;;</code>" in the value of the environment variable |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7743 is replaced by the default path. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7744 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7745 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7746 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7747 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7748 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7749 <hr><h3><a name="pdf-package.preload"><code>package.preload</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7750 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7751 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7752 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7753 A table to store loaders for specific modules |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7754 (see <a href="#pdf-require"><code>require</code></a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7755 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7756 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7757 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7758 This variable is only a reference to the real table; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7759 assignments to this variable do not change the |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7760 table used by <a href="#pdf-require"><code>require</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7761 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7762 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7763 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7764 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7765 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7766 <hr><h3><a name="pdf-package.searchers"><code>package.searchers</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7767 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7768 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7769 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7770 A table used by <a href="#pdf-require"><code>require</code></a> to control how to load modules. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7771 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7772 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7773 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7774 Each entry in this table is a <em>searcher function</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7775 When looking for a module, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7776 <a href="#pdf-require"><code>require</code></a> calls each of these searchers in ascending order, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7777 with the module name (the argument given to <a href="#pdf-require"><code>require</code></a>) as its |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7778 sole parameter. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7779 The function can return another function (the module <em>loader</em>) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7780 plus an extra value that will be passed to that loader, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7781 or a string explaining why it did not find that module |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7782 (or <b>nil</b> if it has nothing to say). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7783 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7784 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7785 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7786 Lua initializes this table with four searcher functions. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7787 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7788 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7789 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7790 The first searcher simply looks for a loader in the |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7791 <a href="#pdf-package.preload"><code>package.preload</code></a> table. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7792 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7793 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7794 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7795 The second searcher looks for a loader as a Lua library, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7796 using the path stored at <a href="#pdf-package.path"><code>package.path</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7797 The search is done as described in function <a href="#pdf-package.searchpath"><code>package.searchpath</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7798 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7799 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7800 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7801 The third searcher looks for a loader as a C library, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7802 using the path given by the variable <a href="#pdf-package.cpath"><code>package.cpath</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7803 Again, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7804 the search is done as described in function <a href="#pdf-package.searchpath"><code>package.searchpath</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7805 For instance, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7806 if the C path is the string |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7807 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7808 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7809 "./?.so;./?.dll;/usr/local/?/init.so" |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7810 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7811 the searcher for module <code>foo</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7812 will try to open the files <code>./foo.so</code>, <code>./foo.dll</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7813 and <code>/usr/local/foo/init.so</code>, in that order. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7814 Once it finds a C library, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7815 this searcher first uses a dynamic link facility to link the |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7816 application with the library. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7817 Then it tries to find a C function inside the library to |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7818 be used as the loader. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7819 The name of this C function is the string "<code>luaopen_</code>" |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7820 concatenated with a copy of the module name where each dot |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7821 is replaced by an underscore. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7822 Moreover, if the module name has a hyphen, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7823 its prefix up to (and including) the first hyphen is removed. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7824 For instance, if the module name is <code>a.v1-b.c</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7825 the function name will be <code>luaopen_b_c</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7826 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7827 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7828 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7829 The fourth searcher tries an <em>all-in-one loader</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7830 It searches the C path for a library for |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7831 the root name of the given module. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7832 For instance, when requiring <code>a.b.c</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7833 it will search for a C library for <code>a</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7834 If found, it looks into it for an open function for |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7835 the submodule; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7836 in our example, that would be <code>luaopen_a_b_c</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7837 With this facility, a package can pack several C submodules |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7838 into one single library, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7839 with each submodule keeping its original open function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7840 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7841 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7842 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7843 All searchers except the first one (preload) return as the extra value |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7844 the file name where the module was found, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7845 as returned by <a href="#pdf-package.searchpath"><code>package.searchpath</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7846 The first searcher returns no extra value. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7847 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7848 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7849 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7850 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7851 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7852 <hr><h3><a name="pdf-package.searchpath"><code>package.searchpath (name, path [, sep [, rep]])</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7853 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7854 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7855 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7856 Searches for the given <code>name</code> in the given <code>path</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7857 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7858 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7859 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7860 A path is a string containing a sequence of |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7861 <em>templates</em> separated by semicolons. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7862 For each template, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7863 the function replaces each interrogation mark (if any) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7864 in the template with a copy of <code>name</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7865 wherein all occurrences of <code>sep</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7866 (a dot, by default) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7867 were replaced by <code>rep</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7868 (the system's directory separator, by default), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7869 and then tries to open the resulting file name. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7870 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7871 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7872 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7873 For instance, if the path is the string |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7874 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7875 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7876 "./?.lua;./?.lc;/usr/local/?/init.lua" |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7877 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7878 the search for the name <code>foo.a</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7879 will try to open the files |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7880 <code>./foo/a.lua</code>, <code>./foo/a.lc</code>, and |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7881 <code>/usr/local/foo/a/init.lua</code>, in that order. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7882 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7883 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7884 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7885 Returns the resulting name of the first file that it can |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7886 open in read mode (after closing the file), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7887 or <b>nil</b> plus an error message if none succeeds. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7888 (This error message lists all file names it tried to open.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7889 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7890 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7891 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7892 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7893 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7894 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7895 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7896 <h2>6.4 – <a name="6.4">String Manipulation</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7897 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7898 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7899 This library provides generic functions for string manipulation, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7900 such as finding and extracting substrings, and pattern matching. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7901 When indexing a string in Lua, the first character is at position 1 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7902 (not at 0, as in C). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7903 Indices are allowed to be negative and are interpreted as indexing backwards, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7904 from the end of the string. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7905 Thus, the last character is at position -1, and so on. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7906 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7907 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7908 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7909 The string library provides all its functions inside the table |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7910 <a name="pdf-string"><code>string</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7911 It also sets a metatable for strings |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7912 where the <code>__index</code> field points to the <code>string</code> table. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7913 Therefore, you can use the string functions in object-oriented style. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7914 For instance, <code>string.byte(s,i)</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7915 can be written as <code>s:byte(i)</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7916 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7917 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7918 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7919 The string library assumes one-byte character encodings. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7920 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7921 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7922 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7923 <hr><h3><a name="pdf-string.byte"><code>string.byte (s [, i [, j]])</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7924 Returns the internal numerical codes of the characters <code>s[i]</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7925 <code>s[i+1]</code>, ..., <code>s[j]</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7926 The default value for <code>i</code> is 1; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7927 the default value for <code>j</code> is <code>i</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7928 These indices are corrected |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7929 following the same rules of function <a href="#pdf-string.sub"><code>string.sub</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7930 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7931 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7932 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7933 Numerical codes are not necessarily portable across platforms. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7934 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7935 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7936 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7937 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7938 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7939 <hr><h3><a name="pdf-string.char"><code>string.char (···)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7940 Receives zero or more integers. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7941 Returns a string with length equal to the number of arguments, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7942 in which each character has the internal numerical code equal |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7943 to its corresponding argument. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7944 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7945 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7946 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7947 Numerical codes are not necessarily portable across platforms. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7948 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7949 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7950 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7951 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7952 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7953 <hr><h3><a name="pdf-string.dump"><code>string.dump (function)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7954 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7955 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7956 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7957 Returns a string containing a binary representation of the given function, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7958 so that a later <a href="#pdf-load"><code>load</code></a> on this string returns |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7959 a copy of the function (but with new upvalues). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7960 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7961 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7962 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7963 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7964 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7965 <hr><h3><a name="pdf-string.find"><code>string.find (s, pattern [, init [, plain]])</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7966 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7967 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7968 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7969 Looks for the first match of |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7970 <code>pattern</code> in the string <code>s</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7971 If it finds a match, then <code>find</code> returns the indices of <code>s</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7972 where this occurrence starts and ends; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7973 otherwise, it returns <b>nil</b>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7974 A third, optional numerical argument <code>init</code> specifies |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7975 where to start the search; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7976 its default value is 1 and can be negative. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7977 A value of <b>true</b> as a fourth, optional argument <code>plain</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7978 turns off the pattern matching facilities, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7979 so the function does a plain "find substring" operation, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7980 with no characters in <code>pattern</code> being considered magic. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7981 Note that if <code>plain</code> is given, then <code>init</code> must be given as well. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7982 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7983 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7984 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7985 If the pattern has captures, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7986 then in a successful match |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7987 the captured values are also returned, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7988 after the two indices. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7989 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7990 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7991 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7992 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7993 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7994 <hr><h3><a name="pdf-string.format"><code>string.format (formatstring, ···)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7995 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7996 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7997 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7998 Returns a formatted version of its variable number of arguments |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7999 following the description given in its first argument (which must be a string). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8000 The format string follows the same rules as the ANSI C function <code>sprintf</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8001 The only differences are that the options/modifiers |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8002 <code>*</code>, <code>h</code>, <code>L</code>, <code>l</code>, <code>n</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8003 and <code>p</code> are not supported |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8004 and that there is an extra option, <code>q</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8005 The <code>q</code> option formats a string between double quotes, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8006 using escape sequences when necessary to ensure that |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8007 it can safely be read back by the Lua interpreter. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8008 For instance, the call |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8009 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8010 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8011 string.format('%q', 'a string with "quotes" and \n new line') |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8012 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8013 may produce the string: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8014 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8015 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8016 "a string with \"quotes\" and \ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8017 new line" |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8018 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8019 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8020 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8021 Options |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8022 <code>A</code> and <code>a</code> (when available), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8023 <code>E</code>, <code>e</code>, <code>f</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8024 <code>G</code>, and <code>g</code> all expect a number as argument. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8025 Options <code>c</code>, <code>d</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8026 <code>i</code>, <code>o</code>, <code>u</code>, <code>X</code>, and <code>x</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8027 also expect a number, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8028 but the range of that number may be limited by |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8029 the underlying C implementation. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8030 For options <code>o</code>, <code>u</code>, <code>X</code>, and <code>x</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8031 the number cannot be negative. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8032 Option <code>q</code> expects a string; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8033 option <code>s</code> expects a string without embedded zeros. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8034 If the argument to option <code>s</code> is not a string, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8035 it is converted to one following the same rules of <a href="#pdf-tostring"><code>tostring</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8036 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8037 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8038 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8039 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8040 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8041 <hr><h3><a name="pdf-string.gmatch"><code>string.gmatch (s, pattern)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8042 Returns an iterator function that, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8043 each time it is called, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8044 returns the next captures from <code>pattern</code> over the string <code>s</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8045 If <code>pattern</code> specifies no captures, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8046 then the whole match is produced in each call. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8047 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8048 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8049 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8050 As an example, the following loop |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8051 will iterate over all the words from string <code>s</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8052 printing one per line: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8053 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8054 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8055 s = "hello world from Lua" |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8056 for w in string.gmatch(s, "%a+") do |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8057 print(w) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8058 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8059 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8060 The next example collects all pairs <code>key=value</code> from the |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8061 given string into a table: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8062 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8063 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8064 t = {} |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8065 s = "from=world, to=Lua" |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8066 for k, v in string.gmatch(s, "(%w+)=(%w+)") do |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8067 t[k] = v |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8068 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8069 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8070 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8071 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8072 For this function, a caret '<code>^</code>' at the start of a pattern does not |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8073 work as an anchor, as this would prevent the iteration. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8074 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8075 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8076 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8077 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8078 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8079 <hr><h3><a name="pdf-string.gsub"><code>string.gsub (s, pattern, repl [, n])</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8080 Returns a copy of <code>s</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8081 in which all (or the first <code>n</code>, if given) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8082 occurrences of the <code>pattern</code> have been |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8083 replaced by a replacement string specified by <code>repl</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8084 which can be a string, a table, or a function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8085 <code>gsub</code> also returns, as its second value, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8086 the total number of matches that occurred. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8087 The name <code>gsub</code> comes from <em>Global SUBstitution</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8088 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8089 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8090 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8091 If <code>repl</code> is a string, then its value is used for replacement. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8092 The character <code>%</code> works as an escape character: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8093 any sequence in <code>repl</code> of the form <code>%<em>d</em></code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8094 with <em>d</em> between 1 and 9, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8095 stands for the value of the <em>d</em>-th captured substring. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8096 The sequence <code>%0</code> stands for the whole match. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8097 The sequence <code>%%</code> stands for a single <code>%</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8098 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8099 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8100 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8101 If <code>repl</code> is a table, then the table is queried for every match, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8102 using the first capture as the key. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8103 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8104 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8105 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8106 If <code>repl</code> is a function, then this function is called every time a |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8107 match occurs, with all captured substrings passed as arguments, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8108 in order. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8109 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8110 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8111 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8112 In any case, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8113 if the pattern specifies no captures, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8114 then it behaves as if the whole pattern was inside a capture. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8115 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8116 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8117 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8118 If the value returned by the table query or by the function call |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8119 is a string or a number, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8120 then it is used as the replacement string; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8121 otherwise, if it is <b>false</b> or <b>nil</b>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8122 then there is no replacement |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8123 (that is, the original match is kept in the string). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8124 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8125 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8126 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8127 Here are some examples: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8128 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8129 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8130 x = string.gsub("hello world", "(%w+)", "%1 %1") |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8131 --> x="hello hello world world" |
242
b5a926c481a5
Handle first h1 tag differently.
hugo.tech@gmail.com <hugo.tech@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
241
diff
changeset
|
8132 |
239
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8133 x = string.gsub("hello world", "%w+", "%0 %0", 1) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8134 --> x="hello hello world" |
242
b5a926c481a5
Handle first h1 tag differently.
hugo.tech@gmail.com <hugo.tech@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
241
diff
changeset
|
8135 |
239
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8136 x = string.gsub("hello world from Lua", "(%w+)%s*(%w+)", "%2 %1") |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8137 --> x="world hello Lua from" |
242
b5a926c481a5
Handle first h1 tag differently.
hugo.tech@gmail.com <hugo.tech@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
241
diff
changeset
|
8138 |
239
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8139 x = string.gsub("home = $HOME, user = $USER", "%$(%w+)", os.getenv) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8140 --> x="home = /home/roberto, user = roberto" |
242
b5a926c481a5
Handle first h1 tag differently.
hugo.tech@gmail.com <hugo.tech@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
241
diff
changeset
|
8141 |
239
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8142 x = string.gsub("4+5 = $return 4+5$", "%$(.-)%$", function (s) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8143 return load(s)() |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8144 end) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8145 --> x="4+5 = 9" |
242
b5a926c481a5
Handle first h1 tag differently.
hugo.tech@gmail.com <hugo.tech@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
241
diff
changeset
|
8146 |
239
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8147 local t = {name="lua", version="5.2"} |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8148 x = string.gsub("$name-$version.tar.gz", "%$(%w+)", t) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8149 --> x="lua-5.2.tar.gz" |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8150 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8151 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8152 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8153 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8154 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8155 <hr><h3><a name="pdf-string.len"><code>string.len (s)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8156 Receives a string and returns its length. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8157 The empty string <code>""</code> has length 0. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8158 Embedded zeros are counted, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8159 so <code>"a\000bc\000"</code> has length 5. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8160 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8161 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8162 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8163 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8164 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8165 <hr><h3><a name="pdf-string.lower"><code>string.lower (s)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8166 Receives a string and returns a copy of this string with all |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8167 uppercase letters changed to lowercase. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8168 All other characters are left unchanged. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8169 The definition of what an uppercase letter is depends on the current locale. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8170 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8171 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8172 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8173 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8174 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8175 <hr><h3><a name="pdf-string.match"><code>string.match (s, pattern [, init])</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8176 Looks for the first <em>match</em> of |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8177 <code>pattern</code> in the string <code>s</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8178 If it finds one, then <code>match</code> returns |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8179 the captures from the pattern; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8180 otherwise it returns <b>nil</b>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8181 If <code>pattern</code> specifies no captures, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8182 then the whole match is returned. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8183 A third, optional numerical argument <code>init</code> specifies |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8184 where to start the search; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8185 its default value is 1 and can be negative. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8186 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8187 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8188 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8189 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8190 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8191 <hr><h3><a name="pdf-string.rep"><code>string.rep (s, n [, sep])</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8192 Returns a string that is the concatenation of <code>n</code> copies of |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8193 the string <code>s</code> separated by the string <code>sep</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8194 The default value for <code>sep</code> is the empty string |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8195 (that is, no separator). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8196 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8197 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8198 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8199 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8200 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8201 <hr><h3><a name="pdf-string.reverse"><code>string.reverse (s)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8202 Returns a string that is the string <code>s</code> reversed. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8203 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8204 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8205 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8206 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8207 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8208 <hr><h3><a name="pdf-string.sub"><code>string.sub (s, i [, j])</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8209 Returns the substring of <code>s</code> that |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8210 starts at <code>i</code> and continues until <code>j</code>; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8211 <code>i</code> and <code>j</code> can be negative. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8212 If <code>j</code> is absent, then it is assumed to be equal to -1 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8213 (which is the same as the string length). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8214 In particular, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8215 the call <code>string.sub(s,1,j)</code> returns a prefix of <code>s</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8216 with length <code>j</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8217 and <code>string.sub(s, -i)</code> returns a suffix of <code>s</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8218 with length <code>i</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8219 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8220 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8221 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8222 If, after the translation of negative indices, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8223 <code>i</code> is less than 1, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8224 it is corrected to 1. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8225 If <code>j</code> is greater than the string length, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8226 it is corrected to that length. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8227 If, after these corrections, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8228 <code>i</code> is greater than <code>j</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8229 the function returns the empty string. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8230 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8231 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8232 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8233 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8234 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8235 <hr><h3><a name="pdf-string.upper"><code>string.upper (s)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8236 Receives a string and returns a copy of this string with all |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8237 lowercase letters changed to uppercase. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8238 All other characters are left unchanged. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8239 The definition of what a lowercase letter is depends on the current locale. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8240 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8241 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8242 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8243 <h3>6.4.1 – <a name="6.4.1">Patterns</a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8244 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8245 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8246 <h4>Character Class:</h4><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8247 A <em>character class</em> is used to represent a set of characters. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8248 The following combinations are allowed in describing a character class: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8249 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8250 <ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8251 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8252 <li><b><em>x</em>: </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8253 (where <em>x</em> is not one of the <em>magic characters</em> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8254 <code>^$()%.[]*+-?</code>) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8255 represents the character <em>x</em> itself. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8256 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8257 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8258 <li><b><code>.</code>: </b> (a dot) represents all characters.</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8259 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8260 <li><b><code>%a</code>: </b> represents all letters.</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8261 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8262 <li><b><code>%c</code>: </b> represents all control characters.</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8263 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8264 <li><b><code>%d</code>: </b> represents all digits.</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8265 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8266 <li><b><code>%g</code>: </b> represents all printable characters except space.</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8267 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8268 <li><b><code>%l</code>: </b> represents all lowercase letters.</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8269 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8270 <li><b><code>%p</code>: </b> represents all punctuation characters.</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8271 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8272 <li><b><code>%s</code>: </b> represents all space characters.</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8273 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8274 <li><b><code>%u</code>: </b> represents all uppercase letters.</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8275 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8276 <li><b><code>%w</code>: </b> represents all alphanumeric characters.</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8277 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8278 <li><b><code>%x</code>: </b> represents all hexadecimal digits.</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8279 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8280 <li><b><code>%<em>x</em></code>: </b> (where <em>x</em> is any non-alphanumeric character) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8281 represents the character <em>x</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8282 This is the standard way to escape the magic characters. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8283 Any punctuation character (even the non magic) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8284 can be preceded by a '<code>%</code>' |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8285 when used to represent itself in a pattern. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8286 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8287 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8288 <li><b><code>[<em>set</em>]</code>: </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8289 represents the class which is the union of all |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8290 characters in <em>set</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8291 A range of characters can be specified by |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8292 separating the end characters of the range, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8293 in ascending order, with a '<code>-</code>', |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8294 All classes <code>%</code><em>x</em> described above can also be used as |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8295 components in <em>set</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8296 All other characters in <em>set</em> represent themselves. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8297 For example, <code>[%w_]</code> (or <code>[_%w]</code>) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8298 represents all alphanumeric characters plus the underscore, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8299 <code>[0-7]</code> represents the octal digits, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8300 and <code>[0-7%l%-]</code> represents the octal digits plus |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8301 the lowercase letters plus the '<code>-</code>' character. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8302 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8303 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8304 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8305 The interaction between ranges and classes is not defined. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8306 Therefore, patterns like <code>[%a-z]</code> or <code>[a-%%]</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8307 have no meaning. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8308 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8309 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8310 <li><b><code>[^<em>set</em>]</code>: </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8311 represents the complement of <em>set</em>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8312 where <em>set</em> is interpreted as above. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8313 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8314 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8315 </ul><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8316 For all classes represented by single letters (<code>%a</code>, <code>%c</code>, etc.), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8317 the corresponding uppercase letter represents the complement of the class. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8318 For instance, <code>%S</code> represents all non-space characters. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8319 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8320 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8321 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8322 The definitions of letter, space, and other character groups |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8323 depend on the current locale. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8324 In particular, the class <code>[a-z]</code> may not be equivalent to <code>%l</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8325 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8326 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8327 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8328 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8329 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8330 <h4>Pattern Item:</h4><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8331 A <em>pattern item</em> can be |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8332 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8333 <ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8334 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8335 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8336 a single character class, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8337 which matches any single character in the class; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8338 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8339 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8340 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8341 a single character class followed by '<code>*</code>', |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8342 which matches 0 or more repetitions of characters in the class. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8343 These repetition items will always match the longest possible sequence; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8344 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8345 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8346 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8347 a single character class followed by '<code>+</code>', |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8348 which matches 1 or more repetitions of characters in the class. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8349 These repetition items will always match the longest possible sequence; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8350 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8351 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8352 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8353 a single character class followed by '<code>-</code>', |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8354 which also matches 0 or more repetitions of characters in the class. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8355 Unlike '<code>*</code>', |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8356 these repetition items will always match the shortest possible sequence; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8357 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8358 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8359 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8360 a single character class followed by '<code>?</code>', |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8361 which matches 0 or 1 occurrence of a character in the class; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8362 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8363 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8364 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8365 <code>%<em>n</em></code>, for <em>n</em> between 1 and 9; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8366 such item matches a substring equal to the <em>n</em>-th captured string |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8367 (see below); |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8368 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8369 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8370 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8371 <code>%b<em>xy</em></code>, where <em>x</em> and <em>y</em> are two distinct characters; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8372 such item matches strings that start with <em>x</em>, end with <em>y</em>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8373 and where the <em>x</em> and <em>y</em> are <em>balanced</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8374 This means that, if one reads the string from left to right, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8375 counting <em>+1</em> for an <em>x</em> and <em>-1</em> for a <em>y</em>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8376 the ending <em>y</em> is the first <em>y</em> where the count reaches 0. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8377 For instance, the item <code>%b()</code> matches expressions with |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8378 balanced parentheses. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8379 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8380 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8381 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8382 <code>%f[<em>set</em>]</code>, a <em>frontier pattern</em>; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8383 such item matches an empty string at any position such that |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8384 the next character belongs to <em>set</em> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8385 and the previous character does not belong to <em>set</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8386 The set <em>set</em> is interpreted as previously described. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8387 The beginning and the end of the subject are handled as if |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8388 they were the character '<code>\0</code>'. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8389 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8390 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8391 </ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8392 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8393 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8394 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8395 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8396 <h4>Pattern:</h4><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8397 A <em>pattern</em> is a sequence of pattern items. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8398 A caret '<code>^</code>' at the beginning of a pattern anchors the match at the |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8399 beginning of the subject string. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8400 A '<code>$</code>' at the end of a pattern anchors the match at the |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8401 end of the subject string. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8402 At other positions, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8403 '<code>^</code>' and '<code>$</code>' have no special meaning and represent themselves. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8404 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8405 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8406 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8407 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8408 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8409 <h4>Captures:</h4><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8410 A pattern can contain sub-patterns enclosed in parentheses; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8411 they describe <em>captures</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8412 When a match succeeds, the substrings of the subject string |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8413 that match captures are stored (<em>captured</em>) for future use. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8414 Captures are numbered according to their left parentheses. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8415 For instance, in the pattern <code>"(a*(.)%w(%s*))"</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8416 the part of the string matching <code>"a*(.)%w(%s*)"</code> is |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8417 stored as the first capture (and therefore has number 1); |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8418 the character matching "<code>.</code>" is captured with number 2, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8419 and the part matching "<code>%s*</code>" has number 3. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8420 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8421 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8422 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8423 As a special case, the empty capture <code>()</code> captures |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8424 the current string position (a number). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8425 For instance, if we apply the pattern <code>"()aa()"</code> on the |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8426 string <code>"flaaap"</code>, there will be two captures: 3 and 5. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8427 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8428 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8429 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8430 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8431 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8432 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8433 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8434 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8435 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8436 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8437 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8438 <h2>6.5 – <a name="6.5">Table Manipulation</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8439 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8440 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8441 This library provides generic functions for table manipulation. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8442 It provides all its functions inside the table <a name="pdf-table"><code>table</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8443 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8444 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8445 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8446 Remember that, whenever an operation needs the length of a table, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8447 the table should be a proper sequence |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8448 or have a <code>__len</code> metamethod (see <a href="#3.4.6">§3.4.6</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8449 All functions ignore non-numeric keys |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8450 in tables given as arguments. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8451 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8452 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8453 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8454 For performance reasons, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8455 all table accesses (get/set) performed by these functions are raw. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8456 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8457 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8458 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8459 <hr><h3><a name="pdf-table.concat"><code>table.concat (list [, sep [, i [, j]]])</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8460 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8461 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8462 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8463 Given a list where all elements are strings or numbers, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8464 returns the string <code>list[i]..sep..list[i+1] ··· sep..list[j]</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8465 The default value for <code>sep</code> is the empty string, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8466 the default for <code>i</code> is 1, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8467 and the default for <code>j</code> is <code>#list</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8468 If <code>i</code> is greater than <code>j</code>, returns the empty string. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8469 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8470 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8471 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8472 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8473 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8474 <hr><h3><a name="pdf-table.insert"><code>table.insert (list, [pos,] value)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8475 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8476 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8477 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8478 Inserts element <code>value</code> at position <code>pos</code> in <code>list</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8479 shifting up the elements |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8480 <code>list[pos], list[pos+1], ···, list[#list]</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8481 The default value for <code>pos</code> is <code>#list+1</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8482 so that a call <code>table.insert(t,x)</code> inserts <code>x</code> at the end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8483 of list <code>t</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8484 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8485 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8486 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8487 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8488 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8489 <hr><h3><a name="pdf-table.pack"><code>table.pack (···)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8490 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8491 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8492 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8493 Returns a new table with all parameters stored into keys 1, 2, etc. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8494 and with a field "<code>n</code>" with the total number of parameters. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8495 Note that the resulting table may not be a sequence. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8496 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8497 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8498 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8499 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8500 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8501 <hr><h3><a name="pdf-table.remove"><code>table.remove (list [, pos])</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8502 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8503 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8504 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8505 Removes from <code>list</code> the element at position <code>pos</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8506 returning the value of the removed element. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8507 When <code>pos</code> is an integer between 1 and <code>#list</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8508 it shifts down the elements |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8509 <code>list[pos+1], list[pos+2], ···, list[#list]</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8510 and erases element <code>list[#list]</code>; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8511 The index <code>pos</code> can also be 0 when <code>#list</code> is 0, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8512 or <code>#list + 1</code>; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8513 in those cases, the function erases the element <code>list[pos]</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8514 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8515 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8516 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8517 The default value for <code>pos</code> is <code>#list</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8518 so that a call <code>table.remove(t)</code> removes the last element |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8519 of list <code>t</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8520 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8521 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8522 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8523 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8524 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8525 <hr><h3><a name="pdf-table.sort"><code>table.sort (list [, comp])</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8526 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8527 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8528 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8529 Sorts list elements in a given order, <em>in-place</em>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8530 from <code>list[1]</code> to <code>list[#list]</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8531 If <code>comp</code> is given, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8532 then it must be a function that receives two list elements |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8533 and returns true when the first element must come |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8534 before the second in the final order |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8535 (so that <code>not comp(list[i+1],list[i])</code> will be true after the sort). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8536 If <code>comp</code> is not given, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8537 then the standard Lua operator <code><</code> is used instead. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8538 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8539 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8540 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8541 The sort algorithm is not stable; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8542 that is, elements considered equal by the given order |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8543 may have their relative positions changed by the sort. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8544 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8545 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8546 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8547 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8548 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8549 <hr><h3><a name="pdf-table.unpack"><code>table.unpack (list [, i [, j]])</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8550 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8551 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8552 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8553 Returns the elements from the given table. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8554 This function is equivalent to |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8555 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8556 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8557 return list[i], list[i+1], ···, list[j] |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8558 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8559 By default, <code>i</code> is 1 and <code>j</code> is <code>#list</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8560 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8561 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8562 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8563 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8564 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8565 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8566 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8567 <h2>6.6 – <a name="6.6">Mathematical Functions</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8568 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8569 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8570 This library is an interface to the standard C math library. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8571 It provides all its functions inside the table <a name="pdf-math"><code>math</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8572 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8573 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8574 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8575 <hr><h3><a name="pdf-math.abs"><code>math.abs (x)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8576 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8577 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8578 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8579 Returns the absolute value of <code>x</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8580 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8581 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8582 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8583 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8584 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8585 <hr><h3><a name="pdf-math.acos"><code>math.acos (x)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8586 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8587 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8588 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8589 Returns the arc cosine of <code>x</code> (in radians). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8590 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8591 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8592 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8593 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8594 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8595 <hr><h3><a name="pdf-math.asin"><code>math.asin (x)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8596 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8597 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8598 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8599 Returns the arc sine of <code>x</code> (in radians). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8600 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8601 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8602 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8603 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8604 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8605 <hr><h3><a name="pdf-math.atan"><code>math.atan (x)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8606 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8607 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8608 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8609 Returns the arc tangent of <code>x</code> (in radians). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8610 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8611 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8612 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8613 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8614 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8615 <hr><h3><a name="pdf-math.atan2"><code>math.atan2 (y, x)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8616 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8617 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8618 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8619 Returns the arc tangent of <code>y/x</code> (in radians), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8620 but uses the signs of both parameters to find the |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8621 quadrant of the result. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8622 (It also handles correctly the case of <code>x</code> being zero.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8623 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8624 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8625 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8626 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8627 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8628 <hr><h3><a name="pdf-math.ceil"><code>math.ceil (x)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8629 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8630 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8631 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8632 Returns the smallest integer larger than or equal to <code>x</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8633 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8634 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8635 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8636 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8637 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8638 <hr><h3><a name="pdf-math.cos"><code>math.cos (x)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8639 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8640 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8641 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8642 Returns the cosine of <code>x</code> (assumed to be in radians). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8643 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8644 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8645 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8646 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8647 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8648 <hr><h3><a name="pdf-math.cosh"><code>math.cosh (x)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8649 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8650 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8651 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8652 Returns the hyperbolic cosine of <code>x</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8653 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8654 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8655 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8656 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8657 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8658 <hr><h3><a name="pdf-math.deg"><code>math.deg (x)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8659 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8660 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8661 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8662 Returns the angle <code>x</code> (given in radians) in degrees. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8663 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8664 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8665 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8666 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8667 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8668 <hr><h3><a name="pdf-math.exp"><code>math.exp (x)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8669 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8670 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8671 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8672 Returns the value <em>e<sup>x</sup></em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8673 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8674 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8675 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8676 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8677 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8678 <hr><h3><a name="pdf-math.floor"><code>math.floor (x)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8679 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8680 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8681 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8682 Returns the largest integer smaller than or equal to <code>x</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8683 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8684 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8685 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8686 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8687 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8688 <hr><h3><a name="pdf-math.fmod"><code>math.fmod (x, y)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8689 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8690 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8691 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8692 Returns the remainder of the division of <code>x</code> by <code>y</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8693 that rounds the quotient towards zero. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8694 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8695 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8696 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8697 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8698 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8699 <hr><h3><a name="pdf-math.frexp"><code>math.frexp (x)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8700 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8701 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8702 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8703 Returns <code>m</code> and <code>e</code> such that <em>x = m2<sup>e</sup></em>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8704 <code>e</code> is an integer and the absolute value of <code>m</code> is |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8705 in the range <em>[0.5, 1)</em> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8706 (or zero when <code>x</code> is zero). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8707 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8708 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8709 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8710 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8711 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8712 <hr><h3><a name="pdf-math.huge"><code>math.huge</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8713 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8714 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8715 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8716 The value <code>HUGE_VAL</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8717 a value larger than or equal to any other numerical value. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8718 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8719 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8720 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8721 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8722 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8723 <hr><h3><a name="pdf-math.ldexp"><code>math.ldexp (m, e)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8724 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8725 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8726 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8727 Returns <em>m2<sup>e</sup></em> (<code>e</code> should be an integer). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8728 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8729 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8730 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8731 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8732 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8733 <hr><h3><a name="pdf-math.log"><code>math.log (x [, base])</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8734 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8735 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8736 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8737 Returns the logarithm of <code>x</code> in the given base. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8738 The default for <code>base</code> is <em>e</em> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8739 (so that the function returns the natural logarithm of <code>x</code>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8740 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8741 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8742 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8743 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8744 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8745 <hr><h3><a name="pdf-math.max"><code>math.max (x, ···)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8746 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8747 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8748 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8749 Returns the maximum value among its arguments. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8750 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8751 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8752 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8753 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8754 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8755 <hr><h3><a name="pdf-math.min"><code>math.min (x, ···)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8756 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8757 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8758 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8759 Returns the minimum value among its arguments. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8760 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8761 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8762 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8763 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8764 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8765 <hr><h3><a name="pdf-math.modf"><code>math.modf (x)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8766 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8767 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8768 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8769 Returns two numbers, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8770 the integral part of <code>x</code> and the fractional part of <code>x</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8771 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8772 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8773 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8774 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8775 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8776 <hr><h3><a name="pdf-math.pi"><code>math.pi</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8777 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8778 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8779 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8780 The value of <em>π</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8781 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8782 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8783 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8784 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8785 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8786 <hr><h3><a name="pdf-math.pow"><code>math.pow (x, y)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8787 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8788 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8789 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8790 Returns <em>x<sup>y</sup></em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8791 (You can also use the expression <code>x^y</code> to compute this value.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8792 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8793 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8794 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8795 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8796 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8797 <hr><h3><a name="pdf-math.rad"><code>math.rad (x)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8798 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8799 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8800 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8801 Returns the angle <code>x</code> (given in degrees) in radians. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8802 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8803 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8804 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8805 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8806 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8807 <hr><h3><a name="pdf-math.random"><code>math.random ([m [, n]])</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8808 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8809 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8810 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8811 This function is an interface to the simple |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8812 pseudo-random generator function <code>rand</code> provided by Standard C. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8813 (No guarantees can be given for its statistical properties.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8814 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8815 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8816 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8817 When called without arguments, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8818 returns a uniform pseudo-random real number |
242
b5a926c481a5
Handle first h1 tag differently.
hugo.tech@gmail.com <hugo.tech@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
241
diff
changeset
|
8819 in the range <em>[0,1)</em>. |
239
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8820 When called with an integer number <code>m</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8821 <code>math.random</code> returns |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8822 a uniform pseudo-random integer in the range <em>[1, m]</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8823 When called with two integer numbers <code>m</code> and <code>n</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8824 <code>math.random</code> returns a uniform pseudo-random |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8825 integer in the range <em>[m, n]</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8826 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8827 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8828 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8829 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8830 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8831 <hr><h3><a name="pdf-math.randomseed"><code>math.randomseed (x)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8832 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8833 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8834 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8835 Sets <code>x</code> as the "seed" |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8836 for the pseudo-random generator: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8837 equal seeds produce equal sequences of numbers. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8838 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8839 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8840 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8841 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8842 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8843 <hr><h3><a name="pdf-math.sin"><code>math.sin (x)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8844 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8845 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8846 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8847 Returns the sine of <code>x</code> (assumed to be in radians). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8848 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8849 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8850 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8851 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8852 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8853 <hr><h3><a name="pdf-math.sinh"><code>math.sinh (x)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8854 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8855 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8856 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8857 Returns the hyperbolic sine of <code>x</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8858 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8859 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8860 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8861 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8862 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8863 <hr><h3><a name="pdf-math.sqrt"><code>math.sqrt (x)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8864 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8865 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8866 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8867 Returns the square root of <code>x</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8868 (You can also use the expression <code>x^0.5</code> to compute this value.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8869 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8870 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8871 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8872 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8873 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8874 <hr><h3><a name="pdf-math.tan"><code>math.tan (x)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8875 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8876 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8877 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8878 Returns the tangent of <code>x</code> (assumed to be in radians). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8879 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8880 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8881 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8882 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8883 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8884 <hr><h3><a name="pdf-math.tanh"><code>math.tanh (x)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8885 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8886 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8887 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8888 Returns the hyperbolic tangent of <code>x</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8889 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8890 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8891 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8892 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8893 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8894 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8895 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8896 <h2>6.7 – <a name="6.7">Bitwise Operations</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8897 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8898 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8899 This library provides bitwise operations. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8900 It provides all its functions inside the table <a name="pdf-bit32"><code>bit32</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8901 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8902 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8903 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8904 Unless otherwise stated, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8905 all functions accept numeric arguments in the range |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8906 <em>(-2<sup>51</sup>,+2<sup>51</sup>)</em>; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8907 each argument is normalized to |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8908 the remainder of its division by <em>2<sup>32</sup></em> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8909 and truncated to an integer (in some unspecified way), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8910 so that its final value falls in the range <em>[0,2<sup>32</sup> - 1]</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8911 Similarly, all results are in the range <em>[0,2<sup>32</sup> - 1]</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8912 Note that <code>bit32.bnot(0)</code> is <code>0xFFFFFFFF</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8913 which is different from <code>-1</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8914 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8915 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8916 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8917 <hr><h3><a name="pdf-bit32.arshift"><code>bit32.arshift (x, disp)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8918 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8919 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8920 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8921 Returns the number <code>x</code> shifted <code>disp</code> bits to the right. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8922 The number <code>disp</code> may be any representable integer. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8923 Negative displacements shift to the left. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8924 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8925 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8926 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8927 This shift operation is what is called arithmetic shift. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8928 Vacant bits on the left are filled |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8929 with copies of the higher bit of <code>x</code>; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8930 vacant bits on the right are filled with zeros. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8931 In particular, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8932 displacements with absolute values higher than 31 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8933 result in zero or <code>0xFFFFFFFF</code> (all original bits are shifted out). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8934 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8935 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8936 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8937 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8938 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8939 <hr><h3><a name="pdf-bit32.band"><code>bit32.band (···)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8940 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8941 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8942 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8943 Returns the bitwise <em>and</em> of its operands. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8944 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8945 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8946 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8947 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8948 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8949 <hr><h3><a name="pdf-bit32.bnot"><code>bit32.bnot (x)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8950 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8951 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8952 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8953 Returns the bitwise negation of <code>x</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8954 For any integer <code>x</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8955 the following identity holds: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8956 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8957 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8958 assert(bit32.bnot(x) == (-1 - x) % 2^32) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8959 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8960 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8961 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8962 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8963 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8964 <hr><h3><a name="pdf-bit32.bor"><code>bit32.bor (···)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8965 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8966 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8967 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8968 Returns the bitwise <em>or</em> of its operands. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8969 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8970 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8971 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8972 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8973 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8974 <hr><h3><a name="pdf-bit32.btest"><code>bit32.btest (···)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8975 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8976 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8977 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8978 Returns a boolean signaling |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8979 whether the bitwise <em>and</em> of its operands is different from zero. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8980 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8981 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8982 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8983 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8984 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8985 <hr><h3><a name="pdf-bit32.bxor"><code>bit32.bxor (···)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8986 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8987 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8988 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8989 Returns the bitwise <em>exclusive or</em> of its operands. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8990 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8991 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8992 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8993 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8994 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8995 <hr><h3><a name="pdf-bit32.extract"><code>bit32.extract (n, field [, width])</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8996 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8997 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8998 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8999 Returns the unsigned number formed by the bits |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9000 <code>field</code> to <code>field + width - 1</code> from <code>n</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9001 Bits are numbered from 0 (least significant) to 31 (most significant). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9002 All accessed bits must be in the range <em>[0, 31]</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9003 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9004 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9005 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9006 The default for <code>width</code> is 1. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9007 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9008 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9009 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9010 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9011 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9012 <hr><h3><a name="pdf-bit32.replace"><code>bit32.replace (n, v, field [, width])</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9013 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9014 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9015 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9016 Returns a copy of <code>n</code> with |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9017 the bits <code>field</code> to <code>field + width - 1</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9018 replaced by the value <code>v</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9019 See <a href="#pdf-bit32.extract"><code>bit32.extract</code></a> for details about <code>field</code> and <code>width</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9020 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9021 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9022 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9023 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9024 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9025 <hr><h3><a name="pdf-bit32.lrotate"><code>bit32.lrotate (x, disp)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9026 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9027 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9028 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9029 Returns the number <code>x</code> rotated <code>disp</code> bits to the left. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9030 The number <code>disp</code> may be any representable integer. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9031 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9032 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9033 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9034 For any valid displacement, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9035 the following identity holds: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9036 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9037 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9038 assert(bit32.lrotate(x, disp) == bit32.lrotate(x, disp % 32)) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9039 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9040 In particular, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9041 negative displacements rotate to the right. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9042 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9043 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9044 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9045 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9046 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9047 <hr><h3><a name="pdf-bit32.lshift"><code>bit32.lshift (x, disp)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9048 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9049 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9050 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9051 Returns the number <code>x</code> shifted <code>disp</code> bits to the left. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9052 The number <code>disp</code> may be any representable integer. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9053 Negative displacements shift to the right. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9054 In any direction, vacant bits are filled with zeros. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9055 In particular, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9056 displacements with absolute values higher than 31 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9057 result in zero (all bits are shifted out). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9058 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9059 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9060 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9061 For positive displacements, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9062 the following equality holds: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9063 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9064 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9065 assert(bit32.lshift(b, disp) == (b * 2^disp) % 2^32) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9066 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9067 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9068 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9069 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9070 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9071 <hr><h3><a name="pdf-bit32.rrotate"><code>bit32.rrotate (x, disp)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9072 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9073 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9074 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9075 Returns the number <code>x</code> rotated <code>disp</code> bits to the right. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9076 The number <code>disp</code> may be any representable integer. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9077 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9078 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9079 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9080 For any valid displacement, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9081 the following identity holds: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9082 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9083 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9084 assert(bit32.rrotate(x, disp) == bit32.rrotate(x, disp % 32)) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9085 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9086 In particular, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9087 negative displacements rotate to the left. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9088 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9089 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9090 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9091 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9092 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9093 <hr><h3><a name="pdf-bit32.rshift"><code>bit32.rshift (x, disp)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9094 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9095 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9096 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9097 Returns the number <code>x</code> shifted <code>disp</code> bits to the right. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9098 The number <code>disp</code> may be any representable integer. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9099 Negative displacements shift to the left. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9100 In any direction, vacant bits are filled with zeros. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9101 In particular, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9102 displacements with absolute values higher than 31 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9103 result in zero (all bits are shifted out). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9104 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9105 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9106 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9107 For positive displacements, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9108 the following equality holds: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9109 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9110 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9111 assert(bit32.rshift(b, disp) == math.floor(b % 2^32 / 2^disp)) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9112 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9113 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9114 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9115 This shift operation is what is called logical shift. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9116 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9117 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9118 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9119 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9120 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9121 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9122 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9123 <h2>6.8 – <a name="6.8">Input and Output Facilities</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9124 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9125 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9126 The I/O library provides two different styles for file manipulation. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9127 The first one uses implicit file descriptors; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9128 that is, there are operations to set a default input file and a |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9129 default output file, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9130 and all input/output operations are over these default files. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9131 The second style uses explicit file descriptors. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9132 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9133 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9134 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9135 When using implicit file descriptors, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9136 all operations are supplied by table <a name="pdf-io"><code>io</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9137 When using explicit file descriptors, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9138 the operation <a href="#pdf-io.open"><code>io.open</code></a> returns a file descriptor |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9139 and then all operations are supplied as methods of the file descriptor. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9140 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9141 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9142 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9143 The table <code>io</code> also provides |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9144 three predefined file descriptors with their usual meanings from C: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9145 <a name="pdf-io.stdin"><code>io.stdin</code></a>, <a name="pdf-io.stdout"><code>io.stdout</code></a>, and <a name="pdf-io.stderr"><code>io.stderr</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9146 The I/O library never closes these files. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9147 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9148 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9149 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9150 Unless otherwise stated, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9151 all I/O functions return <b>nil</b> on failure |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9152 (plus an error message as a second result and |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9153 a system-dependent error code as a third result) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9154 and some value different from <b>nil</b> on success. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9155 On non-Posix systems, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9156 the computation of the error message and error code |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9157 in case of errors |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9158 may be not thread safe, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9159 because they rely on the global C variable <code>errno</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9160 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9161 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9162 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9163 <hr><h3><a name="pdf-io.close"><code>io.close ([file])</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9164 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9165 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9166 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9167 Equivalent to <code>file:close()</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9168 Without a <code>file</code>, closes the default output file. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9169 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9170 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9171 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9172 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9173 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9174 <hr><h3><a name="pdf-io.flush"><code>io.flush ()</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9175 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9176 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9177 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9178 Equivalent to <code>io.output():flush()</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9179 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9180 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9181 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9182 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9183 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9184 <hr><h3><a name="pdf-io.input"><code>io.input ([file])</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9185 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9186 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9187 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9188 When called with a file name, it opens the named file (in text mode), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9189 and sets its handle as the default input file. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9190 When called with a file handle, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9191 it simply sets this file handle as the default input file. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9192 When called without parameters, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9193 it returns the current default input file. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9194 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9195 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9196 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9197 In case of errors this function raises the error, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9198 instead of returning an error code. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9199 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9200 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9201 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9202 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9203 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9204 <hr><h3><a name="pdf-io.lines"><code>io.lines ([filename ···])</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9205 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9206 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9207 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9208 Opens the given file name in read mode |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9209 and returns an iterator function that |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9210 works like <code>file:lines(···)</code> over the opened file. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9211 When the iterator function detects the end of file, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9212 it returns <b>nil</b> (to finish the loop) and automatically closes the file. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9213 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9214 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9215 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9216 The call <code>io.lines()</code> (with no file name) is equivalent |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9217 to <code>io.input():lines()</code>; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9218 that is, it iterates over the lines of the default input file. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9219 In this case it does not close the file when the loop ends. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9220 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9221 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9222 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9223 In case of errors this function raises the error, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9224 instead of returning an error code. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9225 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9226 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9227 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9228 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9229 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9230 <hr><h3><a name="pdf-io.open"><code>io.open (filename [, mode])</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9231 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9232 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9233 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9234 This function opens a file, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9235 in the mode specified in the string <code>mode</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9236 It returns a new file handle, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9237 or, in case of errors, <b>nil</b> plus an error message. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9238 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9239 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9240 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9241 The <code>mode</code> string can be any of the following: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9242 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9243 <ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9244 <li><b>"<code>r</code>": </b> read mode (the default);</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9245 <li><b>"<code>w</code>": </b> write mode;</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9246 <li><b>"<code>a</code>": </b> append mode;</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9247 <li><b>"<code>r+</code>": </b> update mode, all previous data is preserved;</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9248 <li><b>"<code>w+</code>": </b> update mode, all previous data is erased;</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9249 <li><b>"<code>a+</code>": </b> append update mode, previous data is preserved, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9250 writing is only allowed at the end of file.</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9251 </ul><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9252 The <code>mode</code> string can also have a '<code>b</code>' at the end, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9253 which is needed in some systems to open the file in binary mode. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9254 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9255 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9256 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9257 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9258 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9259 <hr><h3><a name="pdf-io.output"><code>io.output ([file])</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9260 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9261 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9262 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9263 Similar to <a href="#pdf-io.input"><code>io.input</code></a>, but operates over the default output file. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9264 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9265 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9266 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9267 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9268 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9269 <hr><h3><a name="pdf-io.popen"><code>io.popen (prog [, mode])</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9270 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9271 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9272 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9273 This function is system dependent and is not available |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9274 on all platforms. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9275 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9276 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9277 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9278 Starts program <code>prog</code> in a separated process and returns |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9279 a file handle that you can use to read data from this program |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9280 (if <code>mode</code> is <code>"r"</code>, the default) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9281 or to write data to this program |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9282 (if <code>mode</code> is <code>"w"</code>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9283 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9284 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9285 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9286 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9287 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9288 <hr><h3><a name="pdf-io.read"><code>io.read (···)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9289 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9290 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9291 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9292 Equivalent to <code>io.input():read(···)</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9293 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9294 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9295 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9296 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9297 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9298 <hr><h3><a name="pdf-io.tmpfile"><code>io.tmpfile ()</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9299 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9300 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9301 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9302 Returns a handle for a temporary file. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9303 This file is opened in update mode |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9304 and it is automatically removed when the program ends. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9305 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9306 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9307 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9308 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9309 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9310 <hr><h3><a name="pdf-io.type"><code>io.type (obj)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9311 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9312 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9313 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9314 Checks whether <code>obj</code> is a valid file handle. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9315 Returns the string <code>"file"</code> if <code>obj</code> is an open file handle, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9316 <code>"closed file"</code> if <code>obj</code> is a closed file handle, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9317 or <b>nil</b> if <code>obj</code> is not a file handle. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9318 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9319 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9320 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9321 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9322 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9323 <hr><h3><a name="pdf-io.write"><code>io.write (···)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9324 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9325 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9326 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9327 Equivalent to <code>io.output():write(···)</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9328 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9329 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9330 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9331 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9332 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9333 <hr><h3><a name="pdf-file:close"><code>file:close ()</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9334 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9335 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9336 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9337 Closes <code>file</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9338 Note that files are automatically closed when |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9339 their handles are garbage collected, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9340 but that takes an unpredictable amount of time to happen. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9341 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9342 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9343 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9344 When closing a file handle created with <a href="#pdf-io.popen"><code>io.popen</code></a>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9345 <a href="#pdf-file:close"><code>file:close</code></a> returns the same values |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9346 returned by <a href="#pdf-os.execute"><code>os.execute</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9347 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9348 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9349 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9350 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9351 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9352 <hr><h3><a name="pdf-file:flush"><code>file:flush ()</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9353 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9354 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9355 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9356 Saves any written data to <code>file</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9357 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9358 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9359 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9360 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9361 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9362 <hr><h3><a name="pdf-file:lines"><code>file:lines (···)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9363 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9364 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9365 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9366 Returns an iterator function that, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9367 each time it is called, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9368 reads the file according to the given formats. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9369 When no format is given, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9370 uses "*l" as a default. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9371 As an example, the construction |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9372 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9373 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9374 for c in file:lines(1) do <em>body</em> end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9375 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9376 will iterate over all characters of the file, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9377 starting at the current position. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9378 Unlike <a href="#pdf-io.lines"><code>io.lines</code></a>, this function does not close the file |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9379 when the loop ends. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9380 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9381 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9382 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9383 In case of errors this function raises the error, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9384 instead of returning an error code. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9385 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9386 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9387 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9388 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9389 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9390 <hr><h3><a name="pdf-file:read"><code>file:read (···)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9391 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9392 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9393 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9394 Reads the file <code>file</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9395 according to the given formats, which specify what to read. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9396 For each format, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9397 the function returns a string (or a number) with the characters read, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9398 or <b>nil</b> if it cannot read data with the specified format. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9399 When called without formats, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9400 it uses a default format that reads the next line |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9401 (see below). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9402 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9403 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9404 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9405 The available formats are |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9406 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9407 <ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9408 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9409 <li><b>"<code>*n</code>": </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9410 reads a number; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9411 this is the only format that returns a number instead of a string. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9412 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9413 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9414 <li><b>"<code>*a</code>": </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9415 reads the whole file, starting at the current position. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9416 On end of file, it returns the empty string. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9417 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9418 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9419 <li><b>"<code>*l</code>": </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9420 reads the next line skipping the end of line, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9421 returning <b>nil</b> on end of file. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9422 This is the default format. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9423 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9424 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9425 <li><b>"<code>*L</code>": </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9426 reads the next line keeping the end of line (if present), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9427 returning <b>nil</b> on end of file. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9428 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9429 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9430 <li><b><em>number</em>: </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9431 reads a string with up to this number of bytes, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9432 returning <b>nil</b> on end of file. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9433 If number is zero, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9434 it reads nothing and returns an empty string, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9435 or <b>nil</b> on end of file. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9436 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9437 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9438 </ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9439 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9440 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9441 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9442 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9443 <hr><h3><a name="pdf-file:seek"><code>file:seek ([whence [, offset]])</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9444 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9445 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9446 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9447 Sets and gets the file position, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9448 measured from the beginning of the file, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9449 to the position given by <code>offset</code> plus a base |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9450 specified by the string <code>whence</code>, as follows: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9451 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9452 <ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9453 <li><b>"<code>set</code>": </b> base is position 0 (beginning of the file);</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9454 <li><b>"<code>cur</code>": </b> base is current position;</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9455 <li><b>"<code>end</code>": </b> base is end of file;</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9456 </ul><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9457 In case of success, <code>seek</code> returns the final file position, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9458 measured in bytes from the beginning of the file. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9459 If <code>seek</code> fails, it returns <b>nil</b>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9460 plus a string describing the error. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9461 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9462 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9463 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9464 The default value for <code>whence</code> is <code>"cur"</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9465 and for <code>offset</code> is 0. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9466 Therefore, the call <code>file:seek()</code> returns the current |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9467 file position, without changing it; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9468 the call <code>file:seek("set")</code> sets the position to the |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9469 beginning of the file (and returns 0); |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9470 and the call <code>file:seek("end")</code> sets the position to the |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9471 end of the file, and returns its size. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9472 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9473 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9474 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9475 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9476 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9477 <hr><h3><a name="pdf-file:setvbuf"><code>file:setvbuf (mode [, size])</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9478 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9479 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9480 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9481 Sets the buffering mode for an output file. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9482 There are three available modes: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9483 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9484 <ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9485 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9486 <li><b>"<code>no</code>": </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9487 no buffering; the result of any output operation appears immediately. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9488 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9489 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9490 <li><b>"<code>full</code>": </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9491 full buffering; output operation is performed only |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9492 when the buffer is full or when |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9493 you explicitly <code>flush</code> the file (see <a href="#pdf-io.flush"><code>io.flush</code></a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9494 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9495 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9496 <li><b>"<code>line</code>": </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9497 line buffering; output is buffered until a newline is output |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9498 or there is any input from some special files |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9499 (such as a terminal device). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9500 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9501 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9502 </ul><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9503 For the last two cases, <code>size</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9504 specifies the size of the buffer, in bytes. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9505 The default is an appropriate size. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9506 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9507 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9508 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9509 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9510 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9511 <hr><h3><a name="pdf-file:write"><code>file:write (···)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9512 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9513 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9514 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9515 Writes the value of each of its arguments to <code>file</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9516 The arguments must be strings or numbers. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9517 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9518 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9519 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9520 In case of success, this function returns <code>file</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9521 Otherwise it returns <b>nil</b> plus a string describing the error. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9522 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9523 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9524 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9525 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9526 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9527 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9528 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9529 <h2>6.9 – <a name="6.9">Operating System Facilities</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9530 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9531 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9532 This library is implemented through table <a name="pdf-os"><code>os</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9533 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9534 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9535 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9536 <hr><h3><a name="pdf-os.clock"><code>os.clock ()</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9537 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9538 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9539 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9540 Returns an approximation of the amount in seconds of CPU time |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9541 used by the program. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9542 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9543 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9544 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9545 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9546 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9547 <hr><h3><a name="pdf-os.date"><code>os.date ([format [, time]])</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9548 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9549 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9550 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9551 Returns a string or a table containing date and time, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9552 formatted according to the given string <code>format</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9553 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9554 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9555 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9556 If the <code>time</code> argument is present, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9557 this is the time to be formatted |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9558 (see the <a href="#pdf-os.time"><code>os.time</code></a> function for a description of this value). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9559 Otherwise, <code>date</code> formats the current time. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9560 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9561 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9562 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9563 If <code>format</code> starts with '<code>!</code>', |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9564 then the date is formatted in Coordinated Universal Time. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9565 After this optional character, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9566 if <code>format</code> is the string "<code>*t</code>", |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9567 then <code>date</code> returns a table with the following fields: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9568 <code>year</code> (four digits), <code>month</code> (1–12), <code>day</code> (1–31), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9569 <code>hour</code> (0–23), <code>min</code> (0–59), <code>sec</code> (0–61), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9570 <code>wday</code> (weekday, Sunday is 1), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9571 <code>yday</code> (day of the year), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9572 and <code>isdst</code> (daylight saving flag, a boolean). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9573 This last field may be absent |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9574 if the information is not available. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9575 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9576 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9577 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9578 If <code>format</code> is not "<code>*t</code>", |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9579 then <code>date</code> returns the date as a string, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9580 formatted according to the same rules as the ANSI C function <code>strftime</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9581 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9582 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9583 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9584 When called without arguments, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9585 <code>date</code> returns a reasonable date and time representation that depends on |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9586 the host system and on the current locale |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9587 (that is, <code>os.date()</code> is equivalent to <code>os.date("%c")</code>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9588 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9589 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9590 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9591 On non-Posix systems, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9592 this function may be not thread safe |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9593 because of its reliance on C function <code>gmtime</code> and C function <code>localtime</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9594 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9595 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9596 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9597 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9598 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9599 <hr><h3><a name="pdf-os.difftime"><code>os.difftime (t2, t1)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9600 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9601 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9602 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9603 Returns the number of seconds from time <code>t1</code> to time <code>t2</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9604 In POSIX, Windows, and some other systems, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9605 this value is exactly <code>t2</code><em>-</em><code>t1</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9606 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9607 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9608 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9609 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9610 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9611 <hr><h3><a name="pdf-os.execute"><code>os.execute ([command])</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9612 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9613 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9614 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9615 This function is equivalent to the ANSI C function <code>system</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9616 It passes <code>command</code> to be executed by an operating system shell. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9617 Its first result is <b>true</b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9618 if the command terminated successfully, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9619 or <b>nil</b> otherwise. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9620 After this first result |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9621 the function returns a string and a number, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9622 as follows: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9623 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9624 <ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9625 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9626 <li><b>"<code>exit</code>": </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9627 the command terminated normally; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9628 the following number is the exit status of the command. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9629 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9630 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9631 <li><b>"<code>signal</code>": </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9632 the command was terminated by a signal; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9633 the following number is the signal that terminated the command. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9634 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9635 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9636 </ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9637 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9638 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9639 When called without a <code>command</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9640 <code>os.execute</code> returns a boolean that is true if a shell is available. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9641 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9642 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9643 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9644 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9645 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9646 <hr><h3><a name="pdf-os.exit"><code>os.exit ([code [, close])</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9647 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9648 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9649 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9650 Calls the ANSI C function <code>exit</code> to terminate the host program. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9651 If <code>code</code> is <b>true</b>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9652 the returned status is <code>EXIT_SUCCESS</code>; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9653 if <code>code</code> is <b>false</b>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9654 the returned status is <code>EXIT_FAILURE</code>; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9655 if <code>code</code> is a number, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9656 the returned status is this number. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9657 The default value for <code>code</code> is <b>true</b>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9658 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9659 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9660 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9661 If the optional second argument <code>close</code> is true, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9662 closes the Lua state before exiting. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9663 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9664 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9665 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9666 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9667 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9668 <hr><h3><a name="pdf-os.getenv"><code>os.getenv (varname)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9669 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9670 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9671 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9672 Returns the value of the process environment variable <code>varname</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9673 or <b>nil</b> if the variable is not defined. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9674 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9675 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9676 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9677 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9678 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9679 <hr><h3><a name="pdf-os.remove"><code>os.remove (filename)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9680 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9681 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9682 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9683 Deletes the file (or empty directory, on POSIX systems) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9684 with the given name. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9685 If this function fails, it returns <b>nil</b>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9686 plus a string describing the error and the error code. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9687 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9688 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9689 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9690 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9691 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9692 <hr><h3><a name="pdf-os.rename"><code>os.rename (oldname, newname)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9693 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9694 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9695 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9696 Renames file or directory named <code>oldname</code> to <code>newname</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9697 If this function fails, it returns <b>nil</b>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9698 plus a string describing the error and the error code. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9699 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9700 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9701 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9702 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9703 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9704 <hr><h3><a name="pdf-os.setlocale"><code>os.setlocale (locale [, category])</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9705 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9706 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9707 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9708 Sets the current locale of the program. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9709 <code>locale</code> is a system-dependent string specifying a locale; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9710 <code>category</code> is an optional string describing which category to change: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9711 <code>"all"</code>, <code>"collate"</code>, <code>"ctype"</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9712 <code>"monetary"</code>, <code>"numeric"</code>, or <code>"time"</code>; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9713 the default category is <code>"all"</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9714 The function returns the name of the new locale, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9715 or <b>nil</b> if the request cannot be honored. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9716 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9717 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9718 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9719 If <code>locale</code> is the empty string, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9720 the current locale is set to an implementation-defined native locale. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9721 If <code>locale</code> is the string "<code>C</code>", |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9722 the current locale is set to the standard C locale. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9723 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9724 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9725 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9726 When called with <b>nil</b> as the first argument, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9727 this function only returns the name of the current locale |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9728 for the given category. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9729 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9730 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9731 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9732 This function may be not thread safe |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9733 because of its reliance on C function <code>setlocale</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9734 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9735 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9736 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9737 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9738 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9739 <hr><h3><a name="pdf-os.time"><code>os.time ([table])</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9740 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9741 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9742 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9743 Returns the current time when called without arguments, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9744 or a time representing the date and time specified by the given table. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9745 This table must have fields <code>year</code>, <code>month</code>, and <code>day</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9746 and may have fields |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9747 <code>hour</code> (default is 12), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9748 <code>min</code> (default is 0), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9749 <code>sec</code> (default is 0), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9750 and <code>isdst</code> (default is <b>nil</b>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9751 For a description of these fields, see the <a href="#pdf-os.date"><code>os.date</code></a> function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9752 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9753 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9754 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9755 The returned value is a number, whose meaning depends on your system. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9756 In POSIX, Windows, and some other systems, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9757 this number counts the number |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9758 of seconds since some given start time (the "epoch"). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9759 In other systems, the meaning is not specified, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9760 and the number returned by <code>time</code> can be used only as an argument to |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9761 <a href="#pdf-os.date"><code>os.date</code></a> and <a href="#pdf-os.difftime"><code>os.difftime</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9762 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9763 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9764 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9765 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9766 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9767 <hr><h3><a name="pdf-os.tmpname"><code>os.tmpname ()</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9768 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9769 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9770 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9771 Returns a string with a file name that can |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9772 be used for a temporary file. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9773 The file must be explicitly opened before its use |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9774 and explicitly removed when no longer needed. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9775 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9776 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9777 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9778 On POSIX systems, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9779 this function also creates a file with that name, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9780 to avoid security risks. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9781 (Someone else might create the file with wrong permissions |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9782 in the time between getting the name and creating the file.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9783 You still have to open the file to use it |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9784 and to remove it (even if you do not use it). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9785 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9786 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9787 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9788 When possible, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9789 you may prefer to use <a href="#pdf-io.tmpfile"><code>io.tmpfile</code></a>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9790 which automatically removes the file when the program ends. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9791 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9792 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9793 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9794 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9795 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9796 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9797 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9798 <h2>6.10 – <a name="6.10">The Debug Library</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9799 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9800 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9801 This library provides |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9802 the functionality of the debug interface (<a href="#4.9">§4.9</a>) to Lua programs. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9803 You should exert care when using this library. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9804 Several of its functions |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9805 violate basic assumptions about Lua code |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9806 (e.g., that variables local to a function |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9807 cannot be accessed from outside; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9808 that userdata metatables cannot be changed by Lua code; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9809 that Lua programs do not crash) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9810 and therefore can compromise otherwise secure code. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9811 Moreover, some functions in this library may be slow. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9812 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9813 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9814 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9815 All functions in this library are provided |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9816 inside the <a name="pdf-debug"><code>debug</code></a> table. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9817 All functions that operate over a thread |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9818 have an optional first argument which is the |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9819 thread to operate over. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9820 The default is always the current thread. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9821 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9822 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9823 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9824 <hr><h3><a name="pdf-debug.debug"><code>debug.debug ()</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9825 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9826 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9827 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9828 Enters an interactive mode with the user, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9829 running each string that the user enters. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9830 Using simple commands and other debug facilities, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9831 the user can inspect global and local variables, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9832 change their values, evaluate expressions, and so on. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9833 A line containing only the word <code>cont</code> finishes this function, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9834 so that the caller continues its execution. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9835 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9836 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9837 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9838 Note that commands for <code>debug.debug</code> are not lexically nested |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9839 within any function and so have no direct access to local variables. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9840 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9841 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9842 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9843 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9844 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9845 <hr><h3><a name="pdf-debug.gethook"><code>debug.gethook ([thread])</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9846 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9847 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9848 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9849 Returns the current hook settings of the thread, as three values: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9850 the current hook function, the current hook mask, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9851 and the current hook count |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9852 (as set by the <a href="#pdf-debug.sethook"><code>debug.sethook</code></a> function). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9853 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9854 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9855 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9856 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9857 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9858 <hr><h3><a name="pdf-debug.getinfo"><code>debug.getinfo ([thread,] f [, what])</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9859 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9860 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9861 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9862 Returns a table with information about a function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9863 You can give the function directly |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9864 or you can give a number as the value of <code>f</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9865 which means the function running at level <code>f</code> of the call stack |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9866 of the given thread: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9867 level 0 is the current function (<code>getinfo</code> itself); |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9868 level 1 is the function that called <code>getinfo</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9869 (except for tail calls, which do not count on the stack); |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9870 and so on. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9871 If <code>f</code> is a number larger than the number of active functions, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9872 then <code>getinfo</code> returns <b>nil</b>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9873 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9874 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9875 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9876 The returned table can contain all the fields returned by <a href="#lua_getinfo"><code>lua_getinfo</code></a>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9877 with the string <code>what</code> describing which fields to fill in. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9878 The default for <code>what</code> is to get all information available, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9879 except the table of valid lines. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9880 If present, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9881 the option '<code>f</code>' |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9882 adds a field named <code>func</code> with the function itself. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9883 If present, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9884 the option '<code>L</code>' |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9885 adds a field named <code>activelines</code> with the table of |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9886 valid lines. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9887 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9888 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9889 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9890 For instance, the expression <code>debug.getinfo(1,"n").name</code> returns |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9891 a table with a name for the current function, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9892 if a reasonable name can be found, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9893 and the expression <code>debug.getinfo(print)</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9894 returns a table with all available information |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9895 about the <a href="#pdf-print"><code>print</code></a> function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9896 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9897 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9898 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9899 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9900 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9901 <hr><h3><a name="pdf-debug.getlocal"><code>debug.getlocal ([thread,] f, local)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9902 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9903 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9904 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9905 This function returns the name and the value of the local variable |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9906 with index <code>local</code> of the function at level <code>f</code> of the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9907 This function accesses not only explicit local variables, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9908 but also parameters, temporaries, etc. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9909 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9910 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9911 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9912 The first parameter or local variable has index 1, and so on, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9913 until the last active variable. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9914 Negative indices refer to vararg parameters; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9915 -1 is the first vararg parameter. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9916 The function returns <b>nil</b> if there is no variable with the given index, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9917 and raises an error when called with a level out of range. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9918 (You can call <a href="#pdf-debug.getinfo"><code>debug.getinfo</code></a> to check whether the level is valid.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9919 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9920 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9921 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9922 Variable names starting with '<code>(</code>' (open parenthesis) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9923 represent internal variables |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9924 (loop control variables, temporaries, varargs, and C function locals). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9925 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9926 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9927 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9928 The parameter <code>f</code> may also be a function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9929 In that case, <code>getlocal</code> returns only the name of function parameters. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9930 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9931 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9932 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9933 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9934 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9935 <hr><h3><a name="pdf-debug.getmetatable"><code>debug.getmetatable (value)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9936 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9937 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9938 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9939 Returns the metatable of the given <code>value</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9940 or <b>nil</b> if it does not have a metatable. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9941 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9942 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9943 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9944 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9945 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9946 <hr><h3><a name="pdf-debug.getregistry"><code>debug.getregistry ()</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9947 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9948 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9949 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9950 Returns the registry table (see <a href="#4.5">§4.5</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9951 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9952 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9953 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9954 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9955 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9956 <hr><h3><a name="pdf-debug.getupvalue"><code>debug.getupvalue (f, up)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9957 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9958 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9959 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9960 This function returns the name and the value of the upvalue |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9961 with index <code>up</code> of the function <code>f</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9962 The function returns <b>nil</b> if there is no upvalue with the given index. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9963 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9964 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9965 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9966 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9967 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9968 <hr><h3><a name="pdf-debug.getuservalue"><code>debug.getuservalue (u)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9969 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9970 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9971 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9972 Returns the Lua value associated to <code>u</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9973 If <code>u</code> is not a userdata, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9974 returns <b>nil</b>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9975 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9976 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9977 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9978 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9979 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9980 <hr><h3><a name="pdf-debug.sethook"><code>debug.sethook ([thread,] hook, mask [, count])</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9981 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9982 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9983 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9984 Sets the given function as a hook. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9985 The string <code>mask</code> and the number <code>count</code> describe |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9986 when the hook will be called. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9987 The string mask may have the following characters, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9988 with the given meaning: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9989 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9990 <ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9991 <li><b>'<code>c</code>': </b> the hook is called every time Lua calls a function;</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9992 <li><b>'<code>r</code>': </b> the hook is called every time Lua returns from a function;</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9993 <li><b>'<code>l</code>': </b> the hook is called every time Lua enters a new line of code.</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9994 </ul><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9995 With a <code>count</code> different from zero, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9996 the hook is called after every <code>count</code> instructions. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9997 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9998 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9999 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10000 When called without arguments, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10001 <a href="#pdf-debug.sethook"><code>debug.sethook</code></a> turns off the hook. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10002 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10003 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10004 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10005 When the hook is called, its first parameter is a string |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10006 describing the event that has triggered its call: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10007 <code>"call"</code> (or <code>"tail call"</code>), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10008 <code>"return"</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10009 <code>"line"</code>, and <code>"count"</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10010 For line events, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10011 the hook also gets the new line number as its second parameter. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10012 Inside a hook, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10013 you can call <code>getinfo</code> with level 2 to get more information about |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10014 the running function |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10015 (level 0 is the <code>getinfo</code> function, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10016 and level 1 is the hook function). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10017 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10018 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10019 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10020 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10021 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10022 <hr><h3><a name="pdf-debug.setlocal"><code>debug.setlocal ([thread,] level, local, value)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10023 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10024 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10025 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10026 This function assigns the value <code>value</code> to the local variable |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10027 with index <code>local</code> of the function at level <code>level</code> of the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10028 The function returns <b>nil</b> if there is no local |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10029 variable with the given index, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10030 and raises an error when called with a <code>level</code> out of range. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10031 (You can call <code>getinfo</code> to check whether the level is valid.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10032 Otherwise, it returns the name of the local variable. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10033 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10034 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10035 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10036 See <a href="#pdf-debug.getlocal"><code>debug.getlocal</code></a> for more information about |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10037 variable indices and names. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10038 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10039 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10040 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10041 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10042 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10043 <hr><h3><a name="pdf-debug.setmetatable"><code>debug.setmetatable (value, table)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10044 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10045 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10046 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10047 Sets the metatable for the given <code>value</code> to the given <code>table</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10048 (which can be <b>nil</b>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10049 Returns <code>value</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10050 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10051 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10052 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10053 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10054 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10055 <hr><h3><a name="pdf-debug.setupvalue"><code>debug.setupvalue (f, up, value)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10056 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10057 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10058 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10059 This function assigns the value <code>value</code> to the upvalue |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10060 with index <code>up</code> of the function <code>f</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10061 The function returns <b>nil</b> if there is no upvalue |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10062 with the given index. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10063 Otherwise, it returns the name of the upvalue. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10064 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10065 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10066 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10067 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10068 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10069 <hr><h3><a name="pdf-debug.setuservalue"><code>debug.setuservalue (udata, value)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10070 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10071 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10072 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10073 Sets the given <code>value</code> as |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10074 the Lua value associated to the given <code>udata</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10075 <code>value</code> must be a table or <b>nil</b>; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10076 <code>udata</code> must be a full userdata. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10077 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10078 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10079 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10080 Returns <code>udata</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10081 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10082 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10083 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10084 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10085 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10086 <hr><h3><a name="pdf-debug.traceback"><code>debug.traceback ([thread,] [message [, level]])</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10087 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10088 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10089 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10090 If <code>message</code> is present but is neither a string nor <b>nil</b>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10091 this function returns <code>message</code> without further processing. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10092 Otherwise, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10093 it returns a string with a traceback of the call stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10094 An optional <code>message</code> string is appended |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10095 at the beginning of the traceback. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10096 An optional <code>level</code> number tells at which level |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10097 to start the traceback |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10098 (default is 1, the function calling <code>traceback</code>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10099 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10100 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10101 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10102 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10103 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10104 <hr><h3><a name="pdf-debug.upvalueid"><code>debug.upvalueid (f, n)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10105 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10106 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10107 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10108 Returns an unique identifier (as a light userdata) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10109 for the upvalue numbered <code>n</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10110 from the given function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10111 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10112 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10113 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10114 These unique identifiers allow a program to check whether different |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10115 closures share upvalues. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10116 Lua closures that share an upvalue |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10117 (that is, that access a same external local variable) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10118 will return identical ids for those upvalue indices. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10119 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10120 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10121 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10122 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10123 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10124 <hr><h3><a name="pdf-debug.upvaluejoin"><code>debug.upvaluejoin (f1, n1, f2, n2)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10125 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10126 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10127 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10128 Make the <code>n1</code>-th upvalue of the Lua closure <code>f1</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10129 refer to the <code>n2</code>-th upvalue of the Lua closure <code>f2</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10130 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10131 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10132 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10133 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10134 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10135 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10136 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10137 <h1>7 – <a name="7">Lua Standalone</a></h1> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10138 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10139 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10140 Although Lua has been designed as an extension language, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10141 to be embedded in a host C program, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10142 it is also frequently used as a standalone language. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10143 An interpreter for Lua as a standalone language, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10144 called simply <code>lua</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10145 is provided with the standard distribution. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10146 The standalone interpreter includes |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10147 all standard libraries, including the debug library. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10148 Its usage is: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10149 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10150 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10151 lua [options] [script [args]] |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10152 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10153 The options are: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10154 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10155 <ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10156 <li><b><code>-e <em>stat</em></code>: </b> executes string <em>stat</em>;</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10157 <li><b><code>-l <em>mod</em></code>: </b> "requires" <em>mod</em>;</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10158 <li><b><code>-i</code>: </b> enters interactive mode after running <em>script</em>;</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10159 <li><b><code>-v</code>: </b> prints version information;</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10160 <li><b><code>-E</code>: </b> ignores environment variables;</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10161 <li><b><code>--</code>: </b> stops handling options;</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10162 <li><b><code>-</code>: </b> executes <code>stdin</code> as a file and stops handling options.</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10163 </ul><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10164 After handling its options, <code>lua</code> runs the given <em>script</em>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10165 passing to it the given <em>args</em> as string arguments. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10166 When called without arguments, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10167 <code>lua</code> behaves as <code>lua -v -i</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10168 when the standard input (<code>stdin</code>) is a terminal, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10169 and as <code>lua -</code> otherwise. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10170 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10171 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10172 <p> |
242
b5a926c481a5
Handle first h1 tag differently.
hugo.tech@gmail.com <hugo.tech@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
241
diff
changeset
|
10173 When called without option <code>-E</code>, |
239
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10174 the interpreter checks for an environment variable <a name="pdf-LUA_INIT_5_2"><code>LUA_INIT_5_2</code></a> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10175 (or <a name="pdf-LUA_INIT"><code>LUA_INIT</code></a> if it is not defined) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10176 before running any argument. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10177 If the variable content has the format <code>@<em>filename</em></code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10178 then <code>lua</code> executes the file. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10179 Otherwise, <code>lua</code> executes the string itself. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10180 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10181 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10182 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10183 When called with option <code>-E</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10184 besides ignoring <code>LUA_INIT</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10185 Lua also ignores |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10186 the values of <code>LUA_PATH</code> and <code>LUA_CPATH</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10187 setting the values of |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10188 <a href="#pdf-package.path"><code>package.path</code></a> and <a href="#pdf-package.cpath"><code>package.cpath</code></a> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10189 with the default paths defined in <code>luaconf.h</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10190 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10191 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10192 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10193 All options are handled in order, except <code>-i</code> and <code>-E</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10194 For instance, an invocation like |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10195 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10196 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10197 $ lua -e'a=1' -e 'print(a)' script.lua |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10198 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10199 will first set <code>a</code> to 1, then print the value of <code>a</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10200 and finally run the file <code>script.lua</code> with no arguments. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10201 (Here <code>$</code> is the shell prompt. Your prompt may be different.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10202 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10203 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10204 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10205 Before starting to run the script, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10206 <code>lua</code> collects all arguments in the command line |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10207 in a global table called <code>arg</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10208 The script name is stored at index 0, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10209 the first argument after the script name goes to index 1, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10210 and so on. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10211 Any arguments before the script name |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10212 (that is, the interpreter name plus the options) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10213 go to negative indices. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10214 For instance, in the call |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10215 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10216 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10217 $ lua -la b.lua t1 t2 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10218 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10219 the interpreter first runs the file <code>a.lua</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10220 then creates a table |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10221 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10222 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10223 arg = { [-2] = "lua", [-1] = "-la", |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10224 [0] = "b.lua", |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10225 [1] = "t1", [2] = "t2" } |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10226 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10227 and finally runs the file <code>b.lua</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10228 The script is called with <code>arg[1]</code>, <code>arg[2]</code>, ... |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10229 as arguments; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10230 it can also access these arguments with the vararg expression '<code>...</code>'. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10231 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10232 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10233 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10234 In interactive mode, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10235 if you write an incomplete statement, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10236 the interpreter waits for its completion |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10237 by issuing a different prompt. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10238 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10239 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10240 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10241 In case of unprotected errors in the script, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10242 the interpreter reports the error to the standard error stream. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10243 If the error object is a string, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10244 the interpreter adds a stack traceback to it. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10245 Otherwise, if the error object has a metamethod <code>__tostring</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10246 the interpreter calls this metamethod to produce the final message. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10247 Finally, if the error object is <b>nil</b>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10248 the interpreter does not report the error. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10249 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10250 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10251 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10252 When finishing normally, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10253 the interpreter closes its main Lua state |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10254 (see <a href="#lua_close"><code>lua_close</code></a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10255 The script can avoid this step by |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10256 calling <a href="#pdf-os.exit"><code>os.exit</code></a> to terminate. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10257 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10258 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10259 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10260 To allow the use of Lua as a |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10261 script interpreter in Unix systems, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10262 the standalone interpreter skips |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10263 the first line of a chunk if it starts with <code>#</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10264 Therefore, Lua scripts can be made into executable programs |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10265 by using <code>chmod +x</code> and the <code>#!</code> form, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10266 as in |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10267 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10268 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10269 #!/usr/local/bin/lua |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10270 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10271 (Of course, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10272 the location of the Lua interpreter may be different in your machine. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10273 If <code>lua</code> is in your <code>PATH</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10274 then |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10275 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10276 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10277 #!/usr/bin/env lua |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10278 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10279 is a more portable solution.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10280 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10281 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10282 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10283 <h1>8 – <a name="8">Incompatibilities with the Previous Version</a></h1> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10284 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10285 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10286 Here we list the incompatibilities that you may find when moving a program |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10287 from Lua 5.1 to Lua 5.2. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10288 You can avoid some incompatibilities by compiling Lua with |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10289 appropriate options (see file <code>luaconf.h</code>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10290 However, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10291 all these compatibility options will be removed in the next version of Lua. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10292 Similarly, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10293 all features marked as deprecated in Lua 5.1 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10294 have been removed in Lua 5.2. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10295 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10296 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10297 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10298 <h2>8.1 – <a name="8.1">Changes in the Language</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10299 <ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10300 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10301 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10302 The concept of <em>environment</em> changed. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10303 Only Lua functions have environments. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10304 To set the environment of a Lua function, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10305 use the variable <code>_ENV</code> or the function <a href="#pdf-load"><code>load</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10306 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10307 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10308 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10309 C functions no longer have environments. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10310 Use an upvalue with a shared table if you need to keep |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10311 shared state among several C functions. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10312 (You may use <a href="#luaL_setfuncs"><code>luaL_setfuncs</code></a> to open a C library |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10313 with all functions sharing a common upvalue.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10314 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10315 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10316 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10317 To manipulate the "environment" of a userdata |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10318 (which is now called user value), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10319 use the new functions |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10320 <a href="#lua_getuservalue"><code>lua_getuservalue</code></a> and <a href="#lua_setuservalue"><code>lua_setuservalue</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10321 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10322 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10323 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10324 Lua identifiers cannot use locale-dependent letters. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10325 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10326 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10327 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10328 Doing a step or a full collection in the garbage collector |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10329 does not restart the collector if it has been stopped. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10330 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10331 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10332 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10333 Weak tables with weak keys now perform like <em>ephemeron tables</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10334 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10335 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10336 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10337 The event <em>tail return</em> in debug hooks was removed. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10338 Instead, tail calls generate a special new event, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10339 <em>tail call</em>, so that the debugger can know that |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10340 there will not be a corresponding return event. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10341 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10342 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10343 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10344 Equality between function values has changed. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10345 Now, a function definition may not create a new value; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10346 it may reuse some previous value if there is no |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10347 observable difference to the new function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10348 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10349 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10350 </ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10351 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10352 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10353 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10354 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10355 <h2>8.2 – <a name="8.2">Changes in the Libraries</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10356 <ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10357 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10358 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10359 Function <code>module</code> is deprecated. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10360 It is easy to set up a module with regular Lua code. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10361 Modules are not expected to set global variables. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10362 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10363 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10364 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10365 Functions <code>setfenv</code> and <code>getfenv</code> were removed, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10366 because of the changes in environments. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10367 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10368 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10369 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10370 Function <code>math.log10</code> is deprecated. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10371 Use <a href="#pdf-math.log"><code>math.log</code></a> with 10 as its second argument, instead. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10372 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10373 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10374 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10375 Function <code>loadstring</code> is deprecated. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10376 Use <code>load</code> instead; it now accepts string arguments |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10377 and are exactly equivalent to <code>loadstring</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10378 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10379 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10380 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10381 Function <code>table.maxn</code> is deprecated. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10382 Write it in Lua if you really need it. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10383 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10384 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10385 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10386 Function <code>os.execute</code> now returns <b>true</b> when command |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10387 terminates successfully and <b>nil</b> plus error information |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10388 otherwise. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10389 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10390 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10391 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10392 Function <code>unpack</code> was moved into the table library |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10393 and therefore must be called as <a href="#pdf-table.unpack"><code>table.unpack</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10394 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10395 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10396 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10397 Character class <code>%z</code> in patterns is deprecated, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10398 as now patterns may contain '<code>\0</code>' as a regular character. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10399 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10400 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10401 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10402 The table <code>package.loaders</code> was renamed <code>package.searchers</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10403 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10404 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10405 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10406 Lua does not have bytecode verification anymore. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10407 So, all functions that load code |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10408 (<a href="#pdf-load"><code>load</code></a> and <a href="#pdf-loadfile"><code>loadfile</code></a>) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10409 are potentially insecure when loading untrusted binary data. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10410 (Actually, those functions were already insecure because |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10411 of flaws in the verification algorithm.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10412 When in doubt, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10413 use the <code>mode</code> argument of those functions |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10414 to restrict them to loading textual chunks. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10415 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10416 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10417 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10418 The standard paths in the official distribution may |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10419 change between versions. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10420 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10421 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10422 </ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10423 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10424 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10425 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10426 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10427 <h2>8.3 – <a name="8.3">Changes in the API</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10428 <ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10429 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10430 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10431 Pseudoindex <code>LUA_GLOBALSINDEX</code> was removed. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10432 You must get the global environment from the registry |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10433 (see <a href="#4.5">§4.5</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10434 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10435 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10436 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10437 Pseudoindex <code>LUA_ENVIRONINDEX</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10438 and functions <code>lua_getfenv</code>/<code>lua_setfenv</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10439 were removed, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10440 as C functions no longer have environments. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10441 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10442 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10443 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10444 Function <code>luaL_register</code> is deprecated. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10445 Use <a href="#luaL_setfuncs"><code>luaL_setfuncs</code></a> so that your module does not create globals. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10446 (Modules are not expected to set global variables anymore.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10447 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10448 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10449 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10450 The <code>osize</code> argument to the allocation function |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10451 may not be zero when creating a new block, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10452 that is, when <code>ptr</code> is <code>NULL</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10453 (see <a href="#lua_Alloc"><code>lua_Alloc</code></a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10454 Use only the test <code>ptr == NULL</code> to check whether |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10455 the block is new. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10456 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10457 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10458 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10459 Finalizers (<code>__gc</code> metamethods) for userdata are called in the |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10460 reverse order that they were marked for finalization, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10461 not that they were created (see <a href="#2.5.1">§2.5.1</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10462 (Most userdata are marked immediately after they are created.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10463 Moreover, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10464 if the metatable does not have a <code>__gc</code> field when set, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10465 the finalizer will not be called, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10466 even if it is set later. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10467 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10468 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10469 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10470 <code>luaL_typerror</code> was removed. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10471 Write your own version if you need it. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10472 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10473 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10474 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10475 Function <code>lua_cpcall</code> is deprecated. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10476 You can simply push the function with <a href="#lua_pushcfunction"><code>lua_pushcfunction</code></a> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10477 and call it with <a href="#lua_pcall"><code>lua_pcall</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10478 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10479 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10480 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10481 Functions <code>lua_equal</code> and <code>lua_lessthan</code> are deprecated. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10482 Use the new <a href="#lua_compare"><code>lua_compare</code></a> with appropriate options instead. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10483 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10484 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10485 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10486 Function <code>lua_objlen</code> was renamed <a href="#lua_rawlen"><code>lua_rawlen</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10487 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10488 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10489 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10490 Function <a href="#lua_load"><code>lua_load</code></a> has an extra parameter, <code>mode</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10491 Pass <code>NULL</code> to simulate the old behavior. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10492 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10493 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10494 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10495 Function <a href="#lua_resume"><code>lua_resume</code></a> has an extra parameter, <code>from</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10496 Pass <code>NULL</code> or the thread doing the call. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10497 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10498 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10499 </ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10500 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10501 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10502 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10503 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10504 <h1>9 – <a name="9">The Complete Syntax of Lua</a></h1> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10505 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10506 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10507 Here is the complete syntax of Lua in extended BNF. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10508 (It does not describe operator precedences.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10509 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10510 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10511 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10512 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10513 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10514 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10515 chunk ::= block |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10516 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10517 block ::= {stat} [retstat] |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10518 |
242
b5a926c481a5
Handle first h1 tag differently.
hugo.tech@gmail.com <hugo.tech@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
241
diff
changeset
|
10519 stat ::= ‘<b>;</b>’ | |
b5a926c481a5
Handle first h1 tag differently.
hugo.tech@gmail.com <hugo.tech@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
241
diff
changeset
|
10520 varlist ‘<b>=</b>’ explist | |
b5a926c481a5
Handle first h1 tag differently.
hugo.tech@gmail.com <hugo.tech@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
241
diff
changeset
|
10521 functioncall | |
b5a926c481a5
Handle first h1 tag differently.
hugo.tech@gmail.com <hugo.tech@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
241
diff
changeset
|
10522 label | |
b5a926c481a5
Handle first h1 tag differently.
hugo.tech@gmail.com <hugo.tech@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
241
diff
changeset
|
10523 <b>break</b> | |
b5a926c481a5
Handle first h1 tag differently.
hugo.tech@gmail.com <hugo.tech@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
241
diff
changeset
|
10524 <b>goto</b> Name | |
b5a926c481a5
Handle first h1 tag differently.
hugo.tech@gmail.com <hugo.tech@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
241
diff
changeset
|
10525 <b>do</b> block <b>end</b> | |
b5a926c481a5
Handle first h1 tag differently.
hugo.tech@gmail.com <hugo.tech@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
241
diff
changeset
|
10526 <b>while</b> exp <b>do</b> block <b>end</b> | |
b5a926c481a5
Handle first h1 tag differently.
hugo.tech@gmail.com <hugo.tech@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
241
diff
changeset
|
10527 <b>repeat</b> block <b>until</b> exp | |
b5a926c481a5
Handle first h1 tag differently.
hugo.tech@gmail.com <hugo.tech@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
241
diff
changeset
|
10528 <b>if</b> exp <b>then</b> block {<b>elseif</b> exp <b>then</b> block} [<b>else</b> block] <b>end</b> | |
b5a926c481a5
Handle first h1 tag differently.
hugo.tech@gmail.com <hugo.tech@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
241
diff
changeset
|
10529 <b>for</b> Name ‘<b>=</b>’ exp ‘<b>,</b>’ exp [‘<b>,</b>’ exp] <b>do</b> block <b>end</b> | |
b5a926c481a5
Handle first h1 tag differently.
hugo.tech@gmail.com <hugo.tech@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
241
diff
changeset
|
10530 <b>for</b> namelist <b>in</b> explist <b>do</b> block <b>end</b> | |
b5a926c481a5
Handle first h1 tag differently.
hugo.tech@gmail.com <hugo.tech@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
241
diff
changeset
|
10531 <b>function</b> funcname funcbody | |
b5a926c481a5
Handle first h1 tag differently.
hugo.tech@gmail.com <hugo.tech@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
241
diff
changeset
|
10532 <b>local</b> <b>function</b> Name funcbody | |
b5a926c481a5
Handle first h1 tag differently.
hugo.tech@gmail.com <hugo.tech@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
241
diff
changeset
|
10533 <b>local</b> namelist [‘<b>=</b>’ explist] |
239
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10534 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10535 retstat ::= <b>return</b> [explist] [‘<b>;</b>’] |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10536 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10537 label ::= ‘<b>::</b>’ Name ‘<b>::</b>’ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10538 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10539 funcname ::= Name {‘<b>.</b>’ Name} [‘<b>:</b>’ Name] |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10540 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10541 varlist ::= var {‘<b>,</b>’ var} |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10542 |
242
b5a926c481a5
Handle first h1 tag differently.
hugo.tech@gmail.com <hugo.tech@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
241
diff
changeset
|
10543 var ::= Name | prefixexp ‘<b>[</b>’ exp ‘<b>]</b>’ | prefixexp ‘<b>.</b>’ Name |
239
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10544 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10545 namelist ::= Name {‘<b>,</b>’ Name} |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10546 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10547 explist ::= exp {‘<b>,</b>’ exp} |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10548 |
242
b5a926c481a5
Handle first h1 tag differently.
hugo.tech@gmail.com <hugo.tech@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
241
diff
changeset
|
10549 exp ::= <b>nil</b> | <b>false</b> | <b>true</b> | Number | String | ‘<b>...</b>’ | functiondef | |
b5a926c481a5
Handle first h1 tag differently.
hugo.tech@gmail.com <hugo.tech@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
241
diff
changeset
|
10550 prefixexp | tableconstructor | exp binop exp | unop exp |
239
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10551 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10552 prefixexp ::= var | functioncall | ‘<b>(</b>’ exp ‘<b>)</b>’ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10553 |
242
b5a926c481a5
Handle first h1 tag differently.
hugo.tech@gmail.com <hugo.tech@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
241
diff
changeset
|
10554 functioncall ::= prefixexp args | prefixexp ‘<b>:</b>’ Name args |
b5a926c481a5
Handle first h1 tag differently.
hugo.tech@gmail.com <hugo.tech@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
241
diff
changeset
|
10555 |
b5a926c481a5
Handle first h1 tag differently.
hugo.tech@gmail.com <hugo.tech@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
241
diff
changeset
|
10556 args ::= ‘<b>(</b>’ [explist] ‘<b>)</b>’ | tableconstructor | String |
239
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10557 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10558 functiondef ::= <b>function</b> funcbody |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10559 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10560 funcbody ::= ‘<b>(</b>’ [parlist] ‘<b>)</b>’ block <b>end</b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10561 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10562 parlist ::= namelist [‘<b>,</b>’ ‘<b>...</b>’] | ‘<b>...</b>’ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10563 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10564 tableconstructor ::= ‘<b>{</b>’ [fieldlist] ‘<b>}</b>’ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10565 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10566 fieldlist ::= field {fieldsep field} [fieldsep] |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10567 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10568 field ::= ‘<b>[</b>’ exp ‘<b>]</b>’ ‘<b>=</b>’ exp | Name ‘<b>=</b>’ exp | exp |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10569 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10570 fieldsep ::= ‘<b>,</b>’ | ‘<b>;</b>’ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10571 |
242
b5a926c481a5
Handle first h1 tag differently.
hugo.tech@gmail.com <hugo.tech@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
241
diff
changeset
|
10572 binop ::= ‘<b>+</b>’ | ‘<b>-</b>’ | ‘<b>*</b>’ | ‘<b>/</b>’ | ‘<b>^</b>’ | ‘<b>%</b>’ | ‘<b>..</b>’ | |
b5a926c481a5
Handle first h1 tag differently.
hugo.tech@gmail.com <hugo.tech@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
241
diff
changeset
|
10573 ‘<b><</b>’ | ‘<b><=</b>’ | ‘<b>></b>’ | ‘<b>>=</b>’ | ‘<b>==</b>’ | ‘<b>~=</b>’ | |
239
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10574 <b>and</b> | <b>or</b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10575 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10576 unop ::= ‘<b>-</b>’ | <b>not</b> | ‘<b>#</b>’ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10577 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10578 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10579 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10580 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10581 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10582 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10583 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10584 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10585 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10586 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10587 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10588 <HR> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10589 <SMALL CLASS="footer"> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10590 Last update: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10591 Thu Mar 21 13:01:53 BRT 2013 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10592 </SMALL> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10593 <!-- |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10594 Last change: revised for Lua 5.2.2 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10595 --> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10596 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10597 </body></html> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10598 |