annotate docs/manual.html @ 445:cc7d246bda2a

minor
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 04 May 2015 15:43:36 -0600
parents c912f6de2053
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
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 &copy; 2011&ndash;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 &ndash; 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 &ndash; 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 &ndash; 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 &ndash; 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 &ndash; 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 &ndash; 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 &ndash; 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 &ndash; 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 &ndash; 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 &ndash; 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 &ndash; 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 &ndash; 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 &ndash; 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 &ndash; 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 &ndash; 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 &ndash; 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 &ndash; 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 &ndash; 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 &ndash; 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 &ndash; 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 &ndash; Local Declarations</A>
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
69 <LI><A HREF="#3.3.8">3.3.8 &ndash; Or/And Statements</A>
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
70 </UL>
240
bcc3911285a2 add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 239
diff changeset
71 <LI><A HREF="#3.4">3.4 &ndash; Expressions</A>
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
72 <UL>
240
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.1">3.4.1 &ndash; Arithmetic Operators</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.2">3.4.2 &ndash; Coercion</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.3">3.4.3 &ndash; Relational 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.4">3.4.4 &ndash; Logical Operators</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.5">3.4.5 &ndash; Concatenation</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.6">3.4.6 &ndash; The Length Operator</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.7">3.4.7 &ndash; Precedence</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.8">3.4.8 &ndash; Table Constructors</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.9">3.4.9 &ndash; Function Calls</A>
bcc3911285a2 add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 239
diff changeset
82 <LI><A HREF="#3.4.10">3.4.10 &ndash; Function Definitions</A>
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
83 </UL>
240
bcc3911285a2 add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 239
diff changeset
84 <LI><A HREF="#3.5">3.5 &ndash; Visibility Rules</A>
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
85 </UL>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
86 <P>
240
bcc3911285a2 add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 239
diff changeset
87 <LI><A HREF="#4">4 &ndash; 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
88 <P>
240
bcc3911285a2 add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 239
diff changeset
89 <LI><A HREF="#5">5 &ndash; The Auxiliary Library</A>
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
90 <P>
240
bcc3911285a2 add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 239
diff changeset
91 <LI><A HREF="#6">6 &ndash; Standard Libraries</A>
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
92 <UL>
240
bcc3911285a2 add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 239
diff changeset
93 <LI><A HREF="#6.1">6.1 &ndash; Basic Functions</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="#6.2">6.2 &ndash; Coroutine Manipulation</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="#6.3">6.3 &ndash; Modules</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="#6.4">6.4 &ndash; String Manipulation</A>
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
97 <UL>
240
bcc3911285a2 add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 239
diff changeset
98 <LI><A HREF="#6.4.1">6.4.1 &ndash; Patterns</A>
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
99 </UL>
240
bcc3911285a2 add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 239
diff changeset
100 <LI><A HREF="#6.5">6.5 &ndash; Table Manipulation</A>
bcc3911285a2 add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 239
diff changeset
101 <LI><A HREF="#6.6">6.6 &ndash; Mathematical Functions</A>
bcc3911285a2 add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 239
diff changeset
102 <LI><A HREF="#6.7">6.7 &ndash; Bitwise Operations</A>
bcc3911285a2 add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 239
diff changeset
103 <LI><A HREF="#6.8">6.8 &ndash; 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
104 <LI><A HREF="#6.9">6.9 &ndash; Operating System Facilities</A>
bcc3911285a2 add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 239
diff changeset
105 <LI><A HREF="#6.10">6.10 &ndash; The Debug Library</A>
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
106 </UL>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
107 <P>
240
bcc3911285a2 add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 239
diff changeset
108 <LI><A HREF="#7">7 &ndash; Lua Standalone</A>
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
109 <P>
240
bcc3911285a2 add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 239
diff changeset
110 <LI><A HREF="#8">8 &ndash; 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
111 <UL>
240
bcc3911285a2 add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 239
diff changeset
112 <LI><A HREF="#8.1">8.1 &ndash; 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
113 <LI><A HREF="#8.2">8.2 &ndash; 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
114 <LI><A HREF="#8.3">8.3 &ndash; 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
115 </UL>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
116 <P>
240
bcc3911285a2 add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 239
diff changeset
117 <LI><A HREF="#9">9 &ndash; 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
118 </UL>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
119
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
120
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
121 <h1>1 &ndash; <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
122
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
123 <p>Luan is a high level programming language based on <a href="http://www.lua.org">Lua</a>. A great strength of Lua is its simplicity and Luan takes this even further, being even simpler than Lua. The goal is to provide a simple programming language for the casual programmer with as few concepts as possible so that programmers can quickly learn the language and then easily understand any code written in Luan.
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
124
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
125 <p>Luan is implemented in Java and is tightly coupled with Java. So it makes a great scripting language for Java programmers. By importing the <em>Java</em> package, one can directly call Java from Luan.
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
126
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
127 <p>Unlike Lua which is meant to be embedded, Luan is meant to be a full scripting language. This done not by adding feature to Luan, but rather by providing a complete set of libraries.
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
128
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
129 <h1>2 &ndash; <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
130
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
131 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
132 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
133
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
134
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 <h2>2.1 &ndash; <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
137
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
138 <p>
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
139 Luan is a <em>dynamically typed language</em>.
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
140 This means that
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
141 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
142 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
143 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
144
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
145
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
146 <p>
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
147 All values in Luan are <em>first-class values</em>.
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
148 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
149 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
150
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
151
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
152 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
153 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
154 <em>nil</em>, <em>boolean</em>, <em>number</em>,
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
155 <em>string</em>, <em>binary</em>, <em>function</em>, <em>userdata</em>,
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
156 and <em>table</em>.
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
157 <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
158 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
159 it usually represents the absence of a useful value.
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
160 <em>Nil</em> is implemented as the Java value <em>null</em>.
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
161 <em>Boolean</em> is the type of the values <b>false</b> and <b>true</b>.
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
162 <em>Boolean</em> is implemented as the Java class <em>Boolean</em>.
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
163 <em>Number</em> represents real (double-precision floating-point) numbers.
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
164 <em>Number</em> is implemented as the Java class <em>Number</em>. Any Java subclass of <em>Number</em> is allowed and this is invisible to the Luan user. Operations on numbers follow the same rules of
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
165 the underlying Java&nbsp;implementation.
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
166
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
167 <em>String</em> is implemented as the Java class <em>String</em>.
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
168 <em>Binary</em> is implemented as the Java type <em>byte[]</em>.
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
169
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
170
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
171 <p>
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
172 Luan can call (and manipulate) functions written in Luan and
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
173 functions written in Java
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
174 (see <a href="#3.4.9">&sect;3.4.9</a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
175
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
176
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
177 <p>
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
178 The type <em>userdata</em> is provided to allow arbitrary Java&nbsp;objects to
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
179 be stored in Lua variables.
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
180 A userdata value is a Java object that isn't of the standard Luan types.
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
181
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
182
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
183 <p>
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
184 Lua has a type <em>thread</em> that Luan lacks because Luan does not have the Lua concept of coroutines.
239
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
187 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
188 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
189 that is, arrays that can be indexed not only with numbers,
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
190 but with any Lua value except <b>nil</b>.
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
191 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
192 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
193 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
194 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
195 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
196
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
197
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
198 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
199 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
200 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
201 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
202 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
203 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
204 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
205 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
206 (see <a href="#3.4.8">&sect;3.4.8</a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
207
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
208
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
209 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
210 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
211 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
212 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
213 which is called the length of the sequence (see <a href="#3.4.6">&sect;3.4.6</a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
214
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
215
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
216 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
217 Like indices,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
218 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
219 In particular,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
220 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
221 table fields can contain functions.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
222 Thus tables can also carry <em>methods</em> (see <a href="#3.4.10">&sect;3.4.10</a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
223
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
224
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
225 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
226 The indexing of tables follows
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
227 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
228 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
229 denote the same table element
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
230 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
231 (that is, equal without metamethods).
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>
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
235 Tables, functions, and userdata values are <em>objects</em>:
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
236 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
237 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
238 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
239 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
240 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
241
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
242
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
243 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
244 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
245 of a given value (see <a href="#6.1">&sect;6.1</a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
246
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
247
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
248
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 <h2>2.2 &ndash; <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
252
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
253 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
254 As will be discussed in <a href="#3.2">&sect;3.2</a> and <a href="#3.3.3">&sect;3.3.3</a>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
255 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
256 to <code>_ENV.var</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
257 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
258 an external local variable called <code>_ENV</code> (see <a href="#3.3.2">&sect;3.3.2</a>),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
259 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
260
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
261
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
262 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
263 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
264 the translation of global names,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
265 <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
266 In particular,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
267 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
268 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
269 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
270 following the usual visibility rules of Lua (see <a href="#3.5">&sect;3.5</a>).
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
273 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
274 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
275
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
276
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
277 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
278 Lua keeps a distinguished environment called the <em>global environment</em>.
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
279 This value is kept in the Luan state implemented in Java.
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
280 In Luan, the variable <a href="#pdf-_G"><code>_G</code></a> is initialized with this same value.
239
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 When Lua compiles a chunk,
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
285 it initializes the value of its <code>_ENV</code> to an empty table.
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
286 The values in the global environment become local variables of the chunk.
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
287 All standard libraries are loaded in the global environment
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
288 and so they become available as local variables.
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
289 You can use <a href="#pdf-load"><code>load</code></a> (or <a href="#pdf-loadfile"><code>load_file</code></a>)
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
290 to load a chunk with a specific environment instead of starting empty.
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
291
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
292
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
293 <p>
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
294 If you change the values in the global environment,
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
295 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
296 Previously loaded chunks are not affected, however,
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
297 as each has its own references to the values in its local variables.
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
298 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
299 (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
300 is never updated by Lua.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
301
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
302
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
303
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
304
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
305
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
306 <h2>2.3 &ndash; <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
307
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
308 <p>
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
309 Luan error handling is quite different from Lua.
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
310
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
311
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
312 <p>
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
313 Luan code can explicitly generate an error by calling the
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
314 <a href="#pdf-error"><code>error</code></a> function.
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
315 Unlike Lua, Luan has <code>try-catch</code> blocks for catching errors. This means that there is no need for Lua's <code>pcall</code> and <code>xpcall</code> functions.
239
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
318 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
319 Whenever there is an error,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
320 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
321 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
322 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
323 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
324 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
325
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
328
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
329 <h2>2.4 &ndash; <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
330
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
331 <p>
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
332 Every table in Luan can have a <em>metatable</em>.
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
333 This <em>metatable</em> is an ordinary Luan table
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
334 that defines the behavior of the original table
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
335 under certain special operations.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
336 You can change several aspects of the behavior
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
337 of operations over a table by setting specific fields in its metatable.
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
338 For instance, when a table is the operand of an addition,
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
339 Luan checks for a function in the field "<code>__add</code>" of the table's metatable.
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
340 If it finds one,
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
341 Luan calls this function to perform the addition.
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
342
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
343 <p>
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
344 Inside Luan's implementation, there is a global metatable that applies to all objects. This metatable is not exposed to Luan users but can be used to change the behavior of objects other than tables.
239
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
347 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
348 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
349 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
350 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
351
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
352
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
353 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
354 You can query the metatable of any value
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
355 using the <a href="#pdf-getmetatable"><code>get_metatable</code></a> function.
239
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
358 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
359 You can replace the metatable of tables
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
360 using the <a href="#pdf-setmetatable"><code>set_metatable</code></a> function.
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
361
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
362
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
363 <p>
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
364 Tables have individual metatables
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
365 (although multiple tables can share their metatables).
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
366 By default, a table has no metatable.
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
367
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
368
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
369 <p>
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
370 A metatable controls how a table behaves in arithmetic operations,
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
371 order comparisons, concatenation, length operation, and indexing.
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
372 When Luan performs one of these operations over a table,
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
373 it checks whether this table has a metatable with the corresponding event.
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
374 If so, the value associated with that key (the metamethod)
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
375 controls how Luan will perform the operation.
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
376
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
377
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
378 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
379 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
380 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
381 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
382 two underscores, '<code>__</code>';
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
383 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
384 string "<code>__add</code>".
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
385
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>
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
388 The semantics of these operations is better explained by a Luan function
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
389 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
390 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
391 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
392 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
393 All functions used in these descriptions
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
394 (<a href="#pdf-rawget"><code>raw_get</code></a>, <a href="#pdf-tonumber"><code>to_number</code></a>, etc.)
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
395 are described in <a href="#6.1">&sect;6.1</a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
396 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
397 we use the expression
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
398
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
399 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
400 metatable(obj)[event]
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
401 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
402 This should be read as
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
403
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
404 <pre>
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
405 raw_get(get_metatable(obj) or {}, event)
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
406 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
407 This means that the access to a metamethod does not invoke other metamethods,
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
408 and access to tables with no metatables does not fail
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
409 (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
410
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
411 <p>
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
412
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 <ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
415
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
416 <li><b>"add": </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
417 the <code>+</code> operation.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
418
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
419
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
420
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
421 <p>
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
422 The function <code>get_bin_handler</code> below defines how Luan chooses a handler
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
423 for a binary operation.
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
424 First, Luan tries the first operand.
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
425 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
426 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
427
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
428 <pre>
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
429 function get_bin_handler (op1, op2, event)
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
430 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
431 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
432 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
433 By using this function,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
434 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
435
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
436 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
437 function add_event (op1, op2)
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
438 local o1, o2 = to_number(op1), to_number(op2)
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
439 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
440 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
441 else -- at least one of the operands is not numeric
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
442 local h = get_bin_handler(op1, op2, "__add")
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
443 if h then
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
444 -- 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
445 return (h(op1, op2))
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
446 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
447 error(&middot;&middot;&middot;)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
448 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
449 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
450 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
451 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
452 </li>
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 <li><b>"sub": </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
455 the <code>-</code> operation.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
456
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
457 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
458 </li>
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 <li><b>"mul": </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
461 the <code>*</code> operation.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
462
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
463 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
464 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
465
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
466 <li><b>"span": </b>
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
467 the <code>/</code> operation.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
468
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
469 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
470 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
471
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
472 <li><b>"mod": </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
473 the <code>%</code> operation.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
474
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
475 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
476 with the operation
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
477 <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
478 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
479
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
480 <li><b>"pow": </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
481 the <code>^</code> (exponentiation) operation.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
482
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
483 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
484 with the function <code>pow</code> (from the C&nbsp;math library)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
485 as the primitive operation.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
486 </li>
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 <li><b>"unm": </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
489 the unary <code>-</code> operation.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
490
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
491
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
492 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
493 function unm_event (op)
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
494 local o = to_number(op)
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
495 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
496 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
497 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
498 -- 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
499 local h = metatable(op).__unm
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
500 if h then
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
501 -- 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
502 return (h(op))
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
503 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
504 error(&middot;&middot;&middot;)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
505 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
506 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
507 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
508 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
509 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
510
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
511 <li><b>"concat": </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
512 the <code>..</code> (concatenation) operation.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
513
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 function concat_event (op1, op2)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
517 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
518 (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
519 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
520 else
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
521 local h = get_bin_handler(op1, op2, "__concat")
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
522 if h then
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
523 return (h(op1, op2))
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
524 else
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
525 error(&middot;&middot;&middot;)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
526 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
527 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
528 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
529 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
530 </li>
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 <li><b>"len": </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
533 the <code>#</code> operation.
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
536 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
537 function len_event (op)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
538 if type(op) == "string" then
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
539 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
540 else
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
541 local h = metatable(op).__len
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
542 if h then
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
543 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
544 elseif type(op) == "table" then
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
545 return #op -- primitive table length
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
546 else -- no handler available: error
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
547 error(&middot;&middot;&middot;)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
548 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
549 end
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 See <a href="#3.4.6">&sect;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
553 </li>
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 <li><b>"eq": </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
556 the <code>==</code> operation.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
557
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
558 The function <code>get_equal_handler</code> defines how Luan chooses a metamethod
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
559 for equality.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
560 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
561 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
562 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
563 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
564
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
565 <pre>
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
566 function get_equal_handler (op1, op2)
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
567 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
568 (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
569 return nil -- different values
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
570 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
571 local mm1 = metatable(op1).__eq
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
572 local mm2 = metatable(op2).__eq
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
573 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
574 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
575 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
576 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
577
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
578 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
579 function eq_event (op1, op2)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
580 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
581 return true -- values are equal
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
582 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
583 -- try metamethod
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
584 local h = get_equal_handler(op1, op2)
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
585 if h then
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
586 return to_boolean(h(op1, op2))
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
587 else
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
588 return false
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
589 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
590 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
591 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
592 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
593 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
594
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
595 <li><b>"lt": </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
596 the <code>&lt;</code> operation.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
597
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 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
600 function lt_event (op1, op2)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
601 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
602 return op1 &lt; op2 -- numeric comparison
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
603 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
604 return op1 &lt; op2 -- lexicographic comparison
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
605 else
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
606 local h = get_bin_handler(op1, op2, "__lt")
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
607 if h then
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
608 return to_boolean(h(op1, op2))
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
609 else
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
610 error(&middot;&middot;&middot;)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
611 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
612 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
613 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
614 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
615 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
616 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
617
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
618 <li><b>"le": </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
619 the <code>&lt;=</code> operation.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
620
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
621
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
622 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
623 function le_event (op1, op2)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
624 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
625 return op1 &lt;= op2 -- numeric comparison
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
626 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
627 return op1 &lt;= op2 -- lexicographic comparison
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
628 else
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
629 local h = get_bin_handler(op1, op2, "__le")
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
630 if h then
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
631 return to_boolean(h(op1, op2))
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
632 else
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
633 h = get_bin_handler(op1, op2, "__lt")
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
634 if h then
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
635 return not to_boolean(h(op2, op1))
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
636 else
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
637 error(&middot;&middot;&middot;)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
638 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
639 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
640 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
641 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
642 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
643 Note that, in the absence of a "le" metamethod,
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
644 Luan tries the "lt", assuming that <code>a &lt;= b</code> is
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
645 equivalent to <code>not (b &lt; a)</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
646
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
647
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
648 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
649 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
650 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
651 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
652
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
653 <li><b>"index": </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
654 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
655 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
656 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
657 (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
658 no key is ever present,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
659 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
660
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
661
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
662 <pre>
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
663 function get_table_event (table, key)
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
664 local h
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
665 if type(table) == "table" then
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
666 local v = raw_get(table, key)
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
667 -- 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
668 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
669 h = metatable(table).__index
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
670 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
671 else
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
672 h = metatable(table).__index
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
673 if h == nil then
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
674 error(&middot;&middot;&middot;)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
675 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
676 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
677 if type(h) == "function" then
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
678 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
679 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
680 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
681 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
682 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
683 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
684
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
685 <li><b>"newindex": </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
686 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
687 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
688 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
689
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
690
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
691 <pre>
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
692 function set_table_event (table, key, value)
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
693 local h
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
694 if type(table) == "table" then
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
695 local v = raw_get(table, key)
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
696 -- if key is present, do raw assignment
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
697 if v ~= nil then raw_set(table, key, value); return end
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
698 h = metatable(table).__newindex
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
699 if h == nil then raw_set(table, key, value); return end
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
700 else
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
701 h = metatable(table).__newindex
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
702 if h == nil then
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
703 error(&middot;&middot;&middot;)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
704 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
705 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
706 if type(h) == "function" then
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
707 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
708 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
709 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
710 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
711 </pre><p>
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>"call": </b>
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
715 called when Luan calls a value.
239
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 function_event (func, ...)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
720 if type(func) == "function" then
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
721 return func(...) -- primitive call
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
722 else
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
723 local h = metatable(func).__call
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
724 if h then
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
725 return h(func, ...)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
726 else
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
727 error(&middot;&middot;&middot;)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
728 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
729 end
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 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
732 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
733
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
734 </ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
735
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
738
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
739 <h2>2.5 &ndash; <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
740
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
741 <p>
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
742 Luan uses Java's garbage collection, so there is very little to say on this subject. So this section is just a place holder to replace the long explanation of Lua's garbage collection which isn't needed by Luan.
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
743
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
744 <p>
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
745 Lua has <em>weak tables</em> which is a good concept but is not yet implemented in Luan. It will be added when there is a need.
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
746
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
747
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
748
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
749 <h2>2.6 &ndash; <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
750
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
751 <p>
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
752 Unlike Lua, Luan does not support coroutines. Yes coroutines are cool, but they are not simple, so in the name of simplicity, Luan does without them.
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
753
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
754
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
755
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
756
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
757
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
758 <h1>3 &ndash; <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
759
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
760 <p>
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
761 This section describes the lexis, the syntax, and the semantics of Luan.
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
762 In other words,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
763 this section describes
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
764 which tokens are valid,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
765 how they can be combined,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
766 and what their combinations mean.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
767
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
768
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
769 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
770 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
771 in which
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
772 {<em>a</em>}&nbsp;means&nbsp;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
773 [<em>a</em>]&nbsp;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
774 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
775 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
776 and other terminal symbols are shown like &lsquo;<b>=</b>&rsquo;.
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
777 The complete syntax of Luan can be found in <a href="#9">&sect;9</a>
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
778 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
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
782 <h2>3.1 &ndash; <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
783
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
784 <p>
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
785 Luan ignores spaces and comments
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
786 between lexical elements (tokens),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
787 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
788
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
789 But unlike Lua, Luan generally treats the newline character as a statement separator. This is how most languages work. If a newline is preceded by a backslash, then it is treated like a space. Also, inside of parenthesis (...), brackets [...], and braces {...}, a newline is treated like a space. This allows the Luan parser to catch mistakes more easily.
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
790
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
791 <p>
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
792 In interactive mode, Luan allows an expression on a line which is then evaluated and printed. This means that entering <em>1+1</em> on an interactive line will produce <em>2</em>.
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
793
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
794
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
795 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
796 <em>Names</em>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
797 (also called <em>identifiers</em>)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
798 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
799 digits, and underscores,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
800 not beginning with a digit.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
801 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
802
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
805 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
806 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
807
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 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
810 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
811 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
812 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
813 then true until while
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
814 </pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
815
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
816 The following <em>keywords</em> are also reserved in Luan but not in Lua:
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
817
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
818 <pre>
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
819 catch import try
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
820 </pre>
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
821
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
822
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
823
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
824 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
825 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
826 <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
827 are two different, valid names.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
828 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
829 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
830 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
831
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
834 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
835
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
836 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
837 + - * / % ^ #
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
838 == ~= &lt;= &gt;= &lt; &gt; =
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
839 ( ) { } [ ]
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
840 ; : , . .. ...
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
841 </pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
842
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
843 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
844 <em>Literal strings</em>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
845 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
846 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
847 '<code>\a</code>' (bell),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
848 '<code>\b</code>' (backspace),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
849 '<code>\f</code>' (form feed),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
850 '<code>\n</code>' (newline),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
851 '<code>\r</code>' (carriage return),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
852 '<code>\t</code>' (horizontal tab),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
853 '<code>\v</code>' (vertical tab),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
854 '<code>\\</code>' (backslash),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
855 '<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
856 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
857 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
858 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
859 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
860 of white-space characters,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
861 including line breaks;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
862 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
863 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
864 into the string contents.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
865
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
866
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
867 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
868 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
869 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
870 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
871 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
872 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
873 (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
874 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
875 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
876 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
877
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
878
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
879 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
880 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
881 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
882 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
883 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
884 opening square bracket.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
885 So, an opening long bracket of level&nbsp;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
886 an opening long bracket of level&nbsp;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
887 and so on.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
888 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
889 for instance, a closing long bracket of level&nbsp;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
890 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
891 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
892 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
893 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
894 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
895 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
896 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
897 (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
898 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
899 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
900
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
901
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
904 For convenience,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
905 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
906 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
907 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
908 (in which '<code>a</code>' is coded as&nbsp;97,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
909 newline is coded as&nbsp;10, and '<code>1</code>' is coded as&nbsp;49),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
910 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
911
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
912 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
913 a = 'alo\n123"'
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
914 a = "alo\n123\""
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
915 a = '\97lo\10\04923"'
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
916 a = [[alo
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
917 123"]]
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
918 a = [==[
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
919 alo
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
920 123"]==]
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
921 </pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
922
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
923 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
924 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
925 and an optional decimal exponent,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
926 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
927 Lua also accepts hexadecimal constants,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
928 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
929 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
930 plus an optional binary exponent,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
931 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
932 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
933
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
934 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
935 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
936 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
937 </pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
938
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
939 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
940 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
941 anywhere outside a string.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
942 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
943 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
944 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
945 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
946 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
947 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
948
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
952
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
953 <h2>3.2 &ndash; <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
954
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
955 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
956 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
957 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
958 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
959
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
960
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
961 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
962 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
963 (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
964 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
965
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
966 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
967 var ::= Name
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
968 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
969 Name denotes identifiers, as defined in <a href="#3.1">&sect;3.1</a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
970
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
973 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
974 as a local (see <a href="#3.3.7">&sect;3.3.7</a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
975 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
976 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
977 defined inside their scope (see <a href="#3.5">&sect;3.5</a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
978
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
979
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
980 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
981 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
982
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
983
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
984 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
985 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
986
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
987 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
988 var ::= prefixexp &lsquo;<b>[</b>&rsquo; exp &lsquo;<b>]</b>&rsquo;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
989 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
990 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
991 An access to an indexed variable <code>t[i]</code> is equivalent to
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
992 a call <code>get_table_event(t,i)</code>.
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
993 (See <a href="#2.4">&sect;2.4</a> for a complete description of the
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
994 <code>get_table_event</code> function.
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
995 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
996 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
997
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
998
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
999 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1000 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
1001 <code>var["Name"]</code>:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1002
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1003 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1004 var ::= prefixexp &lsquo;<b>.</b>&rsquo; Name
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1005 </pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1006
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1007 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1008 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
1009 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
1010 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
1011 <code>_ENV</code> is never a global name (see <a href="#2.2">&sect;2.2</a>).
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 <h2>3.3 &ndash; <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
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 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
1021 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
1022 This set includes
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1023 assignments, control structures, function calls,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1024 and variable declarations.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1025
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 <h3>3.3.1 &ndash; <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
1029
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1030 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1031 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
1032 which are executed sequentially:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1033
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1034 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1035 block ::= {stat}
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1036 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1037 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
1038 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
1039 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
1040 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
1041
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1042 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1043 stat ::= &lsquo;<b>;</b>&rsquo;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1044 </pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1045
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1046
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1047 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1048 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
1049
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1050 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1051 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
1052 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1053 Explicit blocks are useful
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1054 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
1055
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1056
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1057
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1058
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1059
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1060 <h3>3.3.2 &ndash; <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
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 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
1064 Syntactically,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1065 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
1066
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1067 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1068 chunk ::= block
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1069 </pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1070
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1071 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1072 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
1073 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
1074 (see <a href="#3.4.10">&sect;3.4.10</a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1075 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
1076 receive arguments, and return values.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1077 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
1078 scope of an external local variable called <code>_ENV</code> (see <a href="#2.2">&sect;2.2</a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1079 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
1080 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
1081
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1082
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1083 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1084 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
1085 To execute a chunk,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1086 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
1087 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
1088 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
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 <h3>3.3.3 &ndash; <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
1096
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1097 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1098 Lua allows multiple assignments.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1099 Therefore, the syntax for assignment
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1100 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
1101 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
1102 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
1103
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1104 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1105 stat ::= varlist &lsquo;<b>=</b>&rsquo; explist
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1106 varlist ::= var {&lsquo;<b>,</b>&rsquo; var}
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1107 explist ::= exp {&lsquo;<b>,</b>&rsquo; exp}
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1108 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1109 Expressions are discussed in <a href="#3.4">&sect;3.4</a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1110
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1111
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1112 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1113 Before the assignment,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1114 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
1115 the list of variables.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1116 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
1117 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
1118 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
1119 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
1120 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
1121 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
1122 before the adjustment
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1123 (except when the call is enclosed in parentheses; see <a href="#3.4">&sect;3.4</a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1124
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1125
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1126 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1127 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
1128 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
1129 Thus the code
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1130
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1131 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1132 i = 3
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1133 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
1134 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1135 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
1136 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
1137 before it is assigned&nbsp;4.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1138 Similarly, the line
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 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1141 x, y = y, x
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1142 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1143 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
1144 and
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1145
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1146 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1147 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
1148 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1149 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
1150
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1151
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1152 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1153 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
1154 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
1155 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
1156 <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
1157 (See <a href="#2.4">&sect;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
1158 <code>settable_event</code> function.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1159 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
1160 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
1161
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1162
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1163 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1164 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
1165 is equivalent to the assignment
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1166 <code>_ENV.x = val</code> (see <a href="#2.2">&sect;2.2</a>).
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1170
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1171
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1172 <h3>3.3.4 &ndash; <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
1173 The control structures
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1174 <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
1175 familiar syntax:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1176
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1177
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1178
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1179
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1180 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1181 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
1182 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
1183 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
1184 </pre><p>
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
1185 Lua also has a <b>for</b> statement (see <a href="#3.3.5">&sect;3.3.5</a>).
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1186
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1187
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1188 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1189 The condition expression of a
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
1190 control structure must return a boolean.
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
1191 This is unlike Lua and is intended to catch programming errors more quickly.
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1192
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1193
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1194 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1195 In the <b>repeat</b>&ndash;<b>until</b> loop,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1196 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
1197 but only after the condition.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1198 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
1199 declared inside the loop block.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1200
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1201
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1202
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1203
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1204 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1205 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
1206 <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
1207 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
1208
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1209
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1210 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1211 stat ::= <b>break</b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1212 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1213 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
1214
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1215
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1216 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1217 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
1218 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
1219
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1220 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
1221 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
1222
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1223 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1224 stat ::= <b>return</b> [explist] [&lsquo;<b>;</b>&rsquo;]
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1225 </pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1226
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1227
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1228
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1229
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1230
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1231 <h3>3.3.5 &ndash; <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
1232
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
1233
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
1234 <p>
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
1235 The <b>for</b> statement works over functions,
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1236 called <em>iterators</em>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1237 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
1238 stopping when this new value is <b>nil</b>.
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
1239 The <b>for</b> loop has the following syntax:
239
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 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1242 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
1243 namelist ::= Name {&lsquo;<b>,</b>&rsquo; Name}
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1244 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1245 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
1246
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1247 <pre>
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
1248 for <em>var_1</em>, &middot;&middot;&middot;, <em>var_n</em> in <em>expression</em> do <em>block</em> end
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1249 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1250 is equivalent to the code:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1251
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1252 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1253 do
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
1254 local <em>f</em> = <em>expression</em>
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1255 while true do
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
1256 local <em>var_1</em>, &middot;&middot;&middot;, <em>var_n</em> = <em>f</em>()
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1257 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
1258 <em>block</em>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1259 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1260 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1261 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1262 Note the following:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1263
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1264 <ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1265
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1266 <li>
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
1267 <code><em>expression</em></code> is evaluated only once.
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
1268 Its result is an <em>iterator</em> function.
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1269 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1270
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1271 <li>
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
1272 <code><em>f</em></code> is an invisible variable.
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
1273 The name is here for explanatory purposes only.
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1274 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1275
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1276 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1277 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
1278 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1279
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1280 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1281 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
1282 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
1283 If you need these values,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1284 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
1285 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1286
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1287 </ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1288
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
1289 <p>
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
1290 Lua also has a numeric <b>for</b> statement which Luan does not support. Instead, Luan offers the <em>range</em> function (inspired by Python) which does the same thing without adding to the syntax of the language.
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1291
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1292
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1293 <h3>3.3.6 &ndash; <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
1294 To allow possible side-effects,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1295 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
1296
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1297 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1298 stat ::= functioncall
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1299 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1300 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
1301 Function calls are explained in <a href="#3.4.9">&sect;3.4.9</a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1302
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1303
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1304
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1305
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1306
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1307 <h3>3.3.7 &ndash; <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
1308 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
1309 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
1310
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1311 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1312 stat ::= <b>local</b> namelist [&lsquo;<b>=</b>&rsquo; explist]
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1313 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1314 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
1315 of a multiple assignment (see <a href="#3.3.3">&sect;3.3.3</a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1316 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
1317
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1318 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1319 A chunk is also a block (see <a href="#3.3.2">&sect;3.3.2</a>),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1320 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
1321
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1324 The visibility rules for local variables are explained in <a href="#3.5">&sect;3.5</a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1325
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1326
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1327
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
1328 <h3>3.3.8 &ndash; <a name="3.3.8">Or/And Statements</a></h3><p>
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
1329
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
1330 <p>
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
1331 An <b>or</b> or <b>and</b> expression is also considered a statement. This is new for Luan and doesn't exist in Lua.
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
1332
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
1333 <p>For example, consider a function <em>do_something</em> that returns a boolean indicating whether it succeeded or failed. You can then do:
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
1334
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
1335 <pre>
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
1336 do_something() or error "didn't work"
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
1337 </pre>
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
1338
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
1339
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1340
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1341
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1342
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1343
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1344 <h2>3.4 &ndash; <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
1345
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1346 <p>
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
1347 The basic expressions in Luan are the following:
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1348
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1349 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1350 exp ::= prefixexp
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1351 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
1352 exp ::= Number
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1353 exp ::= String
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1354 exp ::= functiondef
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1355 exp ::= tableconstructor
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1356 exp ::= &lsquo;<b>...</b>&rsquo;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1357 exp ::= exp binop exp
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1358 exp ::= unop exp
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1359 prefixexp ::= var | functioncall | &lsquo;<b>(</b>&rsquo; exp &lsquo;<b>)</b>&rsquo;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1360 </pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1361
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1362 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1363 Numbers and literal strings are explained in <a href="#3.1">&sect;3.1</a>;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1364 variables are explained in <a href="#3.2">&sect;3.2</a>;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1365 function definitions are explained in <a href="#3.4.10">&sect;3.4.10</a>;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1366 function calls are explained in <a href="#3.4.9">&sect;3.4.9</a>;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1367 table constructors are explained in <a href="#3.4.8">&sect;3.4.8</a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1368 Vararg expressions,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1369 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
1370 directly inside a vararg function;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1371 they are explained in <a href="#3.4.10">&sect;3.4.10</a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1372
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1373
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1374 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1375 Binary operators comprise arithmetic operators (see <a href="#3.4.1">&sect;3.4.1</a>),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1376 relational operators (see <a href="#3.4.3">&sect;3.4.3</a>), logical operators (see <a href="#3.4.4">&sect;3.4.4</a>),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1377 and the concatenation operator (see <a href="#3.4.5">&sect;3.4.5</a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1378 Unary operators comprise the unary minus (see <a href="#3.4.1">&sect;3.4.1</a>),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1379 the unary <b>not</b> (see <a href="#3.4.4">&sect;3.4.4</a>),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1380 and the unary <em>length operator</em> (see <a href="#3.4.6">&sect;3.4.6</a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1381
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1382
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1383 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1384 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
1385 If a function call is used as a statement (see <a href="#3.3.6">&sect;3.3.6</a>),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1386 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
1387 thus discarding all returned values.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1388 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
1389 of a list of expressions,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1390 then no adjustment is made
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1391 (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
1392 In all other contexts,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1393 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
1394 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
1395 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
1396
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1397
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1398 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1399 Here are some examples:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1400
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1401 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1402 f() -- adjusted to 0 results
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1403 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
1404 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
1405 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
1406 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
1407 -- 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
1408 -- 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
1409
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1410 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
1411 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
1412 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
1413 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
1414 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
1415 {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
1416 {...} -- 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
1417 {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
1418 </pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1419
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1420 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1421 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
1422 Thus,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1423 <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
1424 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
1425 (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
1426 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
1427
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1428
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1429
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1430 <h3>3.4.1 &ndash; <a name="3.4.1">Arithmetic Operators</a></h3><p>
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
1431 Luan supports the usual arithmetic operators:
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1432 the binary <code>+</code> (addition),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1433 <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
1434 <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
1435 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
1436 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
1437 numbers (see <a href="#3.4.2">&sect;3.4.2</a>),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1438 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
1439 Exponentiation works for any exponent.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1440 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
1441 Modulo is defined as
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1442
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1443 <pre>
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
1444 a % b == a - Math.floor(a/b)*b
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1445 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1446 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
1447 the quotient towards minus infinity.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1448
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1449
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1450
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1451
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 <h3>3.4.2 &ndash; <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
1454
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1455 <p>
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
1456 Luan provides automatic conversion between
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1457 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
1458 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
1459 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
1460 (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
1461 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
1462 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
1463 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
1464 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
1465 (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
1466
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 <h3>3.4.3 &ndash; <a name="3.4.3">Relational Operators</a></h3><p>
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
1472 The relational operators in Luan are
239
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 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1475 == ~= &lt; &gt; &lt;= &gt;=
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1476 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1477 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
1478
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1479
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1480 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1481 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
1482 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
1483 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
1484 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
1485 Tables, userdata, and threads
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1486 are compared by reference:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1487 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
1488 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
1489 (a table, userdata, or thread),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1490 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
1491 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
1492 Closures with any detectable difference
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1493 (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
1494
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1495
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1496 <p>
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
1497 You can change the way that Luan compares tables
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1498 by using the "eq" metamethod (see <a href="#2.4">&sect;2.4</a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1499
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 The conversion rules of <a href="#3.4.2">&sect;3.4.2</a>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1503 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
1504 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
1505 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
1506 entries in a table.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1507
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1508
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1509 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1510 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
1511
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1514 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
1515 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
1516 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
1517 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
1518 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
1519 metamethod (see <a href="#2.4">&sect;2.4</a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1520 A comparison <code>a &gt; b</code> is translated to <code>b &lt; a</code>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1521 and <code>a &gt;= b</code> is translated to <code>b &lt;= a</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1522
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1523
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1524
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1527 <h3>3.4.4 &ndash; <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
1528 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
1529 <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
1530 Like the control structures (see <a href="#3.3.4">&sect;3.3.4</a>),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1531 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
1532 and anything else as true.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1533
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1534
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1535 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1536 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
1537 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
1538 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
1539 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
1540 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
1541 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
1542 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
1543 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
1544 that is,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1545 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
1546 Here are some examples:
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 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1549 10 or 20 --&gt; 10
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1550 10 or error() --&gt; 10
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1551 nil or "a" --&gt; "a"
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1552 nil and 10 --&gt; nil
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1553 false and error() --&gt; false
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1554 false and nil --&gt; false
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1555 false or nil --&gt; nil
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1556 10 and 20 --&gt; 20
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1557 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1558 (In this manual,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1559 <code>--&gt;</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
1560
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1561
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1562
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1563
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1564
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1565 <h3>3.4.5 &ndash; <a name="3.4.5">Concatenation</a></h3><p>
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
1566 The string concatenation operator in Luan is
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1567 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
1568 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
1569 strings according to the rules mentioned in <a href="#3.4.2">&sect;3.4.2</a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1570 Otherwise, the <code>__concat</code> metamethod is called (see <a href="#2.4">&sect;2.4</a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1571
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1572
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1573
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1574
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 <h3>3.4.6 &ndash; <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
1577
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1578 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1579 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
1580 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
1581 (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
1582 character is one byte).
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1586 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
1587 any value but strings through the <code>__len</code> metamethod (see <a href="#2.4">&sect;2.4</a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1588
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 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
1592 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
1593 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
1594 that is,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1595 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
1596 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
1597 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
1598 Note that a table like
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1599
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1600 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1601 {10, 20, nil, 40}
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1602 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1603 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
1604 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
1605 (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
1606 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
1607 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
1608 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
1609
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1610
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1611
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1612
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1613
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1614 <h3>3.4.7 &ndash; <a name="3.4.7">Precedence</a></h3><p>
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
1615 Operator precedence in Luan follows the table below,
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1616 from lower to higher priority:
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 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1619 or
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1620 and
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1621 &lt; &gt; &lt;= &gt;= ~= ==
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1622 ..
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 * / %
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1625 not # - (unary)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1626 ^
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 As usual,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1629 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
1630 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
1631 operators are right associative.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1632 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
1633
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1634
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1635
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1636
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1637
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1638 <h3>3.4.8 &ndash; <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
1639 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
1640 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
1641 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
1642 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
1643 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
1644
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1645 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1646 tableconstructor ::= &lsquo;<b>{</b>&rsquo; [fieldlist] &lsquo;<b>}</b>&rsquo;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1647 fieldlist ::= field {fieldsep field} [fieldsep]
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1648 field ::= &lsquo;<b>[</b>&rsquo; exp &lsquo;<b>]</b>&rsquo; &lsquo;<b>=</b>&rsquo; exp | Name &lsquo;<b>=</b>&rsquo; exp | exp
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1649 fieldsep ::= &lsquo;<b>,</b>&rsquo; | &lsquo;<b>;</b>&rsquo;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1650 </pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1651
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1652 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1653 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
1654 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
1655 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
1656 <code>["name"] = exp</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1657 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
1658 <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
1659 starting with 1.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1660 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
1661 For example,
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 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1664 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
1665 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1666 is equivalent to
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1667
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1668 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1669 do
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1670 local t = {}
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1671 t[f(1)] = g
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1672 t[1] = "x" -- 1st exp
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1673 t[2] = "y" -- 2nd exp
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1674 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
1675 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
1676 t[30] = 23
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1677 t[4] = 45 -- 4th exp
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1678 a = t
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1679 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1680 </pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1681
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1682 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1683 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
1684 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
1685 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
1686 (see <a href="#3.4.9">&sect;3.4.9</a>).
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 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
1691 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
1692
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1693
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1694
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 <h3>3.4.9 &ndash; <a name="3.4.9">Function Calls</a></h3><p>
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
1698 A function call in Luan has the following syntax:
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1699
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1700 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1701 functioncall ::= prefixexp args
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1702 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1703 In a function call,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1704 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
1705 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
1706 then this function is called
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1707 with the given arguments.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1708 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
1709 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
1710 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
1711 (see <a href="#2.4">&sect;2.4</a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1712
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1713
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1714 <p>
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
1715 Lua supports a special function call for "methods" like <em>obj:fn(args)</em> . Luan does not support this.
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1716
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1717 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1718 Arguments have the following syntax:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1719
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1720 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1721 args ::= &lsquo;<b>(</b>&rsquo; [explist] &lsquo;<b>)</b>&rsquo;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1722 args ::= tableconstructor
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1723 args ::= String
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1724 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1725 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
1726 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
1727 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
1728 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
1729 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
1730 (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
1731 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
1732 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
1733
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1736 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
1737 a <em>tail call</em>.
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
1738 Luan implements <em>proper tail calls</em>
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1739 (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
1740 in a tail call,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1741 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
1742 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
1743 a program can execute.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1744 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
1745 calling function.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1746 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
1747 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
1748 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
1749 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
1750 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
1751
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1752 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1753 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
1754 return 2 * f(x)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1755 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
1756 f(x); return -- results discarded
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1757 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
1758 </pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1759
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
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 <h3>3.4.10 &ndash; <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
1764
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1765 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1766 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
1767
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1768 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1769 functiondef ::= <b>function</b> funcbody
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1770 funcbody ::= &lsquo;<b>(</b>&rsquo; [parlist] &lsquo;<b>)</b>&rsquo; block <b>end</b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1771 </pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1772
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1773 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1774 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
1775
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1776 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1777 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
1778 stat ::= <b>local</b> <b>function</b> Name funcbody
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
1779 funcname ::= Name {&lsquo;<b>.</b>&rsquo; Name}
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1780 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1781 The statement
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1782
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1783 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1784 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
1785 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1786 translates to
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1787
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1788 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1789 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
1790 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1791 The statement
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1792
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1793 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1794 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
1795 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1796 translates to
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 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1799 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
1800 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1801 The statement
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1802
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1803 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1804 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
1805 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1806 translates to
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1807
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1808 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1809 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
1810 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1811 not to
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1812
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1813 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1814 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
1815 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1816 (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
1817 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
1818
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1821 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
1822 whose value has type <em>function</em>.
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
1823 When Luan precompiles a chunk,
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1824 all its function bodies are precompiled too.
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
1825 Then, whenever Luan executes the function definition,
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1826 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
1827 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
1828 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
1829
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1830
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1831 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1832 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
1833 initialized with the argument values:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1834
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1835 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1836 parlist ::= namelist [&lsquo;<b>,</b>&rsquo; &lsquo;<b>...</b>&rsquo;] | &lsquo;<b>...</b>&rsquo;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1837 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1838 When a function is called,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1839 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
1840 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
1841 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
1842 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
1843 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
1844 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
1845 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
1846 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
1847 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
1848 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
1849 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
1850 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
1851 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
1852 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
1853 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
1854 then no adjustment is made
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1855 (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
1856
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1857
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1858 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1859 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
1860
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1861 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1862 function f(a, b) end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1863 function g(a, b, ...) end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1864 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
1865 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1866 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
1867 to the vararg expression:
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 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1870 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
1871
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1872 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
1873 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
1874 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
1875 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
1876 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
1877
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1878 g(3) a=3, b=nil, ... --&gt; (nothing)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1879 g(3, 4) a=3, b=4, ... --&gt; (nothing)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1880 g(3, 4, 5, 8) a=3, b=4, ... --&gt; 5 8
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1881 g(5, r()) a=5, b=1, ... --&gt; 2 3
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1882 </pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1883
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1884 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1885 Results are returned using the <b>return</b> statement (see <a href="#3.3.4">&sect;3.3.4</a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1886 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
1887 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
1888 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
1889
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1890
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1891
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1892
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1893 <h2>3.5 &ndash; <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
1894
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1895 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1896
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
1897 Luan is a lexically scoped language.
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1898 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
1899 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
1900 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
1901 Consider the following example:
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 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1904 x = 10 -- global variable
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1905 do -- new block
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1906 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
1907 print(x) --&gt; 10
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1908 x = x+1
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1909 do -- another block
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1910 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
1911 print(x) --&gt; 12
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1912 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1913 print(x) --&gt; 11
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1914 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1915 print(x) --&gt; 10 (the global one)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1916 </pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1917
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1918 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1919 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
1920 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
1921 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
1922
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1925 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
1926 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
1927 defined inside their scope.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1928 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
1929 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
1930 inside the inner function.
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1933 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1934 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
1935 defines new local variables.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1936 Consider the following example:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1937
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1938 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1939 a = {}
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1940 local x = 20
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1941 for i=1,10 do
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1942 local y = 0
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1943 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
1944 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1945 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1946 The loop creates ten closures
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1947 (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
1948 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
1949 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
1950
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1951
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1952
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1953
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1954
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1955 <h1>4 &ndash; <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
1956
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1957 <p>
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
1958 In the Lua documentation,
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
1959 this section described the C&nbsp;API for Lua.
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
1960 Obviously this is not relevant for Luan.
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
1961 The implementation of Luan is radically different from Lua and will be documented eventually in Javadoc.
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
1962 So this section is just a placeholder so that Luan documentation can match Lua's documentation.
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1963
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1964
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1965
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1966
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1967 <h1>5 &ndash; <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
1968
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1969 <p>
243
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
1970 Like the previous section, this section is specific to Lua and is not relevant to Luan.
c912f6de2053 more work on the manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 242
diff changeset
1971 So this section is just a placeholder.
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1972
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1973
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1974
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1975
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1976
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1977 <h1>6 &ndash; <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
1978
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1979 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1980 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
1981 that are implemented directly through the C&nbsp;API.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1982 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
1983 (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
1984 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
1985 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
1986 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
1987 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
1988
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1989
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1990 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1991 All libraries are implemented through the official C&nbsp;API
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1992 and are provided as separate C&nbsp;modules.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1993 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
1994
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1995 <ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1996
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1997 <li>basic library (<a href="#6.1">&sect;6.1</a>);</li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1998
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1999 <li>coroutine library (<a href="#6.2">&sect;6.2</a>);</li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2000
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2001 <li>package library (<a href="#6.3">&sect;6.3</a>);</li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2002
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2003 <li>string manipulation (<a href="#6.4">&sect;6.4</a>);</li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2004
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2005 <li>table manipulation (<a href="#6.5">&sect;6.5</a>);</li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2006
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2007 <li>mathematical functions (<a href="#6.6">&sect;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
2008
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2009 <li>bitwise operations (<a href="#6.7">&sect;6.7</a>);</li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2010
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2011 <li>input and output (<a href="#6.8">&sect;6.8</a>);</li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2012
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2013 <li>operating system facilities (<a href="#6.9">&sect;6.9</a>);</li>
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 <li>debug facilities (<a href="#6.10">&sect;6.10</a>).</li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2016
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2017 </ul><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2018 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
2019 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
2020 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
2021
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2022
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2023 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2024 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
2025 the C&nbsp;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
2026 which opens all standard libraries.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2027 Alternatively,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2028 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
2029 <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
2030 <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
2031 <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
2032 <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
2033 <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
2034 <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
2035 <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
2036 <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
2037 <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
2038 <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
2039 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
2040 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
2041
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2042
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2043
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2044 <h2>6.1 &ndash; <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
2045
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2046 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2047 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
2048 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
2049 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
2050 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
2051
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2054 <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
2055 Issues an error when
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2056 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
2057 otherwise, returns all its arguments.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2058 <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
2059 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
2060
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2063
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2064 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2065 <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
2066
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2067
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2068 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2069 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
2070 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
2071
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2072 <ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2073
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2074 <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
2075 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
2076 This is the default option.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2077 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2078
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2079 <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
2080 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
2081 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
2082 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
2083 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2084
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2085 <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
2086 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
2087 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2088
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2089 <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
2090 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
2091 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
2092 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
2093 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
2094
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2095 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2096 k, b = collectgarbage("count")
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2097 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
2098 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2099 (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
2100 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
2101 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2102
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2103 <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
2104 performs a garbage-collection step.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2105 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
2106 (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
2107 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
2108 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
2109 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
2110 </li>
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 <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
2113 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
2114 the collector (see <a href="#2.5">&sect;2.5</a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2115 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
2116 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2117
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2118 <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
2119 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
2120 the collector (see <a href="#2.5">&sect;2.5</a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2121 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
2122 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2123
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2124 <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
2125 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
2126 (i.e., not stopped).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2127 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2128
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2129 <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
2130 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
2131 This is an experimental feature (see <a href="#2.5">&sect;2.5</a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2132 </li>
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 <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
2135 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
2136 This is the default mode.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2137 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2138
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2139 </ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2140
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2141
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2142
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2143 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2144 <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
2145 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
2146 When called without arguments,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2147 <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
2148 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
2149 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
2150 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
2151
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2152
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2153
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2154
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2155 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2156 <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
2157 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
2158 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
2159 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
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2163 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
2164 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
2165 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
2166 With level&nbsp;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
2167 <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
2168 Level&nbsp;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
2169 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
2170 Passing a level&nbsp;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
2171 to the message.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2172
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2173
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 <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
2178 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
2179 holds the global environment (see <a href="#2.2">&sect;2.2</a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2180 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
2181 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
2182 nor vice-versa.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2183
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2184
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2187 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2188 <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
2189
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2190
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2191 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2192 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
2193 Otherwise,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2194 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
2195 returns the associated value.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2196 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
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2201 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2202 <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
2203
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2204
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2205 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2206 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
2207 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
2208 results from the call.
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2212 Otherwise,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2213 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
2214 so that the construction
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2215
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2216 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2217 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
2218 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2219 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
2220 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
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2225 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2226 <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
2227
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2228
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2229 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2230 Loads a chunk.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2231
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2232
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2233 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2234 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
2235 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
2236 <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
2237 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
2238 with previous results.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2239 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
2240
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2241
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2242 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2243 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
2244 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
2245 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
2246
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2247
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2248 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2249 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
2250 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
2251 if that parameter is given,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2252 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
2253 (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
2254 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
2255 the <code>_ENV</code> variable (see <a href="#2.2">&sect;2.2</a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2256 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
2257 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
2258
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2259
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2260 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2261 <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
2262 and debug information (see <a href="#4.9">&sect;4.9</a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2263 When absent,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2264 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
2265 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
2266
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 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
2270 (that is, a precompiled chunk).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2271 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
2272 "<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
2273 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
2274 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
2275
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2276
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2277
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2280 <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
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2284 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
2285 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
2286 or from the standard input,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2287 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
2288
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2289
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2290
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2291
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2292 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2293 <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
2294
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2295
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2296 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2297 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
2298 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
2299 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
2300 <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
2301 and its associated value.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2302 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
2303 <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
2304 and its associated value.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2305 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
2306 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
2307 <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
2308 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
2309 In particular,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2310 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
2311
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2312
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2313 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2314 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
2315 <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
2316 (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
2317 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
2318
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2319
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2320 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2321 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
2322 during the traversal,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2323 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
2324 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
2325 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
2326
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2327
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 <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
2332
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2333
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2334 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2335 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
2336 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
2337 results from the call.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2338
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2339
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2340 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2341 Otherwise,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2342 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
2343 so that the construction
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2344
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2345 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2346 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
2347 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2348 will iterate over all key&ndash;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
2349
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2350
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2351 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2352 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
2353 the table during its traversal.
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2359 <hr><h3><a name="pdf-pcall"><code>pcall (f [, arg1, &middot;&middot;&middot;])</code></a></h3>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2360
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2361
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2362 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2363 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
2364 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
2365 This means that any error inside&nbsp;<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
2366 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
2367 and returns a status code.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2368 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
2369 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
2370 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
2371 after this first result.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2372 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
2373
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2374
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2375
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2376
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2377 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2378 <hr><h3><a name="pdf-print"><code>print (&middot;&middot;&middot;)</code></a></h3>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2379 Receives any number of arguments
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2380 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
2381 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
2382 <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
2383 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
2384 for instance for debugging.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2385 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
2386 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
2387
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2388
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2389
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2390
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2391 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2392 <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
2393 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
2394 without invoking any metamethod.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2395 Returns a boolean.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2396
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2399
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2400 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2401 <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
2402 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
2403 without invoking any metamethod.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2404 <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
2405 <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
2406
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2409
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2410 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2411 <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
2412 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
2413 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
2414 without invoking any metamethod.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2415 Returns an integer number.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2416
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2417
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2418
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2419
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2420 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2421 <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
2422 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
2423 without invoking any metamethod.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2424 <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
2425 <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
2426 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
2427
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2428
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2429 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2430 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
2431
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2432
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2433
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2434
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2435 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2436 <hr><h3><a name="pdf-select"><code>select (index, &middot;&middot;&middot;)</code></a></h3>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2437
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2438
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2439 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2440 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
2441 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
2442 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
2443 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
2444 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
2445
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2446
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2447
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2448
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2449 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2450 <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
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 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
2455 (You cannot change the metatable of other types from Lua, only from&nbsp;C.)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2456 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
2457 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
2458 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
2459 raises an error.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2460
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2461
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2462 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2463 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
2464
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2465
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2466
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2467
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2468 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2469 <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
2470
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2471
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2472 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2473 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
2474 <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
2475 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
2476 a string convertible to a number (see <a href="#3.4.2">&sect;3.4.2</a>),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2477 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
2478 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
2479
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2480
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2481 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2482 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
2483 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
2484 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
2485 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
2486 In bases above&nbsp;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
2487 represents&nbsp;10, '<code>B</code>' represents&nbsp;11, and so forth,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2488 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
2489 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
2490 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
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2494
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2495 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2496 <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
2497 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
2498 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
2499 (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
2500 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
2501
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2502
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2503 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2504 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
2505 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
2506 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
2507 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
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2513 <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
2514 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
2515 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
2516 "<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
2517 "<code>number</code>",
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2518 "<code>string</code>",
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2519 "<code>boolean</code>",
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2520 "<code>table</code>",
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2521 "<code>function</code>",
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2522 "<code>thread</code>",
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2523 and "<code>userdata</code>".
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2524
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2525
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2526
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2527
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2528 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2529 <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
2530 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
2531 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
2532 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
2533
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2534
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2535
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2536
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2537 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2538 <hr><h3><a name="pdf-xpcall"><code>xpcall (f, msgh [, arg1, &middot;&middot;&middot;])</code></a></h3>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2539
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2540
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2541 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2542 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
2543 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
2544
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2545
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2546
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2547
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2548
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2549
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2550
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2551 <h2>6.2 &ndash; <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
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 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
2555 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
2556 See <a href="#2.6">&sect;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
2557
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2558
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2559 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2560 <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
2561
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2562
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2563 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2564 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
2565 <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
2566 Returns this new coroutine,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2567 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
2568
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2569
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2573 <hr><h3><a name="pdf-coroutine.resume"><code>coroutine.resume (co [, val1, &middot;&middot;&middot;])</code></a></h3>
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2576 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2577 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
2578 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
2579 it starts running its body.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2580 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
2581 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
2582 If the coroutine has yielded,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2583 <code>resume</code> restarts it;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2584 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
2585 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
2586
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2587
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2588 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2589 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
2590 <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
2591 (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
2592 (if the coroutine terminates).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2593 If there is any error,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2594 <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
2595
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2596
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2597
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2598
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2599 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2600 <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
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2604 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
2605 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
2606
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2607
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2608
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2611 <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
2612
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2613
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2614 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2615 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
2616 <code>"running"</code>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2617 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
2618 <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
2619 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
2620 <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
2621 (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
2622 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
2623 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
2624
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2625
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2626
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2627
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2628 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2629 <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
2630
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2631
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2632 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2633 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
2634 <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
2635 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
2636 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
2637 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
2638 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
2639 except the first boolean.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2640 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
2641
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2644
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2645 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2646 <hr><h3><a name="pdf-coroutine.yield"><code>coroutine.yield (&middot;&middot;&middot;)</code></a></h3>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2647
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2648
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2649 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2650 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
2651 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
2652
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2653
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2654
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2655
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2656
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2657
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 <h2>6.3 &ndash; <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
2660
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2661 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2662 The package library provides basic
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2663 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
2664 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
2665 <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
2666 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
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2670 <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
2671
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2672
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2673 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2674 Loads the given module.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2675 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
2676 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
2677 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
2678 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
2679 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
2680
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2681
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2682 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2683 To find a loader,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2684 <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
2685 By changing this sequence,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2686 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
2687 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
2688 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
2689
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2690
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2691 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2692 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
2693 If it has a value,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2694 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
2695 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
2696 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
2697 If that also fails, it searches for a C&nbsp;loader using the
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2698 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
2699 If that also fails,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2700 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
2701
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2702
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2703 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2704 Once a loader is found,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2705 <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
2706 <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
2707 (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
2708 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
2709 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
2710 <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
2711 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
2712 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
2713 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
2714 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
2715 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
2716
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2717
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2718 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2719 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
2720 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
2721 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
2722
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2723
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2724
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2727 <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
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2731 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
2732 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
2733
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2734 <ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2735
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2736 <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
2737 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
2738
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2739 <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
2740 Default is '<code>;</code>'.</li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2741
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2742 <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
2743 substitution points in a template.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2744 Default is '<code>?</code>'.</li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2745
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2746 <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
2747 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
2748 Default is '<code>!</code>'.</li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2749
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2750 <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
2751 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
2752 Default is '<code>-</code>'.</li>
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 </ul>
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2758 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2759 <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
2760
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2761
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2762 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2763 The path used by <a href="#pdf-require"><code>require</code></a> to search for a C&nbsp;loader.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2764
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2765
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2766 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2767 Lua initializes the C&nbsp;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
2768 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
2769 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
2770 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
2771 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
2772
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2773
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2774
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2775
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2776 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2777 <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
2778
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2779
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2780 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2781 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
2782 modules are already loaded.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2783 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
2784 <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
2785 <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
2786
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2787
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2788 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2789 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
2790 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
2791 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
2792
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2793
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2794
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2795
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2796 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2797 <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
2798
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2799
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2800 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2801 Dynamically links the host program with the C&nbsp;library <code>libname</code>.
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2805 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
2806 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
2807 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
2808 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
2809 Otherwise,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2810 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
2811 and returns this function as a C&nbsp;function.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2812 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
2813 (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
2814
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2815
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2816 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2817 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
2818 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
2819 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
2820 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
2821 does not automatically adds extensions.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2822 <code>libname</code> must be the complete file name of the C&nbsp;library,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2823 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
2824 <code>funcname</code> must be the exact name exported by the C&nbsp;library
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2825 (which may depend on the C&nbsp;compiler and linker used).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2826
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2827
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2828 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2829 This function is not supported by Standard&nbsp;C.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2830 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
2831 (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
2832 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
2833
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2834
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2835
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2836
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2837 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2838 <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
2839
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2840
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2841 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2842 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
2843
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2844
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2845 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2846 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
2847 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
2848 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
2849 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
2850 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
2851 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
2852 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
2853
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2854
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2857 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2858 <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
2859
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2860
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2861 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2862 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
2863 (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
2864
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2865
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2866 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2867 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
2868 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
2869 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
2870
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2871
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 <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
2876
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2877
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2878 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2879 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
2880
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2881
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2882 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2883 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
2884 When looking for a module,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2885 <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
2886 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
2887 sole parameter.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2888 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
2889 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
2890 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
2891 (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
2892
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2893
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2894 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2895 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
2896
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2897
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2898 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2899 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
2900 <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
2901
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2902
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2903 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2904 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
2905 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
2906 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
2907
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2908
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2909 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2910 The third searcher looks for a loader as a C&nbsp;library,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2911 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
2912 Again,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2913 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
2914 For instance,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2915 if the C&nbsp;path is the string
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 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2918 "./?.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
2919 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2920 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
2921 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
2922 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
2923 Once it finds a C&nbsp;library,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2924 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
2925 application with the library.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2926 Then it tries to find a C&nbsp;function inside the library to
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2927 be used as the loader.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2928 The name of this C&nbsp;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
2929 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
2930 is replaced by an underscore.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2931 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
2932 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
2933 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
2934 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
2935
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2936
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2937 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2938 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
2939 It searches the C&nbsp;path for a library for
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2940 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
2941 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
2942 it will search for a C&nbsp;library for <code>a</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2943 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
2944 the submodule;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2945 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
2946 With this facility, a package can pack several C&nbsp;submodules
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2947 into one single library,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2948 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
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2952 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
2953 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
2954 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
2955 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
2956
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2957
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2961 <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
2962
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2963
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2964 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2965 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
2966
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2967
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2968 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2969 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
2970 <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
2971 For each template,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2972 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
2973 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
2974 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
2975 (a dot, by default)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2976 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
2977 (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
2978 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
2979
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2982 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
2983
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2984 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2985 "./?.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
2986 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2987 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
2988 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
2989 <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
2990 <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
2991
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2992
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2993 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2994 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
2995 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
2996 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
2997 (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
2998
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2999
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3000
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3004
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3005 <h2>6.4 &ndash; <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
3006
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3007 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3008 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
3009 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
3010 When indexing a string in Lua, the first character is at position&nbsp;1
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3011 (not at&nbsp;0, as in C).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3012 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
3013 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
3014 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
3015
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3018 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
3019 <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
3020 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
3021 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
3022 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
3023 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
3024 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
3025
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3026
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3027 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3028 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
3029
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3030
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3031 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3032 <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
3033 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
3034 <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
3035 The default value for <code>i</code> is&nbsp;1;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3036 the default value for <code>j</code> is&nbsp;<code>i</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3037 These indices are corrected
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3038 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
3039
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3042 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
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3046
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3047 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3048 <hr><h3><a name="pdf-string.char"><code>string.char (&middot;&middot;&middot;)</code></a></h3>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3049 Receives zero or more integers.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3050 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
3051 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
3052 to its corresponding argument.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3053
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3054
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3055 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3056 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
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3060
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3061 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3062 <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
3063
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3064
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3065 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3066 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
3067 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
3068 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
3069
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3070
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3073 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3074 <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
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3078 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
3079 <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
3080 If it finds a match, then <code>find</code> returns the indices of&nbsp;<code>s</code>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3081 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
3082 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
3083 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
3084 where to start the search;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3085 its default value is&nbsp;1 and can be negative.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3086 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
3087 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
3088 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
3089 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
3090 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
3091
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3092
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3093 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3094 If the pattern has captures,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3095 then in a successful match
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3096 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
3097 after the two indices.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3098
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3099
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3100
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3101
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3102 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3103 <hr><h3><a name="pdf-string.format"><code>string.format (formatstring, &middot;&middot;&middot;)</code></a></h3>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3104
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3105
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3106 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3107 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
3108 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
3109 The format string follows the same rules as the ANSI&nbsp;C function <code>sprintf</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3110 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
3111 <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
3112 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
3113 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
3114 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
3115 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
3116 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
3117 For instance, the call
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3118
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3119 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3120 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
3121 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3122 may produce the string:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3123
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3124 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3125 "a string with \"quotes\" and \
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3126 new line"
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3127 </pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3128
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3129 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3130 Options
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3131 <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
3132 <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
3133 <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
3134 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
3135 <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
3136 also expect a number,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3137 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
3138 the underlying C&nbsp;implementation.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3139 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
3140 the number cannot be negative.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3141 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
3142 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
3143 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
3144 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
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3149 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3150 <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
3151 Returns an iterator function that,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3152 each time it is called,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3153 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
3154 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
3155 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
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3159 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
3160 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
3161 printing one per line:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3162
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3163 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3164 s = "hello world from Lua"
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3165 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
3166 print(w)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3167 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3168 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3169 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
3170 given string into a table:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3171
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3172 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3173 t = {}
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3174 s = "from=world, to=Lua"
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3175 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
3176 t[k] = v
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3177 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3178 </pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3179
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3180 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3181 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
3182 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
3183
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3184
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 <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
3189 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
3190 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
3191 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
3192 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
3193 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
3194 <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
3195 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
3196 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
3197
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3198
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3199 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3200 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
3201 The character&nbsp;<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
3202 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
3203 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
3204 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
3205 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
3206 The sequence <code>%%</code> stands for a single&nbsp;<code>%</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3207
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3210 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
3211 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
3212
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3213
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3214 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3215 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
3216 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
3217 in order.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3218
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3219
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3220 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3221 In any case,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3222 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
3223 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
3224
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3227 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
3228 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
3229 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
3230 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
3231 then there is no replacement
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3232 (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
3233
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3234
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3235 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3236 Here are some examples:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3237
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3238 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3239 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
3240 --&gt; 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
3241
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3242 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
3243 --&gt; 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
3244
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3245 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
3246 --&gt; 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
3247
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3248 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
3249 --&gt; 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
3250
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3251 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
3252 return load(s)()
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3253 end)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3254 --&gt; 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
3255
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3256 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
3257 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
3258 --&gt; 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
3259 </pre>
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3263 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3264 <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
3265 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
3266 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
3267 Embedded zeros are counted,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3268 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
3269
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
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3274 <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
3275 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
3276 uppercase letters changed to lowercase.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3277 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
3278 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
3279
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3280
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3281
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3282
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3283 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3284 <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
3285 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
3286 <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
3287 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
3288 the captures from the pattern;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3289 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
3290 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
3291 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
3292 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
3293 where to start the search;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3294 its default value is&nbsp;1 and can be negative.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3295
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3298
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3299 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3300 <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
3301 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
3302 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
3303 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
3304 (that is, no separator).
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3308
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3309 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3310 <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
3311 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
3312
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3313
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3314
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3315
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3316 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3317 <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
3318 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
3319 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
3320 <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
3321 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
3322 (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
3323 In particular,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3324 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
3325 with length <code>j</code>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3326 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
3327 with length <code>i</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3328
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 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
3332 <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
3333 it is corrected to 1.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3334 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
3335 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
3336 If, after these corrections,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3337 <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
3338 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
3339
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3343 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3344 <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
3345 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
3346 lowercase letters changed to uppercase.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3347 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
3348 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
3349
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 <h3>6.4.1 &ndash; <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
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 <h4>Character Class:</h4><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3356 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
3357 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
3358
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3359 <ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3360
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3361 <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
3362 (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
3363 <code>^$()%.[]*+-?</code>)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3364 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
3365 </li>
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 <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
3368
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3369 <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
3370
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3371 <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
3372
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3373 <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
3374
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3375 <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
3376
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3377 <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
3378
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3379 <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
3380
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3381 <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
3382
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3383 <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
3384
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3385 <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
3386
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3387 <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
3388
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3389 <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
3390 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
3391 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
3392 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
3393 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
3394 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
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>[<em>set</em>]</code>: </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3398 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
3399 characters in <em>set</em>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3400 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
3401 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
3402 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
3403 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
3404 components in <em>set</em>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3405 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
3406 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
3407 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
3408 <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
3409 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
3410 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
3411
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3412
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3413 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3414 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
3415 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
3416 have no meaning.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3417 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3418
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3419 <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
3420 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
3421 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
3422 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3423
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3424 </ul><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3425 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
3426 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
3427 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
3428
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3429
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3430 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3431 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
3432 depend on the current locale.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3433 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
3434
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3435
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3436
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3439 <h4>Pattern Item:</h4><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3440 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
3441
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3442 <ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3443
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3444 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3445 a single character class,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3446 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
3447 </li>
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 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3450 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
3451 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
3452 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
3453 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3454
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3455 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3456 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
3457 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
3458 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
3459 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3460
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3461 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3462 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
3463 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
3464 Unlike '<code>*</code>',
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3465 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
3466 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3467
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3468 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3469 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
3470 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
3471 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3472
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3473 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3474 <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
3475 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
3476 (see below);
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3477 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3478
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3479 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3480 <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
3481 such item matches strings that start with&nbsp;<em>x</em>, end with&nbsp;<em>y</em>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3482 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
3483 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
3484 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
3485 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
3486 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
3487 balanced parentheses.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3488 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3489
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3490 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3491 <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
3492 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
3493 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
3494 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
3495 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
3496 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
3497 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
3498 </li>
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 </ul>
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3503
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3504
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3505 <h4>Pattern:</h4><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3506 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
3507 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
3508 beginning of the subject string.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3509 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
3510 end of the subject string.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3511 At other positions,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3512 '<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
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3517
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3518 <h4>Captures:</h4><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3519 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
3520 they describe <em>captures</em>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3521 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
3522 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
3523 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
3524 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
3525 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
3526 stored as the first capture (and therefore has number&nbsp;1);
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3527 the character matching "<code>.</code>" is captured with number&nbsp;2,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3528 and the part matching "<code>%s*</code>" has number&nbsp;3.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3529
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 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
3533 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
3534 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
3535 string <code>"flaaap"</code>, there will be two captures: 3&nbsp;and&nbsp;5.
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3541
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3542
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3545
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3546
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3547 <h2>6.5 &ndash; <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
3548
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3549 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3550 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
3551 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
3552
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3553
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3554 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3555 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
3556 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
3557 or have a <code>__len</code> metamethod (see <a href="#3.4.6">&sect;3.4.6</a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3558 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
3559 in tables given as arguments.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3560
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3561
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3562 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3563 For performance reasons,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3564 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
3565
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3566
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3567 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3568 <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
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3572 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
3573 returns the string <code>list[i]..sep..list[i+1] &middot;&middot;&middot; sep..list[j]</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3574 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
3575 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
3576 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
3577 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
3578
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3579
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3580
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3581
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3582 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3583 <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
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3587 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
3588 shifting up the elements
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3589 <code>list[pos], list[pos+1], &middot;&middot;&middot;, list[#list]</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3590 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
3591 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
3592 of list <code>t</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3593
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3594
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3595
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3598 <hr><h3><a name="pdf-table.pack"><code>table.pack (&middot;&middot;&middot;)</code></a></h3>
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3602 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
3603 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
3604 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
3605
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3609 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3610 <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
3611
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3614 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
3615 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
3616 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
3617 it shifts down the elements
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3618 <code>list[pos+1], list[pos+2], &middot;&middot;&middot;, list[#list]</code>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3619 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
3620 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
3621 or <code>#list + 1</code>;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3622 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
3623
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3626 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
3627 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
3628 of list <code>t</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3629
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3630
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3631
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 <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
3635
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3638 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
3639 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
3640 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
3641 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
3642 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
3643 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
3644 (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
3645 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
3646 then the standard Lua operator <code>&lt;</code> is used instead.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3647
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3650 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
3651 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
3652 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
3653
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3654
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3655
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 <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
3659
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3662 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
3663 This function is equivalent to
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 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3666 return list[i], list[i+1], &middot;&middot;&middot;, list[j]
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3667 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3668 By default, <code>i</code> is&nbsp;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
3669
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3670
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3671
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 <h2>6.6 &ndash; <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
3677
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3678 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3679 This library is an interface to the standard C&nbsp;math library.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3680 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
3681
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3682
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3683 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3684 <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
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3688 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
3689
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3690
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3691
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 <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
3695
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3696
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3697 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3698 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
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3703 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3704 <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
3705
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3706
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3707 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3708 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
3709
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3714 <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
3715
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3716
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3717 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3718 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
3719
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3720
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3721
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3722
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3723 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3724 <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
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3728 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
3729 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
3730 quadrant of the result.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3731 (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
3732
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3733
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3734
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3737 <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
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3741 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
3742
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3745
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3746 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3747 <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
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3751 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
3752
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3753
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3754
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 <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
3758
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3761 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
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3765
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3766 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3767 <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
3768
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3769
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3770 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3771 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
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3777 <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
3778
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3779
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3780 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3781 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
3782
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3783
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3786 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3787 <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
3788
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3789
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3790 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3791 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
3792
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3793
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3794
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3797 <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
3798
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3801 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
3802 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
3803
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3804
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3807 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3808 <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
3809
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3810
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3811 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3812 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
3813 <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
3814 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
3815 (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
3816
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3817
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 <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
3822
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3825 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
3826 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
3827
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3828
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3829
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3830
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3831 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3832 <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
3833
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3834
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3835 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3836 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
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3840
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3841 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3842 <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
3843
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3844
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3845 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3846 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
3847 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
3848 (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
3849
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3850
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3851
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3852
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3853 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3854 <hr><h3><a name="pdf-math.max"><code>math.max (x, &middot;&middot;&middot;)</code></a></h3>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3855
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3856
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3857 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3858 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
3859
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3860
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3861
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3864 <hr><h3><a name="pdf-math.min"><code>math.min (x, &middot;&middot;&middot;)</code></a></h3>
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3868 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
3869
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3872
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3873 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3874 <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
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3878 Returns two numbers,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3879 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
3880
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3881
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3884 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3885 <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
3886
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3887
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3888 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3889 The value of <em>&pi;</em>.
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3892
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3893
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3894 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3895 <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
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3899 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
3900 (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
3901
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3902
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3905 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3906 <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
3907
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3908
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3909 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3910 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
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3915 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3916 <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
3917
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3918
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3919 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3920 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
3921 pseudo-random generator function <code>rand</code> provided by Standard&nbsp;C.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3922 (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
3923
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3926 When called without arguments,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3927 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
3928 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
3929 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
3930 <code>math.random</code> returns
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3931 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
3932 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
3933 <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
3934 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
3935
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3936
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3937
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3938
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3939 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3940 <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
3941
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3942
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3943 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3944 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
3945 for the pseudo-random generator:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3946 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
3947
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3948
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 <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
3953
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3956 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
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3960
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3961 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3962 <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
3963
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3964
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3965 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3966 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
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3972 <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
3973
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3974
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3975 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3976 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
3977 (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
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3981
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3982 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3983 <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
3984
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3985
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3986 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3987 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
3988
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3989
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3990
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3991
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3992 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3993 <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
3994
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3995
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3996 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3997 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
3998
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3999
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4000
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4001
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4002
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4003
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4004
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4005 <h2>6.7 &ndash; <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
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 This library provides bitwise operations.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4009 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
4010
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4011
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4012 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4013 Unless otherwise stated,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4014 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
4015 <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
4016 each argument is normalized to
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4017 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
4018 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
4019 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
4020 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
4021 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
4022 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
4023
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4024
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4025 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4026 <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
4027
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4028
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4029 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4030 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
4031 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
4032 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
4033
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4034
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4035 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4036 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
4037 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
4038 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
4039 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
4040 In particular,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4041 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
4042 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
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4048 <hr><h3><a name="pdf-bit32.band"><code>bit32.band (&middot;&middot;&middot;)</code></a></h3>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4049
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4050
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4051 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4052 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
4053
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4054
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4057 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4058 <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
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4062 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
4063 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
4064 the following identity holds:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4065
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4066 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4067 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
4068 </pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4069
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4073 <hr><h3><a name="pdf-bit32.bor"><code>bit32.bor (&middot;&middot;&middot;)</code></a></h3>
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4076 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4077 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
4078
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4079
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4080
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4083 <hr><h3><a name="pdf-bit32.btest"><code>bit32.btest (&middot;&middot;&middot;)</code></a></h3>
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4087 Returns a boolean signaling
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4088 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
4089
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4090
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4091
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4094 <hr><h3><a name="pdf-bit32.bxor"><code>bit32.bxor (&middot;&middot;&middot;)</code></a></h3>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4095
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4096
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4097 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4098 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
4099
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4100
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4101
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4102
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4103 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4104 <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
4105
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4106
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4107 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4108 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
4109 <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
4110 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
4111 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
4112
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4113
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4114 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4115 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
4116
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4117
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4121 <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
4122
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4123
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4124 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4125 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
4126 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
4127 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
4128 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
4129
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4130
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4131
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4134 <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
4135
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4136
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4137 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4138 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
4139 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
4140
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4141
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4142 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4143 For any valid displacement,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4144 the following identity holds:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4145
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4146 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4147 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
4148 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4149 In particular,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4150 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
4151
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4152
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4153
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4154
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4155 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4156 <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
4157
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4158
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4159 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4160 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
4161 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
4162 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
4163 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
4164 In particular,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4165 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
4166 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
4167
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4168
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4169 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4170 For positive displacements,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4171 the following equality holds:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4172
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4173 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4174 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
4175 </pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4176
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4177
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4178
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4179 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4180 <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
4181
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4182
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4183 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4184 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
4185 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
4186
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4187
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4188 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4189 For any valid displacement,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4190 the following identity holds:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4191
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4192 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4193 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
4194 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4195 In particular,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4196 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
4197
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4198
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4199
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4200
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4201 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4202 <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
4203
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4206 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
4207 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
4208 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
4209 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
4210 In particular,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4211 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
4212 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
4213
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4214
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4215 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4216 For positive displacements,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4217 the following equality holds:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4218
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4219 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4220 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
4221 </pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4222
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4223 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4224 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
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4231
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4232 <h2>6.8 &ndash; <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
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 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
4236 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
4237 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
4238 default output file,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4239 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
4240 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
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4244 When using implicit file descriptors,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4245 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
4246 When using explicit file descriptors,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4247 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
4248 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
4249
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4250
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4251 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4252 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
4253 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
4254 <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
4255 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
4256
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4257
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4258 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4259 Unless otherwise stated,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4260 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
4261 (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
4262 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
4263 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
4264 On non-Posix systems,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4265 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
4266 in case of errors
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4267 may be not thread safe,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4268 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
4269
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4272 <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
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4276 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
4277 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
4278
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4279
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4280
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4283 <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
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4287 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
4288
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4291
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4292 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4293 <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
4294
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4295
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4296 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4297 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
4298 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
4299 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
4300 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
4301 When called without parameters,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4302 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
4303
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4306 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
4307 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
4308
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4309
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4310
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4311
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4312 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4313 <hr><h3><a name="pdf-io.lines"><code>io.lines ([filename &middot;&middot;&middot;])</code></a></h3>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4314
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4315
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4316 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4317 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
4318 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
4319 works like <code>file:lines(&middot;&middot;&middot;)</code> over the opened file.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4320 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
4321 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
4322
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4323
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4324 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4325 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
4326 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
4327 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
4328 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
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4332 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
4333 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
4334
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4337
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4338 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4339 <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
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4343 This function opens a file,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4344 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
4345 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
4346 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
4347
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4348
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4349 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4350 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
4351
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4352 <ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4353 <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
4354 <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
4355 <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
4356 <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
4357 <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
4358 <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
4359 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
4360 </ul><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4361 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
4362 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
4363
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4364
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4365
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4366
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4367 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4368 <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
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4372 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
4373
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4374
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4375
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 <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
4379
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4382 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
4383 on all platforms.
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4386 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4387 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
4388 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
4389 (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
4390 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
4391 (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
4392
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4393
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4397 <hr><h3><a name="pdf-io.read"><code>io.read (&middot;&middot;&middot;)</code></a></h3>
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4400 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4401 Equivalent to <code>io.input():read(&middot;&middot;&middot;)</code>.
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4404
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4405
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4406 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4407 <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
4408
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4411 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
4412 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
4413 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
4414
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4415
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4416
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 <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
4420
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4421
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4422 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4423 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
4424 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
4425 <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
4426 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
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4432 <hr><h3><a name="pdf-io.write"><code>io.write (&middot;&middot;&middot;)</code></a></h3>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4433
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 Equivalent to <code>io.output():write(&middot;&middot;&middot;)</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4437
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4442 <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
4443
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4444
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4445 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4446 Closes <code>file</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4447 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
4448 their handles are garbage collected,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4449 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
4450
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4453 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
4454 <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
4455 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
4456
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4461 <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
4462
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4463
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4464 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4465 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
4466
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4467
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4468
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4469
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4470 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4471 <hr><h3><a name="pdf-file:lines"><code>file:lines (&middot;&middot;&middot;)</code></a></h3>
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4474 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4475 Returns an iterator function that,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4476 each time it is called,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4477 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
4478 When no format is given,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4479 uses "*l" as a default.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4480 As an example, the construction
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 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4483 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
4484 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4485 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
4486 starting at the current position.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4487 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
4488 when the loop ends.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4489
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4490
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4491 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4492 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
4493 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
4494
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4495
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4496
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4497
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4498 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4499 <hr><h3><a name="pdf-file:read"><code>file:read (&middot;&middot;&middot;)</code></a></h3>
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4503 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
4504 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
4505 For each format,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4506 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
4507 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
4508 When called without formats,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4509 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
4510 (see below).
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4513 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4514 The available formats are
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4515
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4516 <ul>
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 <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
4519 reads a number;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4520 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
4521 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4522
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4523 <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
4524 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
4525 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
4526 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4527
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4528 <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
4529 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
4530 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
4531 This is the default format.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4532 </li>
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 <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
4535 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
4536 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
4537 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4538
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4539 <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
4540 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
4541 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
4542 If number is zero,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4543 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
4544 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
4545 </li>
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 </ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4548
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4549
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4550
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4551 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4552 <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
4553
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4556 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
4557 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
4558 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
4559 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
4560
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4561 <ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4562 <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
4563 <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
4564 <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
4565 </ul><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4566 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
4567 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
4568 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
4569 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
4570
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4571
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4572 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4573 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
4574 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
4575 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
4576 file position, without changing it;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4577 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
4578 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
4579 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
4580 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
4581
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4582
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4583
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4586 <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
4587
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4588
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4589 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4590 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
4591 There are three available modes:
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 <ul>
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 <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
4596 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
4597 </li>
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 <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
4600 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
4601 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
4602 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
4603 </li>
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 <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
4606 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
4607 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
4608 (such as a terminal device).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4609 </li>
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 </ul><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4612 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
4613 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
4614 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
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4618
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4619 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4620 <hr><h3><a name="pdf-file:write"><code>file:write (&middot;&middot;&middot;)</code></a></h3>
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4624 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
4625 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
4626
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4627
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4628 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4629 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
4630 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
4631
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4632
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 <h2>6.9 &ndash; <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
4639
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4640 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4641 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
4642
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4643
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4644 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4645 <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
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4649 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
4650 used by the program.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4651
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4652
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4655 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4656 <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
4657
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4658
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4659 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4660 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
4661 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
4662
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4663
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4664 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4665 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
4666 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
4667 (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
4668 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
4669
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4670
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4671 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4672 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
4673 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
4674 After this optional character,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4675 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
4676 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
4677 <code>year</code> (four digits), <code>month</code> (1&ndash;12), <code>day</code> (1&ndash;31),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4678 <code>hour</code> (0&ndash;23), <code>min</code> (0&ndash;59), <code>sec</code> (0&ndash;61),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4679 <code>wday</code> (weekday, Sunday is&nbsp;1),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4680 <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
4681 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
4682 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
4683 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
4684
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4685
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4686 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4687 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
4688 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
4689 formatted according to the same rules as the ANSI&nbsp;C function <code>strftime</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4690
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4691
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4692 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4693 When called without arguments,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4694 <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
4695 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
4696 (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
4697
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4698
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4699 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4700 On non-Posix systems,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4701 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
4702 because of its reliance on C&nbsp;function <code>gmtime</code> and C&nbsp;function <code>localtime</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4703
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4704
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4705
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4708 <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
4709
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4710
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4711 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4712 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
4713 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
4714 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
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4718
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4719 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4720 <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
4721
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4722
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4723 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4724 This function is equivalent to the ANSI&nbsp;C function <code>system</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4725 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
4726 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
4727 if the command terminated successfully,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4728 or <b>nil</b> otherwise.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4729 After this first result
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4730 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
4731 as follows:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4732
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4733 <ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4734
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4735 <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
4736 the command terminated normally;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4737 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
4738 </li>
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 <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
4741 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
4742 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
4743 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4744
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4745 </ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4746
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4747 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4748 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
4749 <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
4750
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4751
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4752
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4753
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4754 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4755 <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
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4759 Calls the ANSI&nbsp;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
4760 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
4761 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
4762 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
4763 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
4764 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
4765 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
4766 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
4767
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4770 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
4771 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
4772
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4773
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4774
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4775
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4776 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4777 <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
4778
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4781 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
4782 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
4783
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4784
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4785
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4786
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4787 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4788 <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
4789
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4790
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4791 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4792 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
4793 with the given name.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4794 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
4795 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
4796
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4797
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4798
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4801 <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
4802
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4803
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4804 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4805 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
4806 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
4807 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
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4811
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4812 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4813 <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
4814
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4815
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4816 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4817 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
4818 <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
4819 <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
4820 <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
4821 <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
4822 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
4823 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
4824 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
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 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
4829 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
4830 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
4831 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
4832
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4833
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4834 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4835 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
4836 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
4837 for the given category.
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4841 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
4842 because of its reliance on C&nbsp;function <code>setlocale</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4843
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4846
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4847 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4848 <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
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4852 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
4853 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
4854 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
4855 and may have fields
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4856 <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
4857 <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
4858 <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
4859 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
4860 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
4861
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4864 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
4865 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
4866 this number counts the number
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4867 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
4868 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
4869 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
4870 <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
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4874
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4875 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4876 <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
4877
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4878
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4879 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4880 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
4881 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
4882 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
4883 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
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 On POSIX systems,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4888 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
4889 to avoid security risks.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4890 (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
4891 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
4892 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
4893 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
4894
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4895
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4896 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4897 When possible,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4898 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
4899 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
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4905
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4906
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4907 <h2>6.10 &ndash; <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
4908
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4909 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4910 This library provides
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4911 the functionality of the debug interface (<a href="#4.9">&sect;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
4912 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
4913 Several of its functions
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4914 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
4915 (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
4916 cannot be accessed from outside;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4917 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
4918 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
4919 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
4920 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
4921
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4922
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4923 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4924 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
4925 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
4926 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
4927 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
4928 thread to operate over.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4929 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
4930
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4931
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4932 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4933 <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
4934
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4935
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4936 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4937 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
4938 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
4939 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
4940 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
4941 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
4942 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
4943 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
4944
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4945
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4946 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4947 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
4948 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
4949
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4950
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4951
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4952
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4953 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4954 <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
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4958 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
4959 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
4960 and the current hook count
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4961 (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
4962
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4963
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4964
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4965
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4966 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4967 <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
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4971 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
4972 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
4973 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
4974 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
4975 of the given thread:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4976 level&nbsp;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
4977 level&nbsp;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
4978 (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
4979 and so on.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4980 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
4981 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
4982
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4983
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4984 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4985 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
4986 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
4987 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
4988 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
4989 If present,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4990 the option '<code>f</code>'
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4991 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
4992 If present,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4993 the option '<code>L</code>'
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4994 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
4995 valid lines.
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4998 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4999 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
5000 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
5001 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
5002 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
5003 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
5004 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
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5010 <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
5011
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5012
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5013 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5014 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
5015 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
5016 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
5017 but also parameters, temporaries, etc.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5018
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5019
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5020 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5021 The first parameter or local variable has index&nbsp;1, and so on,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5022 until the last active variable.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5023 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
5024 -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
5025 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
5026 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
5027 (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
5028
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5029
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5030 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5031 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
5032 represent internal variables
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5033 (loop control variables, temporaries, varargs, and C&nbsp;function locals).
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5037 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
5038 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
5039
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5042
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5043 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5044 <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
5045
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5046
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5047 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5048 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
5049 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
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5053
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5054 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5055 <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
5056
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 Returns the registry table (see <a href="#4.5">&sect;4.5</a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5060
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5061
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5062
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5063
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5064 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5065 <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
5066
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5067
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5068 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5069 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
5070 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
5071 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
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5077 <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
5078
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5079
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5080 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5081 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
5082 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
5083 returns <b>nil</b>.
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5086
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5087
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5088 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5089 <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
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5093 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
5094 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
5095 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
5096 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
5097 with the given meaning:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5098
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5099 <ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5100 <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
5101 <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
5102 <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
5103 </ul><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5104 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
5105 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
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5109 When called without arguments,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5110 <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
5111
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5112
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5113 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5114 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
5115 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
5116 <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
5117 <code>"return"</code>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5118 <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
5119 For line events,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5120 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
5121 Inside a hook,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5122 you can call <code>getinfo</code> with level&nbsp;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
5123 the running function
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5124 (level&nbsp;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
5125 and level&nbsp;1 is the hook function).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5126
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5127
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 <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
5132
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5133
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5134 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5135 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
5136 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
5137 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
5138 variable with the given index,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5139 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
5140 (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
5141 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
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5145 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
5146 variable indices and names.
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
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5151 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5152 <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
5153
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5154
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5155 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5156 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
5157 (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
5158 Returns <code>value</code>.
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5161
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5162
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5163 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5164 <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
5165
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5166
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5167 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5168 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
5169 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
5170 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
5171 with the given index.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5172 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
5173
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5174
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5175
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5176
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5177 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5178 <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
5179
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5180
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5181 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5182 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
5183 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
5184 <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
5185 <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
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 Returns <code>udata</code>.
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
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5194 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5195 <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
5196
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5197
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5198 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5199 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
5200 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
5201 Otherwise,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5202 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
5203 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
5204 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
5205 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
5206 to start the traceback
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5207 (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
5208
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5209
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5210
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5211
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5212 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5213 <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
5214
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5215
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5216 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5217 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
5218 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
5219 from the given function.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5220
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5221
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5222 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5223 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
5224 closures share upvalues.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5225 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
5226 (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
5227 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
5228
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5229
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5230
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5231
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5232 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5233 <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
5234
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5235
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5236 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5237 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
5238 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
5239
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5242
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5243
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5244
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5245
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5246 <h1>7 &ndash; <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
5247
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5248 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5249 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
5250 to be embedded in a host C&nbsp;program,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5251 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
5252 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
5253 called simply <code>lua</code>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5254 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
5255 The standalone interpreter includes
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5256 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
5257 Its usage is:
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 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5260 lua [options] [script [args]]
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5261 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5262 The options are:
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 <ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5265 <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
5266 <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
5267 <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
5268 <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
5269 <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
5270 <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
5271 <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
5272 </ul><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5273 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
5274 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
5275 When called without arguments,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5276 <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
5277 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
5278 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
5279
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 <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
5282 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
5283 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
5284 (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
5285 before running any argument.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5286 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
5287 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
5288 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
5289
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5290
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5291 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5292 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
5293 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
5294 Lua also ignores
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5295 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
5296 setting the values of
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5297 <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
5298 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
5299
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5300
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5301 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5302 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
5303 For instance, an invocation like
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 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5306 $ 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
5307 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5308 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
5309 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
5310 (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
5311
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5312
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5313 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5314 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
5315 <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
5316 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
5317 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
5318 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
5319 and so on.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5320 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
5321 (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
5322 go to negative indices.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5323 For instance, in the call
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5324
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5325 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5326 $ 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
5327 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5328 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
5329 then creates a table
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5330
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5331 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5332 arg = { [-2] = "lua", [-1] = "-la",
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5333 [0] = "b.lua",
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5334 [1] = "t1", [2] = "t2" }
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5335 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5336 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
5337 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
5338 as arguments;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5339 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
5340
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5343 In interactive mode,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5344 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
5345 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
5346 by issuing a different prompt.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5347
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5348
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5349 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5350 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
5351 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
5352 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
5353 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
5354 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
5355 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
5356 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
5357 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
5358
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5359
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5360 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5361 When finishing normally,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5362 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
5363 (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
5364 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
5365 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
5366
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5367
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5368 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5369 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
5370 script interpreter in Unix systems,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5371 the standalone interpreter skips
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5372 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
5373 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
5374 by using <code>chmod +x</code> and the&nbsp;<code>#!</code> form,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5375 as in
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 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5378 #!/usr/local/bin/lua
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5379 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5380 (Of course,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5381 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
5382 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
5383 then
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 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5386 #!/usr/bin/env lua
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5387 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5388 is a more portable solution.)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5389
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5390
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5391
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5392 <h1>8 &ndash; <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
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 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
5396 from Lua&nbsp;5.1 to Lua&nbsp;5.2.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5397 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
5398 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
5399 However,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5400 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
5401 Similarly,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5402 all features marked as deprecated in Lua&nbsp;5.1
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5403 have been removed in Lua&nbsp;5.2.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5404
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5405
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5406
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5407 <h2>8.1 &ndash; <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
5408 <ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5409
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5410 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5411 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
5412 Only Lua functions have environments.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5413 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
5414 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
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 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
5419 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
5420 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
5421 (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
5422 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
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5426 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
5427 (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
5428 use the new functions
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5429 <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
5430 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5431
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5432 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5433 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
5434 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5435
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5436 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5437 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
5438 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
5439 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5440
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5441 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5442 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
5443 </li>
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 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5446 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
5447 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
5448 <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
5449 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
5450 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5451
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5452 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5453 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
5454 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
5455 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
5456 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
5457 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5458
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5459 </ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5460
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5461
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5462
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5463
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5464 <h2>8.2 &ndash; <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
5465 <ul>
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 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5468 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
5469 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
5470 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
5471 </li>
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 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5474 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
5475 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
5476 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5477
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5478 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5479 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
5480 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
5481 </li>
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 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5484 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
5485 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
5486 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
5487 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5488
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5489 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5490 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
5491 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
5492 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5493
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5494 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5495 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
5496 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
5497 otherwise.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5498 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5499
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5500 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5501 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
5502 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
5503 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5504
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5505 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5506 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
5507 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
5508 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5509
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5510 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5511 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
5512 </li>
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 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5515 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
5516 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
5517 (<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
5518 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
5519 (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
5520 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
5521 When in doubt,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5522 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
5523 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
5524 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5525
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5526 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5527 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
5528 change between versions.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5529 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5530
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5531 </ul>
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5534
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5535
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5536 <h2>8.3 &ndash; <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
5537 <ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5538
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5539 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5540 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
5541 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
5542 (see <a href="#4.5">&sect;4.5</a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5543 </li>
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 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5546 Pseudoindex <code>LUA_ENVIRONINDEX</code>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5547 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
5548 were removed,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5549 as C&nbsp;functions no longer have environments.
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>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5553 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
5554 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
5555 (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
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>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5559 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
5560 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
5561 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
5562 (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
5563 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
5564 the block is new.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5565 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5566
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 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
5569 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
5570 not that they were created (see <a href="#2.5.1">&sect;2.5.1</a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5571 (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
5572 Moreover,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5573 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
5574 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
5575 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
5576 </li>
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 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5579 <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
5580 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
5581 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5582
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5583 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5584 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
5585 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
5586 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
5587 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5588
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5589 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5590 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
5591 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
5592 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5593
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5594 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5595 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
5596 </li>
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 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5599 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
5600 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
5601 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5602
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5603 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5604 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
5605 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
5606 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5607
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5608 </ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5609
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5610
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 <h1>9 &ndash; <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
5614
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5615 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5616 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
5617 (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
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5622 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5623
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5624 chunk ::= block
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5625
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5626 block ::= {stat} [retstat]
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5627
242
b5a926c481a5 Handle first h1 tag differently.
hugo.tech@gmail.com <hugo.tech@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 241
diff changeset
5628 stat ::= &lsquo;<b>;</b>&rsquo; |
b5a926c481a5 Handle first h1 tag differently.
hugo.tech@gmail.com <hugo.tech@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 241
diff changeset
5629 varlist &lsquo;<b>=</b>&rsquo; explist |
b5a926c481a5 Handle first h1 tag differently.
hugo.tech@gmail.com <hugo.tech@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 241
diff changeset
5630 functioncall |
b5a926c481a5 Handle first h1 tag differently.
hugo.tech@gmail.com <hugo.tech@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 241
diff changeset
5631 label |
b5a926c481a5 Handle first h1 tag differently.
hugo.tech@gmail.com <hugo.tech@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 241
diff changeset
5632 <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
5633 <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
5634 <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
5635 <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
5636 <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
5637 <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
5638 <b>for</b> Name &lsquo;<b>=</b>&rsquo; exp &lsquo;<b>,</b>&rsquo; exp [&lsquo;<b>,</b>&rsquo; 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
5639 <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
5640 <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
5641 <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
5642 <b>local</b> namelist [&lsquo;<b>=</b>&rsquo; explist]
239
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 retstat ::= <b>return</b> [explist] [&lsquo;<b>;</b>&rsquo;]
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5645
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5646 label ::= &lsquo;<b>::</b>&rsquo; Name &lsquo;<b>::</b>&rsquo;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5647
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5648 funcname ::= Name {&lsquo;<b>.</b>&rsquo; Name} [&lsquo;<b>:</b>&rsquo; Name]
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5649
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5650 varlist ::= var {&lsquo;<b>,</b>&rsquo; var}
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5651
242
b5a926c481a5 Handle first h1 tag differently.
hugo.tech@gmail.com <hugo.tech@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 241
diff changeset
5652 var ::= Name | prefixexp &lsquo;<b>[</b>&rsquo; exp &lsquo;<b>]</b>&rsquo; | prefixexp &lsquo;<b>.</b>&rsquo; Name
239
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 namelist ::= Name {&lsquo;<b>,</b>&rsquo; Name}
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 explist ::= exp {&lsquo;<b>,</b>&rsquo; exp}
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5657
242
b5a926c481a5 Handle first h1 tag differently.
hugo.tech@gmail.com <hugo.tech@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 241
diff changeset
5658 exp ::= <b>nil</b> | <b>false</b> | <b>true</b> | Number | String | &lsquo;<b>...</b>&rsquo; | functiondef |
b5a926c481a5 Handle first h1 tag differently.
hugo.tech@gmail.com <hugo.tech@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 241
diff changeset
5659 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
5660
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5661 prefixexp ::= var | functioncall | &lsquo;<b>(</b>&rsquo; exp &lsquo;<b>)</b>&rsquo;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5662
242
b5a926c481a5 Handle first h1 tag differently.
hugo.tech@gmail.com <hugo.tech@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 241
diff changeset
5663 functioncall ::= prefixexp args | prefixexp &lsquo;<b>:</b>&rsquo; 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
5664
b5a926c481a5 Handle first h1 tag differently.
hugo.tech@gmail.com <hugo.tech@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 241
diff changeset
5665 args ::= &lsquo;<b>(</b>&rsquo; [explist] &lsquo;<b>)</b>&rsquo; | tableconstructor | String
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5666
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5667 functiondef ::= <b>function</b> funcbody
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5668
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5669 funcbody ::= &lsquo;<b>(</b>&rsquo; [parlist] &lsquo;<b>)</b>&rsquo; block <b>end</b>
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 parlist ::= namelist [&lsquo;<b>,</b>&rsquo; &lsquo;<b>...</b>&rsquo;] | &lsquo;<b>...</b>&rsquo;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5672
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5673 tableconstructor ::= &lsquo;<b>{</b>&rsquo; [fieldlist] &lsquo;<b>}</b>&rsquo;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5674
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5675 fieldlist ::= field {fieldsep field} [fieldsep]
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 field ::= &lsquo;<b>[</b>&rsquo; exp &lsquo;<b>]</b>&rsquo; &lsquo;<b>=</b>&rsquo; exp | Name &lsquo;<b>=</b>&rsquo; exp | exp
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5678
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5679 fieldsep ::= &lsquo;<b>,</b>&rsquo; | &lsquo;<b>;</b>&rsquo;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5680
242
b5a926c481a5 Handle first h1 tag differently.
hugo.tech@gmail.com <hugo.tech@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 241
diff changeset
5681 binop ::= &lsquo;<b>+</b>&rsquo; | &lsquo;<b>-</b>&rsquo; | &lsquo;<b>*</b>&rsquo; | &lsquo;<b>/</b>&rsquo; | &lsquo;<b>^</b>&rsquo; | &lsquo;<b>%</b>&rsquo; | &lsquo;<b>..</b>&rsquo; |
b5a926c481a5 Handle first h1 tag differently.
hugo.tech@gmail.com <hugo.tech@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 241
diff changeset
5682 &lsquo;<b>&lt;</b>&rsquo; | &lsquo;<b>&lt;=</b>&rsquo; | &lsquo;<b>&gt;</b>&rsquo; | &lsquo;<b>&gt;=</b>&rsquo; | &lsquo;<b>==</b>&rsquo; | &lsquo;<b>~=</b>&rsquo; |
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5683 <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
5684
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5685 unop ::= &lsquo;<b>-</b>&rsquo; | <b>not</b> | &lsquo;<b>#</b>&rsquo;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5686
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5687 </pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5688
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5689 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5690
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5694
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5695
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5696
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5697 <HR>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5698 <SMALL CLASS="footer">
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5699 Last update:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5700 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
5701 </SMALL>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5702 <!--
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5703 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
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 </body></html>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5707