annotate docs/manual.html @ 240:bcc3911285a2

add manual css files git-svn-id: https://luan-java.googlecode.com/svn/trunk@241 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Mon, 06 Oct 2014 22:27:24 +0000
parents aa7bc9c1df22
children 852840d64a7f
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>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5 <title>Lua 5.2 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>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
14 <h1>
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>
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
69 </UL>
240
bcc3911285a2 add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 239
diff changeset
70 <LI><A HREF="#3.4">3.4 &ndash; Expressions</A>
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
71 <UL>
240
bcc3911285a2 add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 239
diff changeset
72 <LI><A HREF="#3.4.1">3.4.1 &ndash; Arithmetic Operators</A>
bcc3911285a2 add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 239
diff changeset
73 <LI><A HREF="#3.4.2">3.4.2 &ndash; Coercion</A>
bcc3911285a2 add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 239
diff changeset
74 <LI><A HREF="#3.4.3">3.4.3 &ndash; Relational Operators</A>
bcc3911285a2 add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 239
diff changeset
75 <LI><A HREF="#3.4.4">3.4.4 &ndash; Logical Operators</A>
bcc3911285a2 add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 239
diff changeset
76 <LI><A HREF="#3.4.5">3.4.5 &ndash; Concatenation</A>
bcc3911285a2 add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 239
diff changeset
77 <LI><A HREF="#3.4.6">3.4.6 &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
78 <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
79 <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
80 <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
81 <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
82 </UL>
240
bcc3911285a2 add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 239
diff changeset
83 <LI><A HREF="#3.5">3.5 &ndash; Visibility Rules</A>
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
84 </UL>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
85 <P>
240
bcc3911285a2 add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 239
diff changeset
86 <LI><A HREF="#4">4 &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
87 <UL>
240
bcc3911285a2 add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 239
diff changeset
88 <LI><A HREF="#4.1">4.1 &ndash; The Stack</A>
bcc3911285a2 add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 239
diff changeset
89 <LI><A HREF="#4.2">4.2 &ndash; Stack Size</A>
bcc3911285a2 add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 239
diff changeset
90 <LI><A HREF="#4.3">4.3 &ndash; Valid and Acceptable Indices</A>
bcc3911285a2 add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 239
diff changeset
91 <LI><A HREF="#4.4">4.4 &ndash; C Closures</A>
bcc3911285a2 add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 239
diff changeset
92 <LI><A HREF="#4.5">4.5 &ndash; Registry</A>
bcc3911285a2 add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 239
diff changeset
93 <LI><A HREF="#4.6">4.6 &ndash; Error Handling in C</A>
bcc3911285a2 add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 239
diff changeset
94 <LI><A HREF="#4.7">4.7 &ndash; Handling Yields in C</A>
bcc3911285a2 add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 239
diff changeset
95 <LI><A HREF="#4.8">4.8 &ndash; Functions and Types</A>
bcc3911285a2 add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 239
diff changeset
96 <LI><A HREF="#4.9">4.9 &ndash; The Debug Interface</A>
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
97 </UL>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
98 <P>
240
bcc3911285a2 add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 239
diff changeset
99 <LI><A HREF="#5">5 &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
100 <UL>
240
bcc3911285a2 add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 239
diff changeset
101 <LI><A HREF="#5.1">5.1 &ndash; Functions and Types</A>
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
102 </UL>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
103 <P>
240
bcc3911285a2 add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 239
diff changeset
104 <LI><A HREF="#6">6 &ndash; Standard Libraries</A>
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
105 <UL>
240
bcc3911285a2 add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 239
diff changeset
106 <LI><A HREF="#6.1">6.1 &ndash; Basic Functions</A>
bcc3911285a2 add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 239
diff changeset
107 <LI><A HREF="#6.2">6.2 &ndash; Coroutine Manipulation</A>
bcc3911285a2 add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 239
diff changeset
108 <LI><A HREF="#6.3">6.3 &ndash; Modules</A>
bcc3911285a2 add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 239
diff changeset
109 <LI><A HREF="#6.4">6.4 &ndash; String Manipulation</A>
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
110 <UL>
240
bcc3911285a2 add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 239
diff changeset
111 <LI><A HREF="#6.4.1">6.4.1 &ndash; Patterns</A>
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
112 </UL>
240
bcc3911285a2 add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 239
diff changeset
113 <LI><A HREF="#6.5">6.5 &ndash; Table Manipulation</A>
bcc3911285a2 add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 239
diff changeset
114 <LI><A HREF="#6.6">6.6 &ndash; Mathematical Functions</A>
bcc3911285a2 add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 239
diff changeset
115 <LI><A HREF="#6.7">6.7 &ndash; Bitwise Operations</A>
bcc3911285a2 add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 239
diff changeset
116 <LI><A HREF="#6.8">6.8 &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
117 <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
118 <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
119 </UL>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
120 <P>
240
bcc3911285a2 add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 239
diff changeset
121 <LI><A HREF="#7">7 &ndash; Lua Standalone</A>
239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
122 <P>
240
bcc3911285a2 add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 239
diff changeset
123 <LI><A HREF="#8">8 &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
124 <UL>
240
bcc3911285a2 add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 239
diff changeset
125 <LI><A HREF="#8.1">8.1 &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
126 <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
127 <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
128 </UL>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
129 <P>
240
bcc3911285a2 add manual css files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 239
diff changeset
130 <LI><A HREF="#9">9 &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
131 </UL>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
132
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
133
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
134 <h1>1 &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
135
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
136 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
137 Lua is an extension programming language designed to support
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
138 general procedural programming with data description
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
139 facilities.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
140 It also offers good support for object-oriented programming,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
141 functional programming, and data-driven programming.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
142 Lua is intended to be used as a powerful, lightweight,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
143 embeddable scripting language for any program that needs one.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
144 Lua is implemented as a library, written in <em>clean C</em>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
145 the common subset of Standard&nbsp;C and C++.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
146
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
147
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
148 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
149 Being an extension language, Lua has no notion of a "main" program:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
150 it only works <em>embedded</em> in a host client,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
151 called the <em>embedding program</em> or simply the <em>host</em>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
152 The host program can invoke functions to execute a piece of Lua code,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
153 can write and read Lua variables,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
154 and can register C&nbsp;functions to be called by Lua code.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
155 Through the use of C&nbsp;functions, Lua can be augmented to cope with
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
156 a wide range of different domains,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
157 thus creating customized programming languages sharing a syntactical framework.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
158 The Lua distribution includes a sample host program called <code>lua</code>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
159 which uses the Lua library to offer a complete, standalone Lua interpreter,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
160 for interactive or batch use.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
161
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
162
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
163 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
164 Lua is free software,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
165 and is provided as usual with no guarantees,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
166 as stated in its license.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
167 The implementation described in this manual is available
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
168 at Lua's official web site, <code>www.lua.org</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
169
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
170
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
171 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
172 Like any other reference manual,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
173 this document is dry in places.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
174 For a discussion of the decisions behind the design of Lua,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
175 see the technical papers available at Lua's web site.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
176 For a detailed introduction to programming in Lua,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
177 see Roberto's book, <em>Programming in Lua</em>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
178
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
179
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
180 <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
181
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
182 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
183 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
184
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
185
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
186
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
187 <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
188
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
189 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
190 Lua is a <em>dynamically typed language</em>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
191 This means that
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
192 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
193 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
194 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
195
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
198 All values in Lua are <em>first-class values</em>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
199 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
200 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
201
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
202
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
203 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
204 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
205 <em>nil</em>, <em>boolean</em>, <em>number</em>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
206 <em>string</em>, <em>function</em>, <em>userdata</em>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
207 <em>thread</em>, and <em>table</em>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
208 <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
209 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
210 it usually represents the absence of a useful value.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
211 <em>Boolean</em> is the type of the values <b>false</b> and <b>true</b>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
212 Both <b>nil</b> and <b>false</b> make a condition false;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
213 any other value makes it true.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
214 <em>Number</em> represents real (double-precision floating-point) numbers.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
215 Operations on numbers follow the same rules of
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
216 the underlying C&nbsp;implementation,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
217 which, in turn, usually follows the IEEE 754 standard.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
218 (It is easy to build Lua interpreters that use other
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
219 internal representations for numbers,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
220 such as single-precision floats or long integers;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
221 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
222 <em>String</em> represents immutable sequences of bytes.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
223
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
224 Lua is 8-bit clean:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
225 strings can contain any 8-bit value,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
226 including embedded zeros ('<code>\0</code>').
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
227
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
228
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
229 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
230 Lua can call (and manipulate) functions written in Lua and
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
231 functions written in C
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
232 (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
233
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
234
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
235 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
236 The type <em>userdata</em> is provided to allow arbitrary C&nbsp;data to
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
237 be stored in Lua variables.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
238 A userdata value is a pointer to a block of raw memory.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
239 There are two kinds of userdata:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
240 full userdata, where the block of memory is managed by Lua,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
241 and light userdata, where the block of memory is managed by the host.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
242 Userdata has no predefined operations in Lua,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
243 except assignment and identity test.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
244 By using <em>metatables</em>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
245 the programmer can define operations for full userdata values
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
246 (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
247 Userdata values cannot be created or modified in Lua,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
248 only through the C&nbsp;API.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
249 This guarantees the integrity of data owned by the host program.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
250
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
251
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
252 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
253 The type <em>thread</em> represents independent threads of execution
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
254 and it is used to implement coroutines (see <a href="#2.6">&sect;2.6</a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
255 Do not confuse Lua threads with operating-system threads.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
256 Lua supports coroutines on all systems,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
257 even those that do not support threads.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
258
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
259
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
260 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
261 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
262 that is, arrays that can be indexed not only with numbers,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
263 but with any Lua value except <b>nil</b> and NaN
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
264 (<em>Not a Number</em>, a special numeric value used to represent
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
265 undefined or unrepresentable results, such as <code>0/0</code>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
266 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
267 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
268 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
269 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
270 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
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 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
275 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
276 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
277 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
278 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
279 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
280 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
281 (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
282
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
283
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
284 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
285 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
286 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
287 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
288 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
289
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
290
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
291 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
292 Like indices,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
293 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
294 In particular,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
295 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
296 table fields can contain functions.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
297 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
298
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
299
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
300 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
301 The indexing of tables follows
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
302 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
303 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
304 denote the same table element
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
305 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
306 (that is, equal without metamethods).
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
309 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
310 Tables, functions, threads, and (full) userdata values are <em>objects</em>:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
311 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
312 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
313 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
314 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
315 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
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 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
320 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
321
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
322
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
323
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
324
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
325
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
326 <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
327
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
328 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
329 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
330 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
331 to <code>_ENV.var</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
332 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
333 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
334 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
335
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
336
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
337 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
338 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
339 the translation of global names,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
340 <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
341 In particular,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
342 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
343 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
344 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
345 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
346
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
347
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
348 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
349 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
350
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
353 Lua keeps a distinguished environment called the <em>global environment</em>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
354 This value is kept at a special index in the C registry (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
355 In Lua, the variable <a href="#pdf-_G"><code>_G</code></a> is initialized with this same value.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
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 When Lua compiles a chunk,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
360 it initializes the value of its <code>_ENV</code> upvalue
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
361 with the global environment (see <a href="#pdf-load"><code>load</code></a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
362 Therefore, by default,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
363 global variables in Lua code refer to entries in the global environment.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
364 Moreover, all standard libraries are loaded in the global environment
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
365 and several functions there operate on that environment.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
366 You can use <a href="#pdf-load"><code>load</code></a> (or <a href="#pdf-loadfile"><code>loadfile</code></a>)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
367 to load a chunk with a different environment.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
368 (In C, you have to load the chunk and then change the value
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
369 of its first upvalue.)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
370
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
371
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
372 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
373 If you change the global environment in the registry
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
374 (through C code or the debug library),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
375 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
376 Previously loaded chunks are not affected, however,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
377 as each has its own reference to the environment in its <code>_ENV</code> variable.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
378 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
379 (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
380 is never updated by Lua.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
381
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
382
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
383
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
384
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
385
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
386 <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
387
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
388 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
389 Because Lua is an embedded extension language,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
390 all Lua actions start from C&nbsp;code in the host program
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
391 calling a function from the Lua library (see <a href="#lua_pcall"><code>lua_pcall</code></a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
392 Whenever an error occurs during
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
393 the compilation or execution of a Lua chunk,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
394 control returns to the host,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
395 which can take appropriate measures
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
396 (such as printing an error message).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
397
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
400 Lua code can explicitly generate an error by calling the
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
401 <a href="#pdf-error"><code>error</code></a> function.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
402 If you need to catch errors in Lua,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
403 you can use <a href="#pdf-pcall"><code>pcall</code></a> or <a href="#pdf-xpcall"><code>xpcall</code></a>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
404 to call a given function in <em>protected mode</em>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
405
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
406
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
407 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
408 Whenever there is an error,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
409 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
410 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
411 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
412 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
413 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
414
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
417 When you use <a href="#pdf-xpcall"><code>xpcall</code></a> or <a href="#lua_pcall"><code>lua_pcall</code></a>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
418 you may give a <em>message handler</em>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
419 to be called in case of errors.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
420 This function is called with the original error message
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
421 and returns a new error message.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
422 It is called before the error unwinds the stack,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
423 so that it can gather more information about the error,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
424 for instance by inspecting the stack and creating a stack traceback.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
425 This message handler is still protected by the protected call;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
426 so, an error inside the message handler
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
427 will call the message handler again.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
428 If this loop goes on, Lua breaks it and returns an appropriate message.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
429
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
430
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
431
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
432
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
433
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
434 <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
435
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
436 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
437 Every value in Lua can have a <em>metatable</em>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
438 This <em>metatable</em> is an ordinary Lua table
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
439 that defines the behavior of the original value
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
440 under certain special operations.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
441 You can change several aspects of the behavior
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
442 of operations over a value by setting specific fields in its metatable.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
443 For instance, when a non-numeric value is the operand of an addition,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
444 Lua checks for a function in the field "<code>__add</code>" of the value's metatable.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
445 If it finds one,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
446 Lua calls this function to perform the addition.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
447
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
448
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
449 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
450 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
451 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
452 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
453 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
454
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
455
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
456 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
457 You can query the metatable of any value
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
458 using the <a href="#pdf-getmetatable"><code>getmetatable</code></a> function.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
459
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
460
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
461 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
462 You can replace the metatable of tables
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
463 using the <a href="#pdf-setmetatable"><code>setmetatable</code></a> function.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
464 You cannot change the metatable of other types from Lua
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
465 (except by using the debug library);
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
466 you must use the C&nbsp;API for that.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
467
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
468
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
469 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
470 Tables and full userdata have individual metatables
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
471 (although multiple tables and userdata can share their metatables).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
472 Values of all other types share one single metatable per type;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
473 that is, there is one single metatable for all numbers,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
474 one for all strings, etc.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
475 By default, a value has no metatable,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
476 but the string library sets a metatable for the string type (see <a href="#6.4">&sect;6.4</a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
477
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
478
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
479 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
480 A metatable controls how an object behaves in arithmetic operations,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
481 order comparisons, concatenation, length operation, and indexing.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
482 A metatable also can define a function to be called
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
483 when a userdata or a table is garbage collected.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
484 When Lua performs one of these operations over a value,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
485 it checks whether this value has a metatable with the corresponding event.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
486 If so, the value associated with that key (the metamethod)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
487 controls how Lua will perform the operation.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
488
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
489
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
490 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
491 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
492 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
493 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
494 two underscores, '<code>__</code>';
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
495 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
496 string "<code>__add</code>".
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
497
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
498
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
499 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
500 The semantics of these operations is better explained by a Lua function
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
501 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
502 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
503 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
504 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
505 All functions used in these descriptions
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
506 (<a href="#pdf-rawget"><code>rawget</code></a>, <a href="#pdf-tonumber"><code>tonumber</code></a>, etc.)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
507 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
508 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
509 we use the expression
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 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
512 metatable(obj)[event]
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
513 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
514 This should be read as
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
515
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
516 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
517 rawget(getmetatable(obj) or {}, event)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
518 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
519 This means that the access to a metamethod does not invoke other metamethods,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
520 and access to objects with no metatables does not fail
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
521 (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
522
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
523
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
524 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
525 For the unary <code>-</code> and <code>#</code> operators,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
526 the metamethod is called with a dummy second argument.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
527 This extra argument is only to simplify Lua's internals;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
528 it may be removed in future versions and therefore it is not present
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
529 in the following code.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
530 (For most uses this extra argument is irrelevant.)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
531
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
532
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
533
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
534 <ul>
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 <li><b>"add": </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
537 the <code>+</code> operation.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
538
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
539
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
540
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
541 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
542 The function <code>getbinhandler</code> below defines how Lua chooses a handler
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
543 for a binary operation.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
544 First, Lua tries the first operand.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
545 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
546 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
547
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
548 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
549 function getbinhandler (op1, op2, event)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
550 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
551 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
552 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
553 By using this function,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
554 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
555
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
556 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
557 function add_event (op1, op2)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
558 local o1, o2 = tonumber(op1), tonumber(op2)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
559 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
560 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
561 else -- at least one of the operands is not numeric
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
562 local h = getbinhandler(op1, op2, "__add")
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
563 if h then
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
564 -- 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
565 return (h(op1, op2))
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
566 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
567 error(&middot;&middot;&middot;)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
568 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
569 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
570 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
571 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
572 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
573
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
574 <li><b>"sub": </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
575 the <code>-</code> operation.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
576
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
577 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
578 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
579
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
580 <li><b>"mul": </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
581 the <code>*</code> operation.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
582
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
583 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
584 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
585
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
586 <li><b>"div": </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
587 the <code>/</code> operation.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
588
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
589 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
590 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
591
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
592 <li><b>"mod": </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
593 the <code>%</code> operation.
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 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
596 with the operation
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
597 <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
598 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
599
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
600 <li><b>"pow": </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
601 the <code>^</code> (exponentiation) operation.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
602
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
603 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
604 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
605 as the primitive operation.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
606 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
607
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
608 <li><b>"unm": </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
609 the unary <code>-</code> operation.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
610
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
611
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
612 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
613 function unm_event (op)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
614 local o = tonumber(op)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
615 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
616 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
617 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
618 -- 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
619 local h = metatable(op).__unm
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
620 if h then
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
621 -- 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
622 return (h(op))
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
623 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
624 error(&middot;&middot;&middot;)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
625 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
626 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
627 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
628 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
629 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
630
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
631 <li><b>"concat": </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
632 the <code>..</code> (concatenation) operation.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
633
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
634
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
635 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
636 function concat_event (op1, op2)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
637 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
638 (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
639 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
640 else
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
641 local h = getbinhandler(op1, op2, "__concat")
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
642 if h then
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
643 return (h(op1, op2))
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
644 else
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
645 error(&middot;&middot;&middot;)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
646 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
647 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
648 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
649 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
650 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
651
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
652 <li><b>"len": </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
653 the <code>#</code> operation.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
654
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
655
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
656 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
657 function len_event (op)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
658 if type(op) == "string" then
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
659 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
660 else
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
661 local h = metatable(op).__len
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
662 if h then
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
663 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
664 elseif type(op) == "table" then
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
665 return #op -- primitive table length
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
666 else -- no handler available: error
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
667 error(&middot;&middot;&middot;)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
668 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
669 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
670 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
671 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
672 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
673 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
674
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
675 <li><b>"eq": </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
676 the <code>==</code> operation.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
677
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
678 The function <code>getequalhandler</code> defines how Lua chooses a metamethod
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
679 for equality.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
680 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
681 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
682 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
683 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
684
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
685 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
686 function getequalhandler (op1, op2)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
687 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
688 (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
689 return nil -- different values
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
690 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
691 local mm1 = metatable(op1).__eq
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
692 local mm2 = metatable(op2).__eq
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
693 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
694 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
695 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
696 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
697
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
698 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
699 function eq_event (op1, op2)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
700 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
701 return true -- values are equal
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
702 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
703 -- try metamethod
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
704 local h = getequalhandler(op1, op2)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
705 if h then
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
706 return not not h(op1, op2)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
707 else
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
708 return false
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 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
713 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
714
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
715 <li><b>"lt": </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
716 the <code>&lt;</code> operation.
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
719 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
720 function lt_event (op1, op2)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
721 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
722 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
723 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
724 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
725 else
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
726 local h = getbinhandler(op1, op2, "__lt")
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
727 if h then
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
728 return not not h(op1, op2)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
729 else
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
730 error(&middot;&middot;&middot;)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
731 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
732 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
733 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
734 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
735 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
736 </li>
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 <li><b>"le": </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
739 the <code>&lt;=</code> operation.
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
742 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
743 function le_event (op1, op2)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
744 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
745 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
746 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
747 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
748 else
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
749 local h = getbinhandler(op1, op2, "__le")
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
750 if h then
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
751 return not not h(op1, op2)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
752 else
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
753 h = getbinhandler(op1, op2, "__lt")
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
754 if h then
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
755 return not h(op2, op1)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
756 else
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
757 error(&middot;&middot;&middot;)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
758 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
759 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
760 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
761 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
762 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
763 Note that, in the absence of a "le" metamethod,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
764 Lua tries the "lt", assuming that <code>a &lt;= b</code> is
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
765 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
766
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
769 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
770 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
771 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
772
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
773 <li><b>"index": </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
774 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
775 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
776 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
777 (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
778 no key is ever present,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
779 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
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 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
783 function gettable_event (table, key)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
784 local h
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
785 if type(table) == "table" then
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
786 local v = rawget(table, key)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
787 -- 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
788 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
789 h = metatable(table).__index
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
790 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
791 else
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
792 h = metatable(table).__index
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
793 if h == nil then
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
794 error(&middot;&middot;&middot;)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
795 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
796 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
797 if type(h) == "function" then
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
798 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
799 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
800 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
801 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
802 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
803 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
804
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
805 <li><b>"newindex": </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
806 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
807 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
808 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
809
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
810
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
811 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
812 function settable_event (table, key, value)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
813 local h
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
814 if type(table) == "table" then
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
815 local v = rawget(table, key)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
816 -- if key is present, do raw assignment
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
817 if v ~= nil then rawset(table, key, value); return end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
818 h = metatable(table).__newindex
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
819 if h == nil then rawset(table, key, value); return end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
820 else
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
821 h = metatable(table).__newindex
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
822 if h == nil then
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
823 error(&middot;&middot;&middot;)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
824 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
825 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
826 if type(h) == "function" then
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
827 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
828 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
829 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
830 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
831 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
832 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
833
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
834 <li><b>"call": </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
835 called when Lua calls a value.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
836
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 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
839 function function_event (func, ...)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
840 if type(func) == "function" then
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
841 return func(...) -- primitive call
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
842 else
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
843 local h = metatable(func).__call
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
844 if h then
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
845 return h(func, ...)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
846 else
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
847 error(&middot;&middot;&middot;)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
848 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
849 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
850 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
851 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
852 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
853
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
854 </ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
855
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
856
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
857
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
858
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
859 <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
860
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
861 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
862 Lua performs automatic memory management.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
863 This means that
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
864 you have to worry neither about allocating memory for new objects
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
865 nor about freeing it when the objects are no longer needed.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
866 Lua manages memory automatically by running
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
867 a <em>garbage collector</em> to collect all <em>dead objects</em>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
868 (that is, objects that are no longer accessible from Lua).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
869 All memory used by Lua is subject to automatic management:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
870 strings, tables, userdata, functions, threads, internal structures, etc.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
871
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
872
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
873 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
874 Lua implements an incremental mark-and-sweep collector.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
875 It uses two numbers to control its garbage-collection cycles:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
876 the <em>garbage-collector pause</em> and
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
877 the <em>garbage-collector step multiplier</em>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
878 Both use percentage points as units
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
879 (e.g., a value of 100 means an internal value of 1).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
880
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
881
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
882 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
883 The garbage-collector pause
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
884 controls how long the collector waits before starting a new cycle.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
885 Larger values make the collector less aggressive.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
886 Values smaller than 100 mean the collector will not wait to
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
887 start a new cycle.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
888 A value of 200 means that the collector waits for the total memory in use
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
889 to double before starting a new cycle.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
890
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
891
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
892 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
893 The garbage-collector step multiplier
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
894 controls the relative speed of the collector relative to
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
895 memory allocation.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
896 Larger values make the collector more aggressive but also increase
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
897 the size of each incremental step.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
898 Values smaller than 100 make the collector too slow and
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
899 can result in the collector never finishing a cycle.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
900 The default is 200,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
901 which means that the collector runs at "twice"
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
902 the speed of memory allocation.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
903
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
904
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
905 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
906 If you set the step multiplier to a very large number
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
907 (larger than 10% of the maximum number of
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
908 bytes that the program may use),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
909 the collector behaves like a stop-the-world collector.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
910 If you then set the pause to 200,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
911 the collector behaves as in old Lua versions,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
912 doing a complete collection every time Lua doubles its
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
913 memory usage.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
914
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
915
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
916 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
917 You can change these numbers by calling <a href="#lua_gc"><code>lua_gc</code></a> in C
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
918 or <a href="#pdf-collectgarbage"><code>collectgarbage</code></a> in Lua.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
919 You can also use these functions to control
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
920 the collector directly (e.g., stop and restart it).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
921
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 As an experimental feature in Lua 5.2,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
925 you can change the collector's operation mode
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
926 from incremental to <em>generational</em>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
927 A <em>generational collector</em> assumes that most objects die young,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
928 and therefore it traverses only young (recently created) objects.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
929 This behavior can reduce the time used by the collector,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
930 but also increases memory usage (as old dead objects may accumulate).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
931 To mitigate this second problem,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
932 from time to time the generational collector performs a full collection.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
933 Remember that this is an experimental feature;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
934 you are welcome to try it,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
935 but check your gains.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
936
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
937
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
938
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
939 <h3>2.5.1 &ndash; <a name="2.5.1">Garbage-Collection Metamethods</a></h3>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
940
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
941 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
942 You can set garbage-collector metamethods for tables
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
943 and, using the C&nbsp;API,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
944 for full userdata (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
945 These metamethods are also called <em>finalizers</em>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
946 Finalizers allow you to coordinate Lua's garbage collection
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
947 with external resource management
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
948 (such as closing files, network or database connections,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
949 or freeing your own memory).
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
953 For an object (table or userdata) to be finalized when collected,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
954 you must <em>mark</em> it for finalization.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
955
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
956 You mark an object for finalization when you set its metatable
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
957 and the metatable has a field indexed by the string "<code>__gc</code>".
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
958 Note that if you set a metatable without a <code>__gc</code> field
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
959 and later create that field in the metatable,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
960 the object will not be marked for finalization.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
961 However, after an object is marked,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
962 you can freely change the <code>__gc</code> field of its metatable.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
963
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
964
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
965 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
966 When a marked object becomes garbage,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
967 it is not collected immediately by the garbage collector.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
968 Instead, Lua puts it in a list.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
969 After the collection,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
970 Lua does the equivalent of the following function
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
971 for each object in that list:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
972
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
973 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
974 function gc_event (obj)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
975 local h = metatable(obj).__gc
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
976 if type(h) == "function" then
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
977 h(obj)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
978 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
979 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
980 </pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
981
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
982 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
983 At the end of each garbage-collection cycle,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
984 the finalizers for objects are called in
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
985 the reverse order that they were marked for collection,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
986 among those collected in that cycle;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
987 that is, the first finalizer to be called is the one associated
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
988 with the object marked last in the program.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
989 The execution of each finalizer may occur at any point during
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
990 the execution of the regular code.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
991
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
992
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
993 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
994 Because the object being collected must still be used by the finalizer,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
995 it (and other objects accessible only through it)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
996 must be <em>resurrected</em> by Lua.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
997 Usually, this resurrection is transient,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
998 and the object memory is freed in the next garbage-collection cycle.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
999 However, if the finalizer stores the object in some global place
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1000 (e.g., a global variable),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1001 then there is a permanent resurrection.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1002 In any case,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1003 the object memory is freed only when it becomes completely inaccessible;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1004 its finalizer will never be called twice.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1005
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 When you close a state (see <a href="#lua_close"><code>lua_close</code></a>),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1009 Lua calls the finalizers of all objects marked for finalization,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1010 following the reverse order that they were marked.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1011 If any finalizer marks new objects for collection during that phase,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1012 these new objects will not be finalized.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1018 <h3>2.5.2 &ndash; <a name="2.5.2">Weak Tables</a></h3>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1019
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1020 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1021 A <em>weak table</em> is a table whose elements are
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1022 <em>weak references</em>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1023 A weak reference is ignored by the garbage collector.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1024 In other words,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1025 if the only references to an object are weak references,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1026 then the garbage collector will collect that object.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1027
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1028
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1029 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1030 A weak table can have weak keys, weak values, or both.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1031 A table with weak keys allows the collection of its keys,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1032 but prevents the collection of its values.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1033 A table with both weak keys and weak values allows the collection of
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1034 both keys and values.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1035 In any case, if either the key or the value is collected,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1036 the whole pair is removed from the table.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1037 The weakness of a table is controlled by the
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1038 <code>__mode</code> field of its metatable.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1039 If the <code>__mode</code> field is a string containing the character&nbsp;'<code>k</code>',
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1040 the keys in the table are weak.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1041 If <code>__mode</code> contains '<code>v</code>',
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1042 the values in the table are weak.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1043
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1044
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1045 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1046 A table with weak keys and strong values
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1047 is also called an <em>ephemeron table</em>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1048 In an ephemeron table,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1049 a value is considered reachable only if its key is reachable.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1050 In particular,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1051 if the only reference to a key comes through its value,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1052 the pair is removed.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1053
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1054
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1055 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1056 Any change in the weakness of a table may take effect only
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1057 at the next collect cycle.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1058 In particular, if you change the weakness to a stronger mode,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1059 Lua may still collect some items from that table
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1060 before the change takes effect.
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1063 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1064 Only objects that have an explicit construction
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1065 are removed from weak tables.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1066 Values, such as numbers and light C functions,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1067 are not subject to garbage collection,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1068 and therefore are not removed from weak tables
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1069 (unless its associated value is collected).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1070 Although strings are subject to garbage collection,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1071 they do not have an explicit construction,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1072 and therefore are not removed from weak tables.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1073
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1074
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1075 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1076 Resurrected objects
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1077 (that is, objects being finalized
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1078 and objects accessible only through objects being finalized)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1079 have a special behavior in weak tables.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1080 They are removed from weak values before running their finalizers,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1081 but are removed from weak keys only in the next collection
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1082 after running their finalizers, when such objects are actually freed.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1083 This behavior allows the finalizer to access properties
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1084 associated with the object through weak tables.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1085
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1086
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1087 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1088 If a weak table is among the resurrected objects in a collection cycle,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1089 it may not be properly cleared until the next cycle.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1090
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1091
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1092
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1093
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1094
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1095
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1096
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1097 <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
1098
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1099 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1100 Lua supports coroutines,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1101 also called <em>collaborative multithreading</em>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1102 A coroutine in Lua represents an independent thread of execution.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1103 Unlike threads in multithread systems, however,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1104 a coroutine only suspends its execution by explicitly calling
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1105 a yield function.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1106
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1107
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1108 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1109 You create a coroutine by calling <a href="#pdf-coroutine.create"><code>coroutine.create</code></a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1110 Its sole argument is a function
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1111 that is the main function of the coroutine.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1112 The <code>create</code> function only creates a new coroutine and
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1113 returns a handle to it (an object of type <em>thread</em>);
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1114 it does not start the coroutine.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1115
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1116
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1117 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1118 You execute a coroutine by calling <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1119 When you first call <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1120 passing as its first argument
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1121 a thread returned by <a href="#pdf-coroutine.create"><code>coroutine.create</code></a>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1122 the coroutine starts its execution,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1123 at the first line of its main function.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1124 Extra arguments passed to <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a> are passed on
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1125 to the coroutine main function.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1126 After the coroutine starts running,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1127 it runs until it terminates or <em>yields</em>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1128
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1129
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1130 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1131 A coroutine can terminate its execution in two ways:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1132 normally, when its main function returns
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1133 (explicitly or implicitly, after the last instruction);
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1134 and abnormally, if there is an unprotected error.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1135 In the first case, <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a> returns <b>true</b>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1136 plus any values returned by the coroutine main function.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1137 In case of errors, <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a> returns <b>false</b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1138 plus an error message.
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1141 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1142 A coroutine yields by calling <a href="#pdf-coroutine.yield"><code>coroutine.yield</code></a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1143 When a coroutine yields,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1144 the corresponding <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a> returns immediately,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1145 even if the yield happens inside nested function calls
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1146 (that is, not in the main function,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1147 but in a function directly or indirectly called by the main function).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1148 In the case of a yield, <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a> also returns <b>true</b>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1149 plus any values passed to <a href="#pdf-coroutine.yield"><code>coroutine.yield</code></a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1150 The next time you resume the same coroutine,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1151 it continues its execution from the point where it yielded,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1152 with the call to <a href="#pdf-coroutine.yield"><code>coroutine.yield</code></a> returning any extra
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1153 arguments passed to <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1154
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1155
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1156 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1157 Like <a href="#pdf-coroutine.create"><code>coroutine.create</code></a>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1158 the <a href="#pdf-coroutine.wrap"><code>coroutine.wrap</code></a> function also creates a coroutine,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1159 but instead of returning the coroutine itself,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1160 it returns a function that, when called, resumes the coroutine.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1161 Any arguments passed to this function
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1162 go as extra arguments to <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1163 <a href="#pdf-coroutine.wrap"><code>coroutine.wrap</code></a> returns all the values returned by <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1164 except the first one (the boolean error code).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1165 Unlike <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1166 <a href="#pdf-coroutine.wrap"><code>coroutine.wrap</code></a> does not catch errors;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1167 any error is propagated to the caller.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1171 As an example of how coroutines work,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1172 consider the following code:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1173
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1174 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1175 function foo (a)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1176 print("foo", a)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1177 return coroutine.yield(2*a)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1178 end
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 co = coroutine.create(function (a,b)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1181 print("co-body", a, b)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1182 local r = foo(a+1)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1183 print("co-body", r)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1184 local r, s = coroutine.yield(a+b, a-b)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1185 print("co-body", r, s)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1186 return b, "end"
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1187 end)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1188
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1189 print("main", coroutine.resume(co, 1, 10))
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1190 print("main", coroutine.resume(co, "r"))
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1191 print("main", coroutine.resume(co, "x", "y"))
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1192 print("main", coroutine.resume(co, "x", "y"))
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1193 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1194 When you run it, it produces the following output:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1195
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1196 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1197 co-body 1 10
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1198 foo 2
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1199 main true 4
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1200 co-body r
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1201 main true 11 -9
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1202 co-body x y
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1203 main true 10 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1204 main false cannot resume dead coroutine
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1205 </pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1206
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1207 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1208 You can also create and manipulate coroutines through the C API:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1209 see functions <a href="#lua_newthread"><code>lua_newthread</code></a>, <a href="#lua_resume"><code>lua_resume</code></a>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1210 and <a href="#lua_yield"><code>lua_yield</code></a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1211
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1212
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1213
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1214
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1215
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1216 <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
1217
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1218 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1219 This section describes the lexis, the syntax, and the semantics of Lua.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1220 In other words,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1221 this section describes
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1222 which tokens are valid,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1223 how they can be combined,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1224 and what their combinations mean.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1225
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1226
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1227 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1228 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
1229 in which
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1230 {<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
1231 [<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
1232 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
1233 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
1234 and other terminal symbols are shown like &lsquo;<b>=</b>&rsquo;.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1235 The complete syntax of Lua can be found in <a href="#9">&sect;9</a>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1236 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
1237
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1238
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1240 <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
1241
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1242 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1243 Lua is a free-form language.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1244 It ignores spaces (including new lines) and comments
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1245 between lexical elements (tokens),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1246 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
1247
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1248
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1249 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1250 <em>Names</em>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1251 (also called <em>identifiers</em>)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1252 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
1253 digits, and underscores,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1254 not beginning with a digit.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1255 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
1256
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1257
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1258 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1259 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
1260 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
1261
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1262
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1263 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1264 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
1265 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
1266 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
1267 then true until while
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1268 </pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1269
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1270 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1271 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
1272 <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
1273 are two different, valid names.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1274 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
1275 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
1276 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
1277
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1278
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1279 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1280 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
1281
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1282 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1283 + - * / % ^ #
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1284 == ~= &lt;= &gt;= &lt; &gt; =
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1285 ( ) { } [ ] ::
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1286 ; : , . .. ...
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1287 </pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1288
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1289 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1290 <em>Literal strings</em>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1291 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
1292 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
1293 '<code>\a</code>' (bell),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1294 '<code>\b</code>' (backspace),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1295 '<code>\f</code>' (form feed),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1296 '<code>\n</code>' (newline),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1297 '<code>\r</code>' (carriage return),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1298 '<code>\t</code>' (horizontal tab),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1299 '<code>\v</code>' (vertical tab),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1300 '<code>\\</code>' (backslash),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1301 '<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
1302 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
1303 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
1304 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
1305 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
1306 of white-space characters,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1307 including line breaks;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1308 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
1309 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
1310 into the string contents.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1311
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1312
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1313 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1314 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
1315 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
1316 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
1317 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
1318 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
1319 (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
1320 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
1321 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
1322 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
1323
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1324
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1325 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1326 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
1327 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
1328 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
1329 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
1330 opening square bracket.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1331 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
1332 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
1333 and so on.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1334 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
1335 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
1336 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
1337 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
1338 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
1339 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
1340 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
1341 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
1342 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
1343 (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
1344 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
1345 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
1346
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1347
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1348 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1349 Any byte in a literal string not
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1350 explicitly affected by the previous rules represents itself.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1351 However, Lua opens files for parsing in text mode,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1352 and the system file functions may have problems with
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1353 some control characters.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1354 So, it is safer to represent
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1355 non-text data as a quoted literal with
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1356 explicit escape sequences for non-text characters.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1357
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1358
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1359 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1360 For convenience,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1361 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
1362 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
1363 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
1364 (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
1365 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
1366 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
1367
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1368 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1369 a = 'alo\n123"'
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1370 a = "alo\n123\""
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1371 a = '\97lo\10\04923"'
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1372 a = [[alo
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1373 123"]]
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1374 a = [==[
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1375 alo
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1376 123"]==]
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1377 </pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1378
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1379 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1380 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
1381 and an optional decimal exponent,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1382 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
1383 Lua also accepts hexadecimal constants,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1384 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
1385 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
1386 plus an optional binary exponent,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1387 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
1388 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
1389
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1390 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1391 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
1392 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
1393 </pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1394
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1395 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1396 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
1397 anywhere outside a string.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1398 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
1399 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
1400 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
1401 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
1402 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
1403 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
1404
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1405
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1406
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1407
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1408
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1409 <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
1410
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1411 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1412 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
1413 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
1414 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
1415
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1416
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1417 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1418 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
1419 (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
1420 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
1421
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1422 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1423 var ::= Name
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1424 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1425 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
1426
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1429 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
1430 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
1431 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
1432 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
1433 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
1434
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1435
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1436 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1437 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
1438
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1439
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1440 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1441 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
1442
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1443 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1444 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
1445 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1446 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
1447 An access to an indexed variable <code>t[i]</code> is equivalent to
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1448 a call <code>gettable_event(t,i)</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1449 (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
1450 <code>gettable_event</code> function.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1451 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
1452 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
1453
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>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1456 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
1457 <code>var["Name"]</code>:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1458
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1459 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1460 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
1461 </pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1462
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1463 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1464 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
1465 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
1466 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
1467 <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
1468
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1469
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1470
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1471
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1472
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1473 <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
1474
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1475 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1476 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
1477 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
1478 This set includes
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1479 assignments, control structures, function calls,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1480 and variable declarations.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1481
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1482
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1483
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1484 <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
1485
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1486 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1487 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
1488 which are executed sequentially:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1489
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1490 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1491 block ::= {stat}
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1492 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1493 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
1494 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
1495 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
1496 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
1497
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1498 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1499 stat ::= &lsquo;<b>;</b>&rsquo;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1500 </pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1501
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1502 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1503 Function calls and assignments
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1504 can start with an open parenthesis.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1505 This possibility leads to an ambiguity in Lua's grammar.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1506 Consider the following fragment:
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 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1509 a = b + c
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1510 (print or io.write)('done')
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1511 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1512 The grammar could see it in two ways:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1513
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1514 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1515 a = b + c(print or io.write)('done')
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1516
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1517 a = b + c; (print or io.write)('done')
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1518 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1519 The current parser always sees such constructions
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1520 in the first way,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1521 interpreting the open parenthesis
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1522 as the start of the arguments to a call.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1523 To avoid this ambiguity,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1524 it is a good practice to always precede with a semicolon
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1525 statements that start with a parenthesis:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1526
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1527 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1528 ;(print or io.write)('done')
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1529 </pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1530
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1531 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1532 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
1533
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1534 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1535 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
1536 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1537 Explicit blocks are useful
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1538 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
1539 Explicit blocks are also sometimes used to
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1540 add a <b>return</b> statement in the middle
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1541 of another block (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
1542
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1543
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1544
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1545
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1546
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1547 <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
1548
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1549 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1550 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
1551 Syntactically,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1552 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
1553
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1554 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1555 chunk ::= block
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1556 </pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1557
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1558 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1559 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
1560 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
1561 (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
1562 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
1563 receive arguments, and return values.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1564 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
1565 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
1566 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
1567 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
1568
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1569
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1570 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1571 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
1572 To execute a chunk,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1573 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
1574 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
1575 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
1576
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 Chunks can also be precompiled into binary form;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1580 see program <code>luac</code> for details.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1581 Programs in source and compiled forms are interchangeable;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1582 Lua automatically detects the file type and acts accordingly.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1583
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1584
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1585
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1586
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1587
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1588
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1589 <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
1590
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1591 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1592 Lua allows multiple assignments.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1593 Therefore, the syntax for assignment
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1594 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
1595 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
1596 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
1597
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1598 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1599 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
1600 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
1601 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
1602 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1603 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
1604
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1605
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1606 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1607 Before the assignment,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1608 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
1609 the list of variables.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1610 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
1611 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
1612 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
1613 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
1614 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
1615 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
1616 before the adjustment
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1617 (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
1618
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1619
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1620 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1621 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
1622 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
1623 Thus the code
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 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1626 i = 3
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1627 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
1628 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1629 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
1630 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
1631 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
1632 Similarly, the line
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 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1635 x, y = y, x
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1636 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1637 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
1638 and
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1639
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1640 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1641 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
1642 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1643 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
1644
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1645
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1646 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1647 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
1648 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
1649 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
1650 <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
1651 (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
1652 <code>settable_event</code> function.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1653 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
1654 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
1655
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1656
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1657 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1658 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
1659 is equivalent to the assignment
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1660 <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
1661
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1662
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1663
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1664
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1665
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1666 <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
1667 The control structures
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1668 <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
1669 familiar syntax:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1670
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1671
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1672
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1673
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1674 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1675 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
1676 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
1677 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
1678 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1679 Lua also has a <b>for</b> statement, in two flavors (see <a href="#3.3.5">&sect;3.3.5</a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1680
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1681
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 The condition expression of a
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1684 control structure can return any value.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1685 Both <b>false</b> and <b>nil</b> are considered false.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1686 All values different from <b>nil</b> and <b>false</b> are considered true
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1687 (in particular, the number 0 and the empty string are also true).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1688
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1689
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1690 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1691 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
1692 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
1693 but only after the condition.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1694 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
1695 declared inside the loop block.
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1698 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1699 The <b>goto</b> statement transfers the program control to a label.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1700 For syntactical reasons,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1701 labels in Lua are considered statements too:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1702
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1703
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1704
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1705 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1706 stat ::= <b>goto</b> Name
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1707 stat ::= label
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1708 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
1709 </pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1710
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1711 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1712 A label is visible in the entire block where it is defined,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1713 except
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1714 inside nested blocks where a label with the same name is defined and
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1715 inside nested functions.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1716 A goto may jump to any visible label as long as it does not
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1717 enter into the scope of a local variable.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1718
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1721 Labels and empty statements are called <em>void statements</em>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1722 as they perform no actions.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1723
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1724
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1725 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1726 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
1727 <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
1728 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
1729
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1730
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1731 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1732 stat ::= <b>break</b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1733 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1734 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
1735
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1736
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1737 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1738 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
1739 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
1740
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1741 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
1742 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
1743
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1744 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1745 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
1746 </pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1747
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1748 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1749 The <b>return</b> statement can only be written
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1750 as the last statement of a block.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1751 If it is really necessary to <b>return</b> in the middle of a block,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1752 then an explicit inner block can be used,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1753 as in the idiom <code>do return end</code>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1754 because now <b>return</b> is the last statement in its (inner) block.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1755
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1756
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1757
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1758
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1759
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1760 <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
1761
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1762 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1763
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1764 The <b>for</b> statement has two forms:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1765 one numeric and one generic.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1766
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1767
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1768 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1769 The numeric <b>for</b> loop repeats a block of code while a
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1770 control variable runs through an arithmetic progression.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1771 It has the following syntax:
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 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1774 stat ::= <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>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1775 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1776 The <em>block</em> is repeated for <em>name</em> starting at the value of
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1777 the first <em>exp</em>, until it passes the second <em>exp</em> by steps of the
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1778 third <em>exp</em>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1779 More precisely, a <b>for</b> statement like
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1780
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1781 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1782 for v = <em>e1</em>, <em>e2</em>, <em>e3</em> do <em>block</em> end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1783 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1784 is equivalent to the code:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1785
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1786 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1787 do
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1788 local <em>var</em>, <em>limit</em>, <em>step</em> = tonumber(<em>e1</em>), tonumber(<em>e2</em>), tonumber(<em>e3</em>)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1789 if not (<em>var</em> and <em>limit</em> and <em>step</em>) then error() end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1790 while (<em>step</em> &gt; 0 and <em>var</em> &lt;= <em>limit</em>) or (<em>step</em> &lt;= 0 and <em>var</em> &gt;= <em>limit</em>) do
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1791 local v = <em>var</em>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1792 <em>block</em>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1793 <em>var</em> = <em>var</em> + <em>step</em>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1794 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1795 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1796 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1797 Note the following:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1798
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1799 <ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1800
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1801 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1802 All three control expressions are evaluated only once,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1803 before the loop starts.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1804 They must all result in numbers.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1805 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1806
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1807 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1808 <code><em>var</em></code>, <code><em>limit</em></code>, and <code><em>step</em></code> are invisible variables.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1809 The names shown here are for explanatory purposes only.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1810 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1811
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1812 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1813 If the third expression (the step) is absent,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1814 then a step of&nbsp;1 is used.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1815 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1816
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1817 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1818 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
1819 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1820
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1821 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1822 The loop variable <code>v</code> is local to the loop;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1823 you cannot use its value after the <b>for</b> ends or is broken.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1824 If you need this value,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1825 assign it to another variable before breaking or exiting the loop.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1826 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1827
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1828 </ul>
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1831 The generic <b>for</b> statement works over functions,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1832 called <em>iterators</em>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1833 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
1834 stopping when this new value is <b>nil</b>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1835 The generic <b>for</b> loop has the following syntax:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1836
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1837 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1838 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
1839 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
1840 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1841 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
1842
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1843 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1844 for <em>var_1</em>, &middot;&middot;&middot;, <em>var_n</em> in <em>explist</em> do <em>block</em> end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1845 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1846 is equivalent to the code:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1847
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1848 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1849 do
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1850 local <em>f</em>, <em>s</em>, <em>var</em> = <em>explist</em>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1851 while true do
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1852 local <em>var_1</em>, &middot;&middot;&middot;, <em>var_n</em> = <em>f</em>(<em>s</em>, <em>var</em>)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1853 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
1854 <em>var</em> = <em>var_1</em>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1855 <em>block</em>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1856 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1857 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1858 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1859 Note the following:
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 <ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1862
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1863 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1864 <code><em>explist</em></code> is evaluated only once.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1865 Its results are an <em>iterator</em> function,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1866 a <em>state</em>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1867 and an initial value for the first <em>iterator variable</em>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1868 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1869
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1870 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1871 <code><em>f</em></code>, <code><em>s</em></code>, and <code><em>var</em></code> are invisible variables.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1872 The names are here for explanatory purposes only.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1873 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1874
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1875 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1876 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
1877 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1878
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1879 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1880 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
1881 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
1882 If you need these values,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1883 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
1884 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1885
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1886 </ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1887
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1888
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1889
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1890
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1891 <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
1892 To allow possible side-effects,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1893 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
1894
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1895 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1896 stat ::= functioncall
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1897 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1898 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
1899 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
1900
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1901
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1902
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1903
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1904
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1905 <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
1906 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
1907 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
1908
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1909 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1910 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
1911 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1912 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
1913 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
1914 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
1915
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1916
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1917 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1918 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
1919 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
1920
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1921
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1922 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1923 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
1924
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1925
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1926
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1927
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1928
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1929
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1930
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1931 <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
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 The basic expressions in Lua are the following:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1935
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1936 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1937 exp ::= prefixexp
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1938 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
1939 exp ::= Number
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1940 exp ::= String
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1941 exp ::= functiondef
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1942 exp ::= tableconstructor
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1943 exp ::= &lsquo;<b>...</b>&rsquo;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1944 exp ::= exp binop exp
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1945 exp ::= unop exp
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1946 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
1947 </pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1948
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1949 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1950 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
1951 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
1952 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
1953 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
1954 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
1955 Vararg expressions,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1956 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
1957 directly inside a vararg function;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1958 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
1959
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1960
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1961 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1962 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
1963 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
1964 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
1965 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
1966 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
1967 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
1968
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1969
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1970 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1971 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
1972 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
1973 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
1974 thus discarding all returned values.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1975 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
1976 of a list of expressions,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1977 then no adjustment is made
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1978 (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
1979 In all other contexts,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1980 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
1981 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
1982 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
1983
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1984
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1985 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1986 Here are some examples:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1987
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1988 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1989 f() -- adjusted to 0 results
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1990 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
1991 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
1992 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
1993 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
1994 -- 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
1995 -- is no corresponding vararg parameter)
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 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
1998 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
1999 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
2000 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
2001 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
2002 {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
2003 {...} -- 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
2004 {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
2005 </pre>
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2008 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
2009 Thus,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2010 <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
2011 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
2012 (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
2013 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
2014
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2015
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2016
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2017 <h3>3.4.1 &ndash; <a name="3.4.1">Arithmetic Operators</a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2018 Lua supports the usual arithmetic operators:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2019 the binary <code>+</code> (addition),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2020 <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
2021 <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
2022 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
2023 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
2024 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
2025 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
2026 Exponentiation works for any exponent.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2027 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
2028 Modulo is defined as
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2029
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2030 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2031 a % b == a - math.floor(a/b)*b
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2032 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2033 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
2034 the quotient towards minus infinity.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2035
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2036
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2037
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2038
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2039
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2040 <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
2041
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2042 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2043 Lua provides automatic conversion between
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2044 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
2045 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
2046 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
2047 (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
2048 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
2049 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
2050 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
2051 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
2052 (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
2053
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2054
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2055
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2056
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2057
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2058 <h3>3.4.3 &ndash; <a name="3.4.3">Relational Operators</a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2059 The relational operators in Lua are
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2060
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2061 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2062 == ~= &lt; &gt; &lt;= &gt;=
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2063 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2064 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
2065
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2068 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
2069 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
2070 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
2071 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
2072 Tables, userdata, and threads
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2073 are compared by reference:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2074 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
2075 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
2076 (a table, userdata, or thread),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2077 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
2078 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
2079 Closures with any detectable difference
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2080 (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
2081
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2082
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2083 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2084 You can change the way that Lua compares tables and userdata
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2085 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
2086
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2087
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2088 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2089 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
2090 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
2091 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
2092 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
2093 entries in a table.
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2096 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2097 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
2098
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2099
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2100 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2101 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
2102 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
2103 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
2104 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
2105 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
2106 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
2107 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
2108 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
2109
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2110
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2111
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2112
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2113
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2114 <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
2115 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
2116 <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
2117 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
2118 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
2119 and anything else as true.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2120
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2121
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2122 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2123 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
2124 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
2125 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
2126 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
2127 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
2128 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
2129 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
2130 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
2131 that is,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2132 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
2133 Here are some examples:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2134
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2135 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2136 10 or 20 --&gt; 10
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2137 10 or error() --&gt; 10
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2138 nil or "a" --&gt; "a"
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2139 nil and 10 --&gt; nil
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2140 false and error() --&gt; false
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2141 false and nil --&gt; false
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2142 false or nil --&gt; nil
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2143 10 and 20 --&gt; 20
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2144 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2145 (In this manual,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2146 <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
2147
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2148
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2149
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2150
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2151
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2152 <h3>3.4.5 &ndash; <a name="3.4.5">Concatenation</a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2153 The string concatenation operator in Lua is
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2154 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
2155 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
2156 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
2157 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
2158
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2159
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2160
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2161
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2162
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2163 <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
2164
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2165 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2166 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
2167 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
2168 (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
2169 character is one byte).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2170
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2171
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2172 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2173 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
2174 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
2175
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2176
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2177 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2178 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
2179 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
2180 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
2181 that is,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2182 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
2183 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
2184 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
2185 Note that a table like
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 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2188 {10, 20, nil, 40}
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2189 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2190 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
2191 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
2192 (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
2193 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
2194 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
2195 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
2196
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2197
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2198
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2199
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2200
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2201 <h3>3.4.7 &ndash; <a name="3.4.7">Precedence</a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2202 Operator precedence in Lua follows the table below,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2203 from lower to higher priority:
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 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2206 or
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2207 and
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2208 &lt; &gt; &lt;= &gt;= ~= ==
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 * / %
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2212 not # - (unary)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2213 ^
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2214 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2215 As usual,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2216 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
2217 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
2218 operators are right associative.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2219 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
2220
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2221
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2222
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2223
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2224
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2225 <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
2226 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
2227 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
2228 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
2229 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
2230 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
2231
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2232 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2233 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
2234 fieldlist ::= field {fieldsep field} [fieldsep]
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2235 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
2236 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
2237 </pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2238
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2239 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2240 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
2241 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
2242 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
2243 <code>["name"] = exp</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2244 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
2245 <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
2246 starting with 1.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2247 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
2248 For example,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2249
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2250 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2251 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
2252 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2253 is equivalent to
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2254
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2255 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2256 do
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2257 local t = {}
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2258 t[f(1)] = g
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2259 t[1] = "x" -- 1st exp
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2260 t[2] = "y" -- 2nd exp
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2261 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
2262 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
2263 t[30] = 23
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2264 t[4] = 45 -- 4th exp
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2265 a = t
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2266 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2267 </pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2268
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2269 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2270 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
2271 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
2272 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
2273 (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
2274
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2277 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
2278 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
2279
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2280
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2281
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2282
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2283
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2284 <h3>3.4.9 &ndash; <a name="3.4.9">Function Calls</a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2285 A function call in Lua has the following syntax:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2286
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2287 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2288 functioncall ::= prefixexp args
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2289 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2290 In a function call,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2291 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
2292 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
2293 then this function is called
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2294 with the given arguments.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2295 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
2296 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
2297 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
2298 (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
2299
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2300
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2301 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2302 The form
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2303
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2304 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2305 functioncall ::= prefixexp &lsquo;<b>:</b>&rsquo; Name args
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2306 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2307 can be used to call "methods".
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2308 A call <code>v:name(<em>args</em>)</code>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2309 is syntactic sugar for <code>v.name(v,<em>args</em>)</code>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2310 except that <code>v</code> is evaluated only once.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
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 Arguments have the following syntax:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2315
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2316 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2317 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
2318 args ::= tableconstructor
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2319 args ::= String
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2320 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2321 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
2322 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
2323 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
2324 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
2325 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
2326 (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
2327 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
2328 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
2329
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2330
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2331 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2332 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
2333 a <em>tail call</em>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2334 Lua implements <em>proper tail calls</em>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2335 (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
2336 in a tail call,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2337 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
2338 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
2339 a program can execute.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2340 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
2341 calling function.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2342 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
2343 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
2344 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
2345 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
2346 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
2347
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2348 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2349 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
2350 return 2 * f(x)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2351 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
2352 f(x); return -- results discarded
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2353 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
2354 </pre>
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2359 <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
2360
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2361 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2362 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
2363
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2364 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2365 functiondef ::= <b>function</b> funcbody
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2366 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
2367 </pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2368
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2369 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2370 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
2371
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2372 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2373 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
2374 stat ::= <b>local</b> <b>function</b> Name funcbody
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2375 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
2376 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2377 The statement
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2378
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2379 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2380 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
2381 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2382 translates to
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2383
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2384 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2385 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
2386 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2387 The statement
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 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2390 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
2391 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2392 translates to
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2393
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2394 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2395 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
2396 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2397 The statement
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 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2400 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
2401 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2402 translates to
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2403
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2404 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2405 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
2406 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2407 not to
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 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2410 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
2411 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2412 (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
2413 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
2414
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2415
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2416 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2417 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
2418 whose value has type <em>function</em>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2419 When Lua precompiles a chunk,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2420 all its function bodies are precompiled too.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2421 Then, whenever Lua executes the function definition,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2422 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
2423 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
2424 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
2425
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2426
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2427 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2428 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
2429 initialized with the argument values:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2430
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2431 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2432 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
2433 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2434 When a function is called,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2435 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
2436 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
2437 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
2438 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
2439 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
2440 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
2441 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
2442 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
2443 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
2444 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
2445 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
2446 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
2447 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
2448 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
2449 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
2450 then no adjustment is made
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2451 (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
2452
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2453
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2454 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2455 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
2456
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2457 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2458 function f(a, b) end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2459 function g(a, b, ...) end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2460 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
2461 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2462 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
2463 to the vararg expression:
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 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2466 CALL PARAMETERS
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 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
2469 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
2470 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
2471 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
2472 f(r()) a=1, b=2
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2473
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2474 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
2475 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
2476 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
2477 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
2478 </pre>
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2481 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
2482 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
2483 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
2484 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
2485
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2486
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2487 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2488
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2489 There is a system-dependent limit on the number of values
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2490 that a function may return.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2491 This limit is guaranteed to be larger than 1000.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2495 The <em>colon</em> syntax
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2496 is used for defining <em>methods</em>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2497 that is, functions that have an implicit extra parameter <code>self</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2498 Thus, the statement
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2499
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2500 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2501 function t.a.b.c:f (<em>params</em>) <em>body</em> end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2502 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2503 is syntactic sugar for
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2504
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2505 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2506 t.a.b.c.f = function (self, <em>params</em>) <em>body</em> end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2507 </pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2508
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2509
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2510
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2511
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2512
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2513
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2514 <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
2515
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2516 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2517
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2518 Lua is a lexically scoped language.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2519 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
2520 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
2521 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
2522 Consider the following example:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2523
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2524 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2525 x = 10 -- global variable
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2526 do -- new block
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2527 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
2528 print(x) --&gt; 10
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2529 x = x+1
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2530 do -- another block
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2531 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
2532 print(x) --&gt; 12
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2533 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2534 print(x) --&gt; 11
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2535 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2536 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
2537 </pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2538
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2539 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2540 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
2541 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
2542 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
2543
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2546 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
2547 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
2548 defined inside their scope.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2549 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
2550 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
2551 inside the inner function.
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2554 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2555 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
2556 defines new local variables.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2557 Consider the following example:
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 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2560 a = {}
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2561 local x = 20
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2562 for i=1,10 do
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2563 local y = 0
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2564 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
2565 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2566 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2567 The loop creates ten closures
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2568 (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
2569 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
2570 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
2571
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2572
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2573
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2574
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2575
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2576 <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
2577
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2578 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2579
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2580 This section describes the C&nbsp;API for Lua, that is,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2581 the set of C&nbsp;functions available to the host program to communicate
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2582 with Lua.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2583 All API functions and related types and constants
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2584 are declared in the header file <a name="pdf-lua.h"><code>lua.h</code></a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2585
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2588 Even when we use the term "function",
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2589 any facility in the API may be provided as a macro instead.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2590 Except where stated otherwise,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2591 all such macros use each of their arguments exactly once
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2592 (except for the first argument, which is always a Lua state),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2593 and so do not generate any hidden side-effects.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2594
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2597 As in most C&nbsp;libraries,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2598 the Lua API functions do not check their arguments for validity or consistency.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2599 However, you can change this behavior by compiling Lua
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2600 with the macro <a name="pdf-LUA_USE_APICHECK"><code>LUA_USE_APICHECK</code></a> defined.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2604 <h2>4.1 &ndash; <a name="4.1">The Stack</a></h2>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2605
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2606 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2607 Lua uses a <em>virtual stack</em> to pass values to and from C.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2608 Each element in this stack represents a Lua value
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2609 (<b>nil</b>, number, string, etc.).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2610
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2611
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2612 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2613 Whenever Lua calls C, the called function gets a new stack,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2614 which is independent of previous stacks and of stacks of
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2615 C&nbsp;functions that are still active.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2616 This stack initially contains any arguments to the C&nbsp;function
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2617 and it is where the C&nbsp;function pushes its results
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2618 to be returned to the caller (see <a href="#lua_CFunction"><code>lua_CFunction</code></a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2619
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2620
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2621 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2622 For convenience,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2623 most query operations in the API do not follow a strict stack discipline.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2624 Instead, they can refer to any element in the stack
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2625 by using an <em>index</em>:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2626 A positive index represents an absolute stack position
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2627 (starting at&nbsp;1);
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2628 a negative index represents an offset relative to the top of the stack.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2629 More specifically, if the stack has <em>n</em> elements,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2630 then index&nbsp;1 represents the first element
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2631 (that is, the element that was pushed onto the stack first)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2632 and
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2633 index&nbsp;<em>n</em> represents the last element;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2634 index&nbsp;-1 also represents the last element
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2635 (that is, the element at the&nbsp;top)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2636 and index <em>-n</em> represents the first element.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2637
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2638
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2639
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2640
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2641
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2642 <h2>4.2 &ndash; <a name="4.2">Stack Size</a></h2>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2643
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2644 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2645 When you interact with the Lua API,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2646 you are responsible for ensuring consistency.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2647 In particular,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2648 <em>you are responsible for controlling stack overflow</em>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2649 You can use the function <a href="#lua_checkstack"><code>lua_checkstack</code></a>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2650 to ensure that the stack has extra slots when pushing new elements.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2651
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2654 Whenever Lua calls C,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2655 it ensures that the stack has at least <a name="pdf-LUA_MINSTACK"><code>LUA_MINSTACK</code></a> extra slots.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2656 <code>LUA_MINSTACK</code> is defined as 20,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2657 so that usually you do not have to worry about stack space
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2658 unless your code has loops pushing elements onto the stack.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2659
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 When you call a Lua function
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2663 without a fixed number of results (see <a href="#lua_call"><code>lua_call</code></a>),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2664 Lua ensures that the stack has enough size for all results,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2665 but it does not ensure any extra space.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2666 So, before pushing anything in the stack after such a call
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2667 you should use <a href="#lua_checkstack"><code>lua_checkstack</code></a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2668
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2669
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2670
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2671
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2672
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2673 <h2>4.3 &ndash; <a name="4.3">Valid and Acceptable Indices</a></h2>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2674
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2675 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2676 Any function in the API that receives stack indices
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2677 works only with <em>valid indices</em> or <em>acceptable indices</em>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2678
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2679
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2680 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2681 A <em>valid index</em> is an index that refers to a
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2682 real position within the stack, that is,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2683 its position lies between&nbsp;1 and the stack top
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2684 (<code>1 &le; abs(index) &le; top</code>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2685
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2686 Usually, functions that can modify the value at an index
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2687 require valid indices.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2688
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2689
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2690 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2691 Unless otherwise noted,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2692 any function that accepts valid indices also accepts <em>pseudo-indices</em>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2693 which represent some Lua values that are accessible to C&nbsp;code
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2694 but which are not in the stack.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2695 Pseudo-indices are used to access the registry
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2696 and the upvalues of a C&nbsp;function (see <a href="#4.4">&sect;4.4</a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2697
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2698
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2699 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2700 Functions that do not need a specific stack position,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2701 but only a value in the stack (e.g., query functions),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2702 can be called with acceptable indices.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2703 An <em>acceptable index</em> can be any valid index,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2704 including the pseudo-indices,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2705 but it also can be any positive index after the stack top
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2706 within the space allocated for the stack,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2707 that is, indices up to the stack size.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2708 (Note that 0 is never an acceptable index.)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2709 Except when noted otherwise,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2710 functions in the API work with acceptable indices.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2711
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2712
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2713 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2714 Acceptable indices serve to avoid extra tests
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2715 against the stack top when querying the stack.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2716 For instance, a C&nbsp;function can query its third argument
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2717 without the need to first check whether there is a third argument,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2718 that is, without the need to check whether 3 is a valid index.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2719
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2720
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2721 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2722 For functions that can be called with acceptable indices,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2723 any non-valid index is treated as if it
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2724 contains a value of a virtual type <a name="pdf-LUA_TNONE"><code>LUA_TNONE</code></a>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2725 which behaves like a nil value.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2726
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2727
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2728
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2729
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2730
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2731 <h2>4.4 &ndash; <a name="4.4">C Closures</a></h2>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2732
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2733 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2734 When a C&nbsp;function is created,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2735 it is possible to associate some values with it,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2736 thus creating a <em>C&nbsp;closure</em>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2737 (see <a href="#lua_pushcclosure"><code>lua_pushcclosure</code></a>);
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2738 these values are called <em>upvalues</em> and are
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2739 accessible to the function whenever it is called.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2740
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2743 Whenever a C&nbsp;function is called,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2744 its upvalues are located at specific pseudo-indices.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2745 These pseudo-indices are produced by the macro
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2746 <a href="#lua_upvalueindex"><code>lua_upvalueindex</code></a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2747 The first value associated with a function is at position
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2748 <code>lua_upvalueindex(1)</code>, and so on.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2749 Any access to <code>lua_upvalueindex(<em>n</em>)</code>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2750 where <em>n</em> is greater than the number of upvalues of the
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2751 current function (but not greater than 256),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2752 produces an acceptable but invalid index.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2753
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2754
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2755
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2756
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2757
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2758 <h2>4.5 &ndash; <a name="4.5">Registry</a></h2>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2759
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2760 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2761 Lua provides a <em>registry</em>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2762 a predefined table that can be used by any C&nbsp;code to
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2763 store whatever Lua values it needs to store.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2764 The registry table is always located at pseudo-index
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2765 <a name="pdf-LUA_REGISTRYINDEX"><code>LUA_REGISTRYINDEX</code></a>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2766 which is a valid index.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2767 Any C&nbsp;library can store data into this table,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2768 but it should take care to choose keys
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2769 that are different from those used
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2770 by other libraries, to avoid collisions.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2771 Typically, you should use as key a string containing your library name,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2772 or a light userdata with the address of a C&nbsp;object in your code,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2773 or any Lua object created by your code.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2774 As with global names,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2775 string keys starting with an underscore followed by
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2776 uppercase letters are reserved for Lua.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2777
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2780 The integer keys in the registry are used by the reference mechanism,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2781 implemented by the auxiliary library,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2782 and by some predefined values.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2783 Therefore, integer keys should not be used for other purposes.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2784
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2785
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2786 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2787 When you create a new Lua state,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2788 its registry comes with some predefined values.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2789 These predefined values are indexed with integer keys
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2790 defined as constants in <code>lua.h</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2791 The following constants are defined:
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 <ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2794 <li><b><a name="pdf-LUA_RIDX_MAINTHREAD"><code>LUA_RIDX_MAINTHREAD</code></a>: </b> At this index the registry has
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2795 the main thread of the state.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2796 (The main thread is the one created together with the state.)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2797 </li>
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 <li><b><a name="pdf-LUA_RIDX_GLOBALS"><code>LUA_RIDX_GLOBALS</code></a>: </b> At this index the registry has
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2800 the global environment.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2801 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2802 </ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2803
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2804
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2805
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2806
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2807 <h2>4.6 &ndash; <a name="4.6">Error Handling in C</a></h2>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2808
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2809 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2810 Internally, Lua uses the C <code>longjmp</code> facility to handle errors.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2811 (You can also choose to use exceptions if you compile Lua as C++;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2812 search for <code>LUAI_THROW</code> in the source code.)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2813 When Lua faces any error
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2814 (such as a memory allocation error, type errors, syntax errors,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2815 and runtime errors)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2816 it <em>raises</em> an error;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2817 that is, it does a long jump.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2818 A <em>protected environment</em> uses <code>setjmp</code>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2819 to set a recovery point;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2820 any error jumps to the most recent active recovery point.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2821
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2822
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2823 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2824 If an error happens outside any protected environment,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2825 Lua calls a <em>panic function</em> (see <a href="#lua_atpanic"><code>lua_atpanic</code></a>)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2826 and then calls <code>abort</code>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2827 thus exiting the host application.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2828 Your panic function can avoid this exit by
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2829 never returning
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2830 (e.g., doing a long jump to your own recovery point outside Lua).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2831
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2832
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2833 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2834 The panic function runs as if it were a message handler (see <a href="#2.3">&sect;2.3</a>);
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2835 in particular, the error message is at the top of the stack.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2836 However, there is no guarantees about stack space.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2837 To push anything on the stack,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2838 the panic function should first check the available space (see <a href="#4.2">&sect;4.2</a>).
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 Most functions in the API can throw an error,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2843 for instance due to a memory allocation error.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2844 The documentation for each function indicates whether
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2845 it can throw errors.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2846
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2847
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2848 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2849 Inside a C&nbsp;function you can throw an error by calling <a href="#lua_error"><code>lua_error</code></a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2850
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2851
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2852
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2853
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2854
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2855 <h2>4.7 &ndash; <a name="4.7">Handling Yields in C</a></h2>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
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 Internally, Lua uses the C <code>longjmp</code> facility to yield a coroutine.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2859 Therefore, if a function <code>foo</code> calls an API function
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2860 and this API function yields
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2861 (directly or indirectly by calling another function that yields),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2862 Lua cannot return to <code>foo</code> any more,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2863 because the <code>longjmp</code> removes its frame from the C stack.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
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 To avoid this kind of problem,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2868 Lua raises an error whenever it tries to yield across an API call,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2869 except for three functions:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2870 <a href="#lua_yieldk"><code>lua_yieldk</code></a>, <a href="#lua_callk"><code>lua_callk</code></a>, and <a href="#lua_pcallk"><code>lua_pcallk</code></a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2871 All those functions receive a <em>continuation function</em>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2872 (as a parameter called <code>k</code>) to continue execution after a yield.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2873
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2874
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2875 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2876 We need to set some terminology to explain continuations.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2877 We have a C function called from Lua which we will call
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2878 the <em>original function</em>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2879 This original function then calls one of those three functions in the C API,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2880 which we will call the <em>callee function</em>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2881 that then yields the current thread.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2882 (This can happen when the callee function is <a href="#lua_yieldk"><code>lua_yieldk</code></a>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2883 or when the callee function is either <a href="#lua_callk"><code>lua_callk</code></a> or <a href="#lua_pcallk"><code>lua_pcallk</code></a>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2884 and the function called by them yields.)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2885
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2886
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2887 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2888 Suppose the running thread yields while executing the callee function.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2889 After the thread resumes,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2890 it eventually will finish running the callee function.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2891 However,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2892 the callee function cannot return to the original function,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2893 because its frame in the C stack was destroyed by the yield.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2894 Instead, Lua calls a <em>continuation function</em>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2895 which was given as an argument to the callee function.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2896 As the name implies,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2897 the continuation function should continue the task
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2898 of the original function.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2899
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2900
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2901 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2902 Lua treats the continuation function as if it were the original function.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2903 The continuation function receives the same Lua stack
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2904 from the original function,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2905 in the same state it would be if the callee function had returned.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2906 (For instance,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2907 after a <a href="#lua_callk"><code>lua_callk</code></a> the function and its arguments are
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2908 removed from the stack and replaced by the results from the call.)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2909 It also has the same upvalues.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2910 Whatever it returns is handled by Lua as if it were the return
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2911 of the original function.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2912
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2913
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2914 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2915 The only difference in the Lua state between the original function
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2916 and its continuation is the result of a call to <a href="#lua_getctx"><code>lua_getctx</code></a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2917
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2918
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2919
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2920
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2921
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2922 <h2>4.8 &ndash; <a name="4.8">Functions and Types</a></h2>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2923
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2924 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2925 Here we list all functions and types from the C&nbsp;API in
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2926 alphabetical order.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2927 Each function has an indicator like this:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2928 <span class="apii">[-o, +p, <em>x</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2929
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2930
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2931 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2932 The first field, <code>o</code>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2933 is how many elements the function pops from the stack.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2934 The second field, <code>p</code>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2935 is how many elements the function pushes onto the stack.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2936 (Any function always pushes its results after popping its arguments.)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2937 A field in the form <code>x|y</code> means the function can push (or pop)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2938 <code>x</code> or <code>y</code> elements,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2939 depending on the situation;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2940 an interrogation mark '<code>?</code>' means that
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2941 we cannot know how many elements the function pops/pushes
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2942 by looking only at its arguments
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2943 (e.g., they may depend on what is on the stack).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2944 The third field, <code>x</code>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2945 tells whether the function may throw errors:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2946 '<code>-</code>' means the function never throws any error;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2947 '<code>e</code>' means the function may throw errors;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2948 '<code>v</code>' means the function may throw an error on purpose.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2952 <hr><h3><a name="lua_absindex"><code>lua_absindex</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2953 <span class="apii">[-0, +0, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2954 <pre>int lua_absindex (lua_State *L, int idx);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2955
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2956 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2957 Converts the acceptable index <code>idx</code> into an absolute index
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2958 (that is, one that does not depend on the stack top).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2959
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2960
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2961
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2962
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2963
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2964 <hr><h3><a name="lua_Alloc"><code>lua_Alloc</code></a></h3>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2965 <pre>typedef void * (*lua_Alloc) (void *ud,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2966 void *ptr,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2967 size_t osize,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2968 size_t nsize);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2969
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2970 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2971 The type of the memory-allocation function used by Lua states.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2972 The allocator function must provide a
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2973 functionality similar to <code>realloc</code>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2974 but not exactly the same.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2975 Its arguments are
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2976 <code>ud</code>, an opaque pointer passed to <a href="#lua_newstate"><code>lua_newstate</code></a>;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2977 <code>ptr</code>, a pointer to the block being allocated/reallocated/freed;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2978 <code>osize</code>, the original size of the block or some code about what
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2979 is being allocated;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2980 <code>nsize</code>, the new size of the block.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2981
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2982
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2983 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2984 When <code>ptr</code> is not <code>NULL</code>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2985 <code>osize</code> is the size of the block pointed by <code>ptr</code>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2986 that is, the size given when it was allocated or reallocated.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2987
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2988
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2989 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2990 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
2991 <code>osize</code> encodes the kind of object that Lua is allocating.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2992 <code>osize</code> is any of
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2993 <a href="#pdf-LUA_TSTRING"><code>LUA_TSTRING</code></a>, <a href="#pdf-LUA_TTABLE"><code>LUA_TTABLE</code></a>, <a href="#pdf-LUA_TFUNCTION"><code>LUA_TFUNCTION</code></a>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2994 <a href="#pdf-LUA_TUSERDATA"><code>LUA_TUSERDATA</code></a>, or <a href="#pdf-LUA_TTHREAD"><code>LUA_TTHREAD</code></a> when (and only when)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2995 Lua is creating a new object of that type.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2996 When <code>osize</code> is some other value,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2997 Lua is allocating memory for something else.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3001 Lua assumes the following behavior from the allocator function:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3005 When <code>nsize</code> is zero,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3006 the allocator should behave like <code>free</code>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3007 and return <code>NULL</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3008
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3009
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3010 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3011 When <code>nsize</code> is not zero,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3012 the allocator should behave like <code>realloc</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3013 The allocator returns <code>NULL</code>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3014 if and only if it cannot fulfill the request.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3015 Lua assumes that the allocator never fails when
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3016 <code>osize &gt;= nsize</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3017
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3018
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3019 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3020 Here is a simple implementation for the allocator function.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3021 It is used in the auxiliary library by <a href="#luaL_newstate"><code>luaL_newstate</code></a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3022
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3023 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3024 static void *l_alloc (void *ud, void *ptr, size_t osize,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3025 size_t nsize) {
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3026 (void)ud; (void)osize; /* not used */
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3027 if (nsize == 0) {
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3028 free(ptr);
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3029 return NULL;
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 else
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3032 return realloc(ptr, nsize);
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3033 }
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3034 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3035 Note that Standard&nbsp;C ensures
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3036 that <code>free(NULL)</code> has no effect and that
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3037 <code>realloc(NULL, size)</code> is equivalent to <code>malloc(size)</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3038 This code assumes that <code>realloc</code> does not fail when shrinking a block.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3039 (Although Standard&nbsp;C does not ensure this behavior,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3040 it seems to be a safe assumption.)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3041
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3042
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3043
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3044
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3045
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3046 <hr><h3><a name="lua_arith"><code>lua_arith</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3047 <span class="apii">[-(2|1), +1, <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3048 <pre>void lua_arith (lua_State *L, int op);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3049
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3050 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3051 Performs an arithmetic operation over the two values
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3052 (or one, in the case of negation)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3053 at the top of the stack,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3054 with the value at the top being the second operand,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3055 pops these values, and pushes the result of the operation.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3056 The function follows the semantics of the corresponding Lua operator
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3057 (that is, it may call metamethods).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3061 The value of <code>op</code> must be one of the following constants:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3062
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3063 <ul>
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 <li><b><a name="pdf-LUA_OPADD"><code>LUA_OPADD</code></a>: </b> performs addition (<code>+</code>)</li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3066 <li><b><a name="pdf-LUA_OPSUB"><code>LUA_OPSUB</code></a>: </b> performs subtraction (<code>-</code>)</li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3067 <li><b><a name="pdf-LUA_OPMUL"><code>LUA_OPMUL</code></a>: </b> performs multiplication (<code>*</code>)</li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3068 <li><b><a name="pdf-LUA_OPDIV"><code>LUA_OPDIV</code></a>: </b> performs division (<code>/</code>)</li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3069 <li><b><a name="pdf-LUA_OPMOD"><code>LUA_OPMOD</code></a>: </b> performs modulo (<code>%</code>)</li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3070 <li><b><a name="pdf-LUA_OPPOW"><code>LUA_OPPOW</code></a>: </b> performs exponentiation (<code>^</code>)</li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3071 <li><b><a name="pdf-LUA_OPUNM"><code>LUA_OPUNM</code></a>: </b> performs mathematical negation (unary <code>-</code>)</li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3072
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3073 </ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3074
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3075
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3076
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3077
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3078 <hr><h3><a name="lua_atpanic"><code>lua_atpanic</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3079 <span class="apii">[-0, +0, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3080 <pre>lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3081
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3082 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3083 Sets a new panic function and returns the old one (see <a href="#4.6">&sect;4.6</a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3084
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3085
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3086
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3087
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3088
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3089 <hr><h3><a name="lua_call"><code>lua_call</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3090 <span class="apii">[-(nargs+1), +nresults, <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3091 <pre>void lua_call (lua_State *L, int nargs, int nresults);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
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 Calls a function.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3095
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3096
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3097 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3098 To call a function you must use the following protocol:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3099 first, the function to be called is pushed onto the stack;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3100 then, the arguments to the function are pushed
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3101 in direct order;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3102 that is, the first argument is pushed first.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3103 Finally you call <a href="#lua_call"><code>lua_call</code></a>;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3104 <code>nargs</code> is the number of arguments that you pushed onto the stack.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3105 All arguments and the function value are popped from the stack
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3106 when the function is called.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3107 The function results are pushed onto the stack when the function returns.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3108 The number of results is adjusted to <code>nresults</code>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3109 unless <code>nresults</code> is <a name="pdf-LUA_MULTRET"><code>LUA_MULTRET</code></a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3110 In this case, all results from the function are pushed.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3111 Lua takes care that the returned values fit into the stack space.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3112 The function results are pushed onto the stack in direct order
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3113 (the first result is pushed first),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3114 so that after the call the last result is on the top of the stack.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3115
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3116
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3117 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3118 Any error inside the called function is propagated upwards
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3119 (with a <code>longjmp</code>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3120
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3121
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3122 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3123 The following example shows how the host program can do the
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3124 equivalent to this Lua code:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3125
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3126 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3127 a = f("how", t.x, 14)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3128 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3129 Here it is in&nbsp;C:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3130
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3131 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3132 lua_getglobal(L, "f"); /* function to be called */
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3133 lua_pushstring(L, "how"); /* 1st argument */
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3134 lua_getglobal(L, "t"); /* table to be indexed */
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3135 lua_getfield(L, -1, "x"); /* push result of t.x (2nd arg) */
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3136 lua_remove(L, -2); /* remove 't' from the stack */
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3137 lua_pushinteger(L, 14); /* 3rd argument */
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3138 lua_call(L, 3, 1); /* call 'f' with 3 arguments and 1 result */
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3139 lua_setglobal(L, "a"); /* set global 'a' */
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3140 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3141 Note that the code above is "balanced":
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3142 at its end, the stack is back to its original configuration.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3143 This is considered good programming practice.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3144
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3145
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3146
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3147
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3148
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3149 <hr><h3><a name="lua_callk"><code>lua_callk</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3150 <span class="apii">[-(nargs + 1), +nresults, <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3151 <pre>void lua_callk (lua_State *L, int nargs, int nresults, int ctx,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3152 lua_CFunction k);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3153
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3154 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3155 This function behaves exactly like <a href="#lua_call"><code>lua_call</code></a>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3156 but allows the called function to yield (see <a href="#4.7">&sect;4.7</a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3157
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3158
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3159
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3160
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3161
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3162 <hr><h3><a name="lua_CFunction"><code>lua_CFunction</code></a></h3>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3163 <pre>typedef int (*lua_CFunction) (lua_State *L);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3164
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3165 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3166 Type for C&nbsp;functions.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3167
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3168
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3169 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3170 In order to communicate properly with Lua,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3171 a C&nbsp;function must use the following protocol,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3172 which defines the way parameters and results are passed:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3173 a C&nbsp;function receives its arguments from Lua in its stack
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3174 in direct order (the first argument is pushed first).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3175 So, when the function starts,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3176 <code>lua_gettop(L)</code> returns the number of arguments received by the function.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3177 The first argument (if any) is at index 1
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3178 and its last argument is at index <code>lua_gettop(L)</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3179 To return values to Lua, a C&nbsp;function just pushes them onto the stack,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3180 in direct order (the first result is pushed first),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3181 and returns the number of results.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3182 Any other value in the stack below the results will be properly
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3183 discarded by Lua.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3184 Like a Lua function, a C&nbsp;function called by Lua can also return
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3185 many results.
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3188 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3189 As an example, the following function receives a variable number
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3190 of numerical arguments and returns their average and sum:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3191
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3192 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3193 static int foo (lua_State *L) {
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3194 int n = lua_gettop(L); /* number of arguments */
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3195 lua_Number sum = 0;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3196 int i;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3197 for (i = 1; i &lt;= n; i++) {
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3198 if (!lua_isnumber(L, i)) {
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3199 lua_pushstring(L, "incorrect argument");
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3200 lua_error(L);
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3201 }
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3202 sum += lua_tonumber(L, i);
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3203 }
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3204 lua_pushnumber(L, sum/n); /* first result */
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3205 lua_pushnumber(L, sum); /* second result */
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3206 return 2; /* number of results */
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 </pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3209
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3210
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3211
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3212
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3213 <hr><h3><a name="lua_checkstack"><code>lua_checkstack</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3214 <span class="apii">[-0, +0, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3215 <pre>int lua_checkstack (lua_State *L, int extra);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3216
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3217 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3218 Ensures that there are at least <code>extra</code> free stack slots in the stack.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3219 It returns false if it cannot fulfill the request,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3220 because it would cause the stack to be larger than a fixed maximum size
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3221 (typically at least a few thousand elements) or
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3222 because it cannot allocate memory for the new stack size.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3223 This function never shrinks the stack;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3224 if the stack is already larger than the new size,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3225 it is left unchanged.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3226
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3227
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3228
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3229
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3230
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3231 <hr><h3><a name="lua_close"><code>lua_close</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3232 <span class="apii">[-0, +0, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3233 <pre>void lua_close (lua_State *L);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
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 Destroys all objects in the given Lua state
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3237 (calling the corresponding garbage-collection metamethods, if any)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3238 and frees all dynamic memory used by this state.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3239 On several platforms, you may not need to call this function,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3240 because all resources are naturally released when the host program ends.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3241 On the other hand, long-running programs that create multiple states,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3242 such as daemons or web servers,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3243 might need to close states as soon as they are not needed.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3244
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3245
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3246
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3247
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3248
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3249 <hr><h3><a name="lua_compare"><code>lua_compare</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3250 <span class="apii">[-0, +0, <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3251 <pre>int lua_compare (lua_State *L, int index1, int index2, int op);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3252
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3253 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3254 Compares two Lua values.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3255 Returns 1 if the value at index <code>index1</code> satisfies <code>op</code>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3256 when compared with the value at index <code>index2</code>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3257 following the semantics of the corresponding Lua operator
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3258 (that is, it may call metamethods).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3259 Otherwise returns&nbsp;0.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3260 Also returns&nbsp;0 if any of the indices is non valid.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
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 The value of <code>op</code> must be one of the following constants:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3265
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3266 <ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3267
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3268 <li><b><a name="pdf-LUA_OPEQ"><code>LUA_OPEQ</code></a>: </b> compares for equality (<code>==</code>)</li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3269 <li><b><a name="pdf-LUA_OPLT"><code>LUA_OPLT</code></a>: </b> compares for less than (<code>&lt;</code>)</li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3270 <li><b><a name="pdf-LUA_OPLE"><code>LUA_OPLE</code></a>: </b> compares for less or equal (<code>&lt;=</code>)</li>
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 </ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3273
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3274
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3275
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3276
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3277 <hr><h3><a name="lua_concat"><code>lua_concat</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3278 <span class="apii">[-n, +1, <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3279 <pre>void lua_concat (lua_State *L, int n);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3280
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3281 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3282 Concatenates the <code>n</code> values at the top of the stack,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3283 pops them, and leaves the result at the top.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3284 If <code>n</code>&nbsp;is&nbsp;1, the result is the single value on the stack
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3285 (that is, the function does nothing);
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3286 if <code>n</code> is 0, the result is the empty string.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3287 Concatenation is performed following the usual semantics of Lua
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3288 (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
3289
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3290
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3291
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3292
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3293
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3294 <hr><h3><a name="lua_copy"><code>lua_copy</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3295 <span class="apii">[-0, +0, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3296 <pre>void lua_copy (lua_State *L, int fromidx, int toidx);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3297
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3298 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3299 Moves the element at index <code>fromidx</code>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3300 into the valid index <code>toidx</code>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3301 without shifting any element
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3302 (therefore replacing the value at that position).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3303
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3304
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3305
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3306
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3307
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3308 <hr><h3><a name="lua_createtable"><code>lua_createtable</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3309 <span class="apii">[-0, +1, <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3310 <pre>void lua_createtable (lua_State *L, int narr, int nrec);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3311
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3312 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3313 Creates a new empty table and pushes it onto the stack.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3314 Parameter <code>narr</code> is a hint for how many elements the table
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3315 will have as a sequence;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3316 parameter <code>nrec</code> is a hint for how many other elements
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3317 the table will have.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3318 Lua may use these hints to preallocate memory for the new table.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3319 This pre-allocation is useful for performance when you know in advance
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3320 how many elements the table will have.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3321 Otherwise you can use the function <a href="#lua_newtable"><code>lua_newtable</code></a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3322
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3323
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3324
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3325
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3326
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3327 <hr><h3><a name="lua_dump"><code>lua_dump</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3328 <span class="apii">[-0, +0, <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3329 <pre>int lua_dump (lua_State *L, lua_Writer writer, void *data);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3330
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3331 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3332 Dumps a function as a binary chunk.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3333 Receives a Lua function on the top of the stack
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3334 and produces a binary chunk that,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3335 if loaded again,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3336 results in a function equivalent to the one dumped.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3337 As it produces parts of the chunk,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3338 <a href="#lua_dump"><code>lua_dump</code></a> calls function <code>writer</code> (see <a href="#lua_Writer"><code>lua_Writer</code></a>)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3339 with the given <code>data</code>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3340 to write them.
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 The value returned is the error code returned by the last
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3345 call to the writer;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3346 0&nbsp;means no errors.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3347
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3348
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3349 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3350 This function does not pop the Lua function from the stack.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3351
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3352
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3353
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3354
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3355
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3356 <hr><h3><a name="lua_error"><code>lua_error</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3357 <span class="apii">[-1, +0, <em>v</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3358 <pre>int lua_error (lua_State *L);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3359
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3360 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3361 Generates a Lua error.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3362 The error message (which can actually be a Lua value of any type)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3363 must be on the stack top.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3364 This function does a long jump,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3365 and therefore never returns
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3366 (see <a href="#luaL_error"><code>luaL_error</code></a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3367
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3368
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3369
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3370
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3371
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3372 <hr><h3><a name="lua_gc"><code>lua_gc</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3373 <span class="apii">[-0, +0, <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3374 <pre>int lua_gc (lua_State *L, int what, int data);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3375
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3376 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3377 Controls the garbage collector.
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3380 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3381 This function performs several tasks,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3382 according to the value of the parameter <code>what</code>:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3383
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3384 <ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3385
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3386 <li><b><code>LUA_GCSTOP</code>: </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3387 stops the garbage collector.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3388 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3389
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3390 <li><b><code>LUA_GCRESTART</code>: </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3391 restarts the garbage collector.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3392 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3393
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3394 <li><b><code>LUA_GCCOLLECT</code>: </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3395 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
3396 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3397
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3398 <li><b><code>LUA_GCCOUNT</code>: </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3399 returns the current amount of memory (in Kbytes) in use by Lua.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3400 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3401
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3402 <li><b><code>LUA_GCCOUNTB</code>: </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3403 returns the remainder of dividing the current amount of bytes of
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3404 memory in use by Lua by 1024.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3405 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3406
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3407 <li><b><code>LUA_GCSTEP</code>: </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3408 performs an incremental step of garbage collection.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3409 The step "size" is controlled by <code>data</code>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3410 (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
3411 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
3412 you must experimentally tune the value of <code>data</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3413 The function returns 1 if the step finished a
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3414 garbage-collection cycle.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3415 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3416
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3417 <li><b><code>LUA_GCSETPAUSE</code>: </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3418 sets <code>data</code> as the new value
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3419 for the <em>pause</em> of 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
3420 The function returns the previous value of the pause.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3421 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3422
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3423 <li><b><code>LUA_GCSETSTEPMUL</code>: </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3424 sets <code>data</code> as the new value for the <em>step multiplier</em> of
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3425 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
3426 The function returns the previous value of the step multiplier.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3427 </li>
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 <li><b><code>LUA_GCISRUNNING</code>: </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3430 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
3431 (i.e., not stopped).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3432 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3433
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3434 <li><b><code>LUA_GCGEN</code>: </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3435 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
3436 (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
3437 </li>
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 <li><b><code>LUA_GCINC</code>: </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3440 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
3441 This is the default mode.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3442 </li>
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 </ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3445
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3446 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3447 For more details about these options,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3448 see <a href="#pdf-collectgarbage"><code>collectgarbage</code></a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3449
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3450
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3451
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3452
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3453
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3454 <hr><h3><a name="lua_getallocf"><code>lua_getallocf</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3455 <span class="apii">[-0, +0, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3456 <pre>lua_Alloc lua_getallocf (lua_State *L, void **ud);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3457
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3458 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3459 Returns the memory-allocation function of a given state.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3460 If <code>ud</code> is not <code>NULL</code>, Lua stores in <code>*ud</code> the
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3461 opaque pointer passed to <a href="#lua_newstate"><code>lua_newstate</code></a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3462
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3463
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3464
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3465
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3466
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3467 <hr><h3><a name="lua_getctx"><code>lua_getctx</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3468 <span class="apii">[-0, +0, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3469 <pre>int lua_getctx (lua_State *L, int *ctx);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3470
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3471 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3472 This function is called by a continuation function (see <a href="#4.7">&sect;4.7</a>)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3473 to retrieve the status of the thread and a context information.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3474
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3475
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3476 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3477 When called in the original function,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3478 <a href="#lua_getctx"><code>lua_getctx</code></a> always returns <a href="#pdf-LUA_OK"><code>LUA_OK</code></a>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3479 and does not change the value of its argument <code>ctx</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3480 When called inside a continuation function,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3481 <a href="#lua_getctx"><code>lua_getctx</code></a> returns <a href="#pdf-LUA_YIELD"><code>LUA_YIELD</code></a> and sets
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3482 the value of <code>ctx</code> to be the context information
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3483 (the value passed as the <code>ctx</code> argument
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3484 to the callee together with the continuation function).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3485
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3486
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3487 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3488 When the callee is <a href="#lua_pcallk"><code>lua_pcallk</code></a>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3489 Lua may also call its continuation function
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3490 to handle errors during the call.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3491 That is, upon an error in the function called by <a href="#lua_pcallk"><code>lua_pcallk</code></a>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3492 Lua may not return to the original function
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3493 but instead may call the continuation function.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3494 In that case, a call to <a href="#lua_getctx"><code>lua_getctx</code></a> will return the error code
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3495 (the value that would be returned by <a href="#lua_pcallk"><code>lua_pcallk</code></a>);
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3496 the value of <code>ctx</code> will be set to the context information,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3497 as in the case of a yield.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3498
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3499
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3500
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3501
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3502
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3503 <hr><h3><a name="lua_getfield"><code>lua_getfield</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3504 <span class="apii">[-0, +1, <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3505 <pre>void lua_getfield (lua_State *L, int index, const char *k);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3506
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3507 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3508 Pushes onto the stack the value <code>t[k]</code>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3509 where <code>t</code> is the value at the given index.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3510 As in Lua, this function may trigger a metamethod
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3511 for the "index" event (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
3512
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3513
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3514
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3515
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3516
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3517 <hr><h3><a name="lua_getglobal"><code>lua_getglobal</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3518 <span class="apii">[-0, +1, <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3519 <pre>void lua_getglobal (lua_State *L, const char *name);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3520
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3521 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3522 Pushes onto the stack the value of the global <code>name</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3523
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3524
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3525
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3526
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3527
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3528 <hr><h3><a name="lua_getmetatable"><code>lua_getmetatable</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3529 <span class="apii">[-0, +(0|1), &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3530 <pre>int lua_getmetatable (lua_State *L, int index);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3531
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3532 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3533 Pushes onto the stack the metatable of the value at the given index.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3534 If the value does not have a metatable,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3535 the function returns&nbsp;0 and pushes nothing on the stack.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
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 <hr><h3><a name="lua_gettable"><code>lua_gettable</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3542 <span class="apii">[-1, +1, <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3543 <pre>void lua_gettable (lua_State *L, int index);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3544
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3545 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3546 Pushes onto the stack the value <code>t[k]</code>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3547 where <code>t</code> is the value at the given index
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3548 and <code>k</code> is the value at the top of the stack.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3549
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3550
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3551 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3552 This function pops the key from the stack
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3553 (putting the resulting value in its place).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3554 As in Lua, this function may trigger a metamethod
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3555 for the "index" event (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
3556
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3557
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3558
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3559
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3560
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3561 <hr><h3><a name="lua_gettop"><code>lua_gettop</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3562 <span class="apii">[-0, +0, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3563 <pre>int lua_gettop (lua_State *L);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3564
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3565 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3566 Returns the index of the top element in the stack.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3567 Because indices start at&nbsp;1,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3568 this result is equal to the number of elements in the stack
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3569 (and so 0&nbsp;means an empty stack).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3570
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3571
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3572
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3573
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3574
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3575 <hr><h3><a name="lua_getuservalue"><code>lua_getuservalue</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3576 <span class="apii">[-0, +1, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3577 <pre>void lua_getuservalue (lua_State *L, int index);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3578
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3579 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3580 Pushes onto the stack the Lua value associated with the userdata
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3581 at the given index.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3582 This Lua value must be a table or <b>nil</b>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3583
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3584
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3585
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3586
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3587
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3588 <hr><h3><a name="lua_insert"><code>lua_insert</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3589 <span class="apii">[-1, +1, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3590 <pre>void lua_insert (lua_State *L, int index);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3591
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3592 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3593 Moves the top element into the given valid index,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3594 shifting up the elements above this index to open space.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3595 This function cannot be called with a pseudo-index,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3596 because a pseudo-index is not an actual stack position.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3597
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3598
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3599
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3600
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3601
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3602 <hr><h3><a name="lua_Integer"><code>lua_Integer</code></a></h3>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3603 <pre>typedef ptrdiff_t lua_Integer;</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3604
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3605 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3606 The type used by the Lua API to represent signed integral values.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
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 By default it is a <code>ptrdiff_t</code>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3611 which is usually the largest signed integral type the machine handles
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3612 "comfortably".
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3613
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3614
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3615
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3616
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3617
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3618 <hr><h3><a name="lua_isboolean"><code>lua_isboolean</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3619 <span class="apii">[-0, +0, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3620 <pre>int lua_isboolean (lua_State *L, int index);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3621
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3622 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3623 Returns 1 if the value at the given index is a boolean,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3624 and 0&nbsp;otherwise.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3625
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3626
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3627
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3628
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3629
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3630 <hr><h3><a name="lua_iscfunction"><code>lua_iscfunction</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3631 <span class="apii">[-0, +0, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3632 <pre>int lua_iscfunction (lua_State *L, int index);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3633
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3634 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3635 Returns 1 if the value at the given index is a C&nbsp;function,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3636 and 0&nbsp;otherwise.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3637
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3638
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3639
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3640
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3641
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3642 <hr><h3><a name="lua_isfunction"><code>lua_isfunction</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3643 <span class="apii">[-0, +0, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3644 <pre>int lua_isfunction (lua_State *L, int index);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3645
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3646 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3647 Returns 1 if the value at the given index is a function
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3648 (either C or Lua), and 0&nbsp;otherwise.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3649
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3650
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3651
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3652
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3653
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3654 <hr><h3><a name="lua_islightuserdata"><code>lua_islightuserdata</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3655 <span class="apii">[-0, +0, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3656 <pre>int lua_islightuserdata (lua_State *L, int index);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3657
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3658 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3659 Returns 1 if the value at the given index is a light userdata,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3660 and 0&nbsp;otherwise.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3661
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3662
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3663
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3664
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3665
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3666 <hr><h3><a name="lua_isnil"><code>lua_isnil</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3667 <span class="apii">[-0, +0, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3668 <pre>int lua_isnil (lua_State *L, int index);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3669
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3670 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3671 Returns 1 if the value at the given index is <b>nil</b>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3672 and 0&nbsp;otherwise.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3673
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3674
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3675
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3676
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3677
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3678 <hr><h3><a name="lua_isnone"><code>lua_isnone</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3679 <span class="apii">[-0, +0, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3680 <pre>int lua_isnone (lua_State *L, int index);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3681
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3682 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3683 Returns 1 if the given index is not valid,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3684 and 0&nbsp;otherwise.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3685
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3686
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3687
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3688
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3689
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3690 <hr><h3><a name="lua_isnoneornil"><code>lua_isnoneornil</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3691 <span class="apii">[-0, +0, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3692 <pre>int lua_isnoneornil (lua_State *L, int index);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3693
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3694 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3695 Returns 1 if the given index is not valid
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3696 or if the value at this index is <b>nil</b>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3697 and 0&nbsp;otherwise.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3698
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3699
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3700
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3701
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3702
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3703 <hr><h3><a name="lua_isnumber"><code>lua_isnumber</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3704 <span class="apii">[-0, +0, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3705 <pre>int lua_isnumber (lua_State *L, int index);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
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 1 if the value at the given index is a number
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3709 or a string convertible to a number,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3710 and 0&nbsp;otherwise.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3711
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3712
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3713
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3714
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3715
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3716 <hr><h3><a name="lua_isstring"><code>lua_isstring</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3717 <span class="apii">[-0, +0, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3718 <pre>int lua_isstring (lua_State *L, int index);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3719
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3720 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3721 Returns 1 if the value at the given index is a string
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3722 or a number (which is always convertible to a string),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3723 and 0&nbsp;otherwise.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3724
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3725
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3726
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3727
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3728
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3729 <hr><h3><a name="lua_istable"><code>lua_istable</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3730 <span class="apii">[-0, +0, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3731 <pre>int lua_istable (lua_State *L, int index);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3732
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3733 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3734 Returns 1 if the value at the given index is a table,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3735 and 0&nbsp;otherwise.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3736
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3737
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3738
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3739
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3740
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3741 <hr><h3><a name="lua_isthread"><code>lua_isthread</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3742 <span class="apii">[-0, +0, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3743 <pre>int lua_isthread (lua_State *L, int index);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3744
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3745 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3746 Returns 1 if the value at the given index is a thread,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3747 and 0&nbsp;otherwise.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3748
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3749
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3750
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3751
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3752
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3753 <hr><h3><a name="lua_isuserdata"><code>lua_isuserdata</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3754 <span class="apii">[-0, +0, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3755 <pre>int lua_isuserdata (lua_State *L, int index);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3756
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3757 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3758 Returns 1 if the value at the given index is a userdata
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3759 (either full or light), and 0&nbsp;otherwise.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3760
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3761
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3762
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3763
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3764
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3765 <hr><h3><a name="lua_len"><code>lua_len</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3766 <span class="apii">[-0, +1, <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3767 <pre>void lua_len (lua_State *L, int index);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3768
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3769 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3770 Returns the "length" of the value at the given index;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3771 it is equivalent to the '<code>#</code>' operator in Lua (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
3772 The result is pushed on the stack.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3773
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3774
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3775
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3776
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3777
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3778 <hr><h3><a name="lua_load"><code>lua_load</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3779 <span class="apii">[-0, +1, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3780 <pre>int lua_load (lua_State *L,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3781 lua_Reader reader,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3782 void *data,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3783 const char *source,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3784 const char *mode);</pre>
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 Loads a Lua chunk (without running it).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3788 If there are no errors,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3789 <code>lua_load</code> pushes the compiled chunk as a Lua
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3790 function on top of the stack.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3791 Otherwise, it pushes an error message.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3795 The return values of <code>lua_load</code> are:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3796
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3797 <ul>
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 <li><b><a href="#pdf-LUA_OK"><code>LUA_OK</code></a>: </b> no errors;</li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3800
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3801 <li><b><a name="pdf-LUA_ERRSYNTAX"><code>LUA_ERRSYNTAX</code></a>: </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3802 syntax error during precompilation;</li>
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 <li><b><a href="#pdf-LUA_ERRMEM"><code>LUA_ERRMEM</code></a>: </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3805 memory allocation error;</li>
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 <li><b><a href="#pdf-LUA_ERRGCMM"><code>LUA_ERRGCMM</code></a>: </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3808 error while running a <code>__gc</code> metamethod.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3809 (This error has no relation with the chunk being loaded.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3810 It is generated by the garbage collector.)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3811 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3812
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3813 </ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3814
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3815 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3816 The <code>lua_load</code> function uses a user-supplied <code>reader</code> function
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3817 to read the chunk (see <a href="#lua_Reader"><code>lua_Reader</code></a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3818 The <code>data</code> argument is an opaque value passed to the reader function.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3819
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3820
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3821 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3822 The <code>source</code> argument gives a name to the chunk,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3823 which is used for error messages and in 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
3824
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3825
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3826 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3827 <code>lua_load</code> automatically detects whether the chunk is text or binary
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3828 and loads it accordingly (see program <code>luac</code>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3829 The string <code>mode</code> works as in function <a href="#pdf-load"><code>load</code></a>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3830 with the addition that
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3831 a <code>NULL</code> value is equivalent to the string "<code>bt</code>".
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3832
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3835 <code>lua_load</code> uses the stack internally,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3836 so the reader function should always leave the stack
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3837 unmodified when returning.
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3841 If the resulting function has one upvalue,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3842 this upvalue is set to the value of the global environment
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3843 stored at index <code>LUA_RIDX_GLOBALS</code> in the registry (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
3844 When loading main chunks,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3845 this upvalue will be 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
3846
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3847
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3848
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3849
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3850
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3851 <hr><h3><a name="lua_newstate"><code>lua_newstate</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3852 <span class="apii">[-0, +0, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3853 <pre>lua_State *lua_newstate (lua_Alloc f, void *ud);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3854
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3855 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3856 Creates a new thread running in a new, independent state.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3857 Returns <code>NULL</code> if cannot create the thread or the state
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3858 (due to lack of memory).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3859 The argument <code>f</code> is the allocator function;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3860 Lua does all memory allocation for this state through this function.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3861 The second argument, <code>ud</code>, is an opaque pointer that Lua
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3862 passes to the allocator in every call.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3863
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3864
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3865
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3866
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3867
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3868 <hr><h3><a name="lua_newtable"><code>lua_newtable</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3869 <span class="apii">[-0, +1, <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3870 <pre>void lua_newtable (lua_State *L);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3871
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3872 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3873 Creates a new empty table and pushes it onto the stack.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3874 It is equivalent to <code>lua_createtable(L, 0, 0)</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3875
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3876
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3877
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3878
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3879
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3880 <hr><h3><a name="lua_newthread"><code>lua_newthread</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3881 <span class="apii">[-0, +1, <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3882 <pre>lua_State *lua_newthread (lua_State *L);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
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 Creates a new thread, pushes it on the stack,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3886 and returns a pointer to a <a href="#lua_State"><code>lua_State</code></a> that represents this new thread.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3887 The new thread returned by this function shares with the original thread
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3888 its global environment,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3889 but has an independent execution stack.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3893 There is no explicit function to close or to destroy a thread.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3894 Threads are subject to garbage collection,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3895 like any Lua object.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3896
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3897
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3898
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3899
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3900
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3901 <hr><h3><a name="lua_newuserdata"><code>lua_newuserdata</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3902 <span class="apii">[-0, +1, <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3903 <pre>void *lua_newuserdata (lua_State *L, size_t size);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
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 This function allocates a new block of memory with the given size,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3907 pushes onto the stack a new full userdata with the block address,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3908 and returns this address.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3909 The host program can freely use this memory.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3910
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3911
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3912
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3913
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3914
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3915 <hr><h3><a name="lua_next"><code>lua_next</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3916 <span class="apii">[-1, +(2|0), <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3917 <pre>int lua_next (lua_State *L, int index);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
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 Pops a key from the stack,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3921 and pushes a key&ndash;value pair from the table at the given index
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3922 (the "next" pair after the given key).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3923 If there are no more elements in the table,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3924 then <a href="#lua_next"><code>lua_next</code></a> returns 0 (and pushes nothing).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3925
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3926
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3927 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3928 A typical traversal looks like this:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3929
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3930 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3931 /* table is in the stack at index 't' */
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3932 lua_pushnil(L); /* first key */
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3933 while (lua_next(L, t) != 0) {
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3934 /* uses 'key' (at index -2) and 'value' (at index -1) */
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3935 printf("%s - %s\n",
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3936 lua_typename(L, lua_type(L, -2)),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3937 lua_typename(L, lua_type(L, -1)));
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3938 /* removes 'value'; keeps 'key' for next iteration */
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3939 lua_pop(L, 1);
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3940 }
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3941 </pre>
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 While traversing a table,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3945 do not call <a href="#lua_tolstring"><code>lua_tolstring</code></a> directly on a key,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3946 unless you know that the key is actually a string.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3947 Recall that <a href="#lua_tolstring"><code>lua_tolstring</code></a> may change
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3948 the value at the given index;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3949 this confuses the next call to <a href="#lua_next"><code>lua_next</code></a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3950
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3951
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3952 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3953 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
3954 the table during its traversal.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3955
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3956
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3957
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3958
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3959
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3960 <hr><h3><a name="lua_Number"><code>lua_Number</code></a></h3>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3961 <pre>typedef double lua_Number;</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3962
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3963 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3964 The type of numbers in Lua.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3965 By default, it is double, but that can be changed in <code>luaconf.h</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3966 Through this configuration file you can change
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3967 Lua to operate with another type for numbers (e.g., float or long).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3968
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3969
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3970
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3971
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3972
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3973 <hr><h3><a name="lua_pcall"><code>lua_pcall</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3974 <span class="apii">[-(nargs + 1), +(nresults|1), &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3975 <pre>int lua_pcall (lua_State *L, int nargs, int nresults, int msgh);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3976
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3977 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3978 Calls a function in protected mode.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3982 Both <code>nargs</code> and <code>nresults</code> have the same meaning as
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3983 in <a href="#lua_call"><code>lua_call</code></a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3984 If there are no errors during the call,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3985 <a href="#lua_pcall"><code>lua_pcall</code></a> behaves exactly like <a href="#lua_call"><code>lua_call</code></a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3986 However, if there is any error,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3987 <a href="#lua_pcall"><code>lua_pcall</code></a> catches it,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3988 pushes a single value on the stack (the error message),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3989 and returns an error code.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3990 Like <a href="#lua_call"><code>lua_call</code></a>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3991 <a href="#lua_pcall"><code>lua_pcall</code></a> always removes the function
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3992 and its arguments from the stack.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3993
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3996 If <code>msgh</code> is 0,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3997 then the error message returned on the stack
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3998 is exactly the original error message.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3999 Otherwise, <code>msgh</code> is the stack index of a
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4000 <em>message handler</em>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4001 (In the current implementation, this index cannot be a pseudo-index.)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4002 In case of runtime errors,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4003 this function will be called with the error message
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4004 and its return value will be the message
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4005 returned on the stack by <a href="#lua_pcall"><code>lua_pcall</code></a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4006
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4007
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4008 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4009 Typically, the message handler is used to add more debug
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4010 information to the error message, such as a stack traceback.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4011 Such information cannot be gathered after the return of <a href="#lua_pcall"><code>lua_pcall</code></a>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4012 since by then the stack has unwound.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4013
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4014
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4015 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4016 The <a href="#lua_pcall"><code>lua_pcall</code></a> function returns one of the following codes
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4017 (defined in <code>lua.h</code>):
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4018
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4019 <ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4020
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4021 <li><b><a name="pdf-LUA_OK"><code>LUA_OK</code></a> (0): </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4022 success.</li>
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 <li><b><a name="pdf-LUA_ERRRUN"><code>LUA_ERRRUN</code></a>: </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4025 a runtime error.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4026 </li>
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 <li><b><a name="pdf-LUA_ERRMEM"><code>LUA_ERRMEM</code></a>: </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4029 memory allocation error.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4030 For such errors, Lua does not call the message handler.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4031 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4032
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4033 <li><b><a name="pdf-LUA_ERRERR"><code>LUA_ERRERR</code></a>: </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4034 error while running the message handler.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4035 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4036
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4037 <li><b><a name="pdf-LUA_ERRGCMM"><code>LUA_ERRGCMM</code></a>: </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4038 error while running a <code>__gc</code> metamethod.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4039 (This error typically has no relation with the function being called.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4040 It is generated by the garbage collector.)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4041 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4042
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4043 </ul>
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4048 <hr><h3><a name="lua_pcallk"><code>lua_pcallk</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4049 <span class="apii">[-(nargs + 1), +(nresults|1), &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4050 <pre>int lua_pcallk (lua_State *L,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4051 int nargs,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4052 int nresults,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4053 int errfunc,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4054 int ctx,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4055 lua_CFunction k);</pre>
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 This function behaves exactly like <a href="#lua_pcall"><code>lua_pcall</code></a>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4059 but allows the called function to yield (see <a href="#4.7">&sect;4.7</a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4060
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4061
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4062
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4063
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4064
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4065 <hr><h3><a name="lua_pop"><code>lua_pop</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4066 <span class="apii">[-n, +0, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4067 <pre>void lua_pop (lua_State *L, int n);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4068
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4069 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4070 Pops <code>n</code> elements from the stack.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4071
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4072
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4073
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4074
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4075
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4076 <hr><h3><a name="lua_pushboolean"><code>lua_pushboolean</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4077 <span class="apii">[-0, +1, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4078 <pre>void lua_pushboolean (lua_State *L, int b);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4079
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4080 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4081 Pushes a boolean value with value <code>b</code> onto the stack.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4082
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4083
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4084
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4085
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4086
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4087 <hr><h3><a name="lua_pushcclosure"><code>lua_pushcclosure</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4088 <span class="apii">[-n, +1, <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4089 <pre>void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4090
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4091 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4092 Pushes a new C&nbsp;closure onto the stack.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4093
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4094
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4095 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4096 When a C&nbsp;function is created,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4097 it is possible to associate some values with it,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4098 thus creating a C&nbsp;closure (see <a href="#4.4">&sect;4.4</a>);
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4099 these values are then accessible to the function whenever it is called.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4100 To associate values with a C&nbsp;function,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4101 first these values should be pushed onto the stack
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4102 (when there are multiple values, the first value is pushed first).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4103 Then <a href="#lua_pushcclosure"><code>lua_pushcclosure</code></a>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4104 is called to create and push the C&nbsp;function onto the stack,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4105 with the argument <code>n</code> telling how many values should be
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4106 associated with the function.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4107 <a href="#lua_pushcclosure"><code>lua_pushcclosure</code></a> also pops these values from the stack.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4108
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4109
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4110 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4111 The maximum value for <code>n</code> is 255.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
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 When <code>n</code> is zero,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4116 this function creates a <em>light C function</em>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4117 which is just a pointer to the C&nbsp;function.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4118 In that case, it never throws a memory error.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4119
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4120
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4121
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4122
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4123
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4124 <hr><h3><a name="lua_pushcfunction"><code>lua_pushcfunction</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4125 <span class="apii">[-0, +1, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4126 <pre>void lua_pushcfunction (lua_State *L, lua_CFunction f);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4127
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4128 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4129 Pushes a C&nbsp;function onto the stack.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4130 This function receives a pointer to a C function
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4131 and pushes onto the stack a Lua value of type <code>function</code> that,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4132 when called, invokes the corresponding C&nbsp;function.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4133
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4134
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4135 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4136 Any function to be registered in Lua must
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4137 follow the correct protocol to receive its parameters
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4138 and return its results (see <a href="#lua_CFunction"><code>lua_CFunction</code></a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4139
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4142 <code>lua_pushcfunction</code> is defined as a macro:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4143
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4144 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4145 #define lua_pushcfunction(L,f) lua_pushcclosure(L,f,0)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4146 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4147 Note that <code>f</code> is used twice.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4148
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4149
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4150
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4151
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4152
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4153 <hr><h3><a name="lua_pushfstring"><code>lua_pushfstring</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4154 <span class="apii">[-0, +1, <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4155 <pre>const char *lua_pushfstring (lua_State *L, const char *fmt, ...);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4156
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4157 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4158 Pushes onto the stack a formatted string
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4159 and returns a pointer to this string.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4160 It is similar to 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
4161 but has some important differences:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4162
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4163 <ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4164
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4165 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4166 You do not have to allocate space for the result:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4167 the result is a Lua string and Lua takes care of memory allocation
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4168 (and deallocation, through garbage collection).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4169 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4170
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4171 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4172 The conversion specifiers are quite restricted.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4173 There are no flags, widths, or precisions.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4174 The conversion specifiers can only be
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4175 '<code>%%</code>' (inserts a '<code>%</code>' in the string),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4176 '<code>%s</code>' (inserts a zero-terminated string, with no size restrictions),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4177 '<code>%f</code>' (inserts a <a href="#lua_Number"><code>lua_Number</code></a>),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4178 '<code>%p</code>' (inserts a pointer as a hexadecimal numeral),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4179 '<code>%d</code>' (inserts an <code>int</code>), and
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4180 '<code>%c</code>' (inserts an <code>int</code> as a byte).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4181 </li>
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 </ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4184
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4185
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4186
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4187
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4188 <hr><h3><a name="lua_pushglobaltable"><code>lua_pushglobaltable</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4189 <span class="apii">[-0, +1, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4190 <pre>void lua_pushglobaltable (lua_State *L);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4191
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4192 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4193 Pushes the global environment onto the stack.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4194
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4195
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4196
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4197
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4198
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4199 <hr><h3><a name="lua_pushinteger"><code>lua_pushinteger</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4200 <span class="apii">[-0, +1, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4201 <pre>void lua_pushinteger (lua_State *L, lua_Integer n);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4202
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4203 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4204 Pushes a number with value <code>n</code> onto the stack.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4205
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4206
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4207
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4208
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4209
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4210 <hr><h3><a name="lua_pushlightuserdata"><code>lua_pushlightuserdata</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4211 <span class="apii">[-0, +1, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4212 <pre>void lua_pushlightuserdata (lua_State *L, void *p);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4213
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4214 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4215 Pushes a light userdata onto the stack.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4216
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4217
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4218 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4219 Userdata represent C&nbsp;values in Lua.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4220 A <em>light userdata</em> represents a pointer, a <code>void*</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4221 It is a value (like a number):
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4222 you do not create it, it has no individual metatable,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4223 and it is not collected (as it was never created).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4224 A light userdata is equal to "any"
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4225 light userdata with the same C&nbsp;address.
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 <hr><h3><a name="lua_pushliteral"><code>lua_pushliteral</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4232 <span class="apii">[-0, +1, <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4233 <pre>const char *lua_pushliteral (lua_State *L, const char *s);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4234
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4235 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4236 This macro is equivalent to <a href="#lua_pushlstring"><code>lua_pushlstring</code></a>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4237 but can be used only when <code>s</code> is a literal string.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4238 It automatically provides the string length.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4240
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4241
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4242
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4243
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4244 <hr><h3><a name="lua_pushlstring"><code>lua_pushlstring</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4245 <span class="apii">[-0, +1, <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4246 <pre>const char *lua_pushlstring (lua_State *L, const char *s, size_t len);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4247
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4248 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4249 Pushes the string pointed to by <code>s</code> with size <code>len</code>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4250 onto the stack.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4251 Lua makes (or reuses) an internal copy of the given string,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4252 so the memory at <code>s</code> can be freed or reused immediately after
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4253 the function returns.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4254 The string can contain any binary data,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4255 including embedded zeros.
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 Returns a pointer to the internal copy of the string.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4260
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4261
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4262
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4263
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4264
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4265 <hr><h3><a name="lua_pushnil"><code>lua_pushnil</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4266 <span class="apii">[-0, +1, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4267 <pre>void lua_pushnil (lua_State *L);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4268
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4269 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4270 Pushes a nil value onto the stack.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4271
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4272
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4273
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4274
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4275
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4276 <hr><h3><a name="lua_pushnumber"><code>lua_pushnumber</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4277 <span class="apii">[-0, +1, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4278 <pre>void lua_pushnumber (lua_State *L, lua_Number n);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4279
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4280 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4281 Pushes a number with value <code>n</code> onto the stack.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4282
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4283
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4284
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4285
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4286
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4287 <hr><h3><a name="lua_pushstring"><code>lua_pushstring</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4288 <span class="apii">[-0, +1, <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4289 <pre>const char *lua_pushstring (lua_State *L, const char *s);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4290
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4291 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4292 Pushes the zero-terminated string pointed to by <code>s</code>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4293 onto the stack.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4294 Lua makes (or reuses) an internal copy of the given string,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4295 so the memory at <code>s</code> can be freed or reused immediately after
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4296 the function returns.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4297
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4298
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4299 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4300 Returns a pointer to the internal copy of the string.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4301
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4302
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4303 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4304 If <code>s</code> is <code>NULL</code>, pushes <b>nil</b> and returns <code>NULL</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4305
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4306
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4307
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4308
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4309
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4310 <hr><h3><a name="lua_pushthread"><code>lua_pushthread</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4311 <span class="apii">[-0, +1, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4312 <pre>int lua_pushthread (lua_State *L);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4313
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4314 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4315 Pushes the thread represented by <code>L</code> onto the stack.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4316 Returns 1 if this thread is the main thread of its state.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4317
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4318
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4319
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4320
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4321
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4322 <hr><h3><a name="lua_pushunsigned"><code>lua_pushunsigned</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4323 <span class="apii">[-0, +1, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4324 <pre>void lua_pushunsigned (lua_State *L, lua_Unsigned n);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4325
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4326 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4327 Pushes a number with value <code>n</code> onto the stack.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4328
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4329
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4330
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4331
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4332
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4333 <hr><h3><a name="lua_pushvalue"><code>lua_pushvalue</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4334 <span class="apii">[-0, +1, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4335 <pre>void lua_pushvalue (lua_State *L, int index);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4336
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4337 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4338 Pushes a copy of the element at the given index
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4339 onto the stack.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4340
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4341
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4342
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4343
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4344
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4345 <hr><h3><a name="lua_pushvfstring"><code>lua_pushvfstring</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4346 <span class="apii">[-0, +1, <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4347 <pre>const char *lua_pushvfstring (lua_State *L,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4348 const char *fmt,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4349 va_list argp);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4350
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4351 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4352 Equivalent to <a href="#lua_pushfstring"><code>lua_pushfstring</code></a>, except that it receives a <code>va_list</code>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4353 instead of a variable number of arguments.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4354
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4355
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4356
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4357
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4358
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4359 <hr><h3><a name="lua_rawequal"><code>lua_rawequal</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4360 <span class="apii">[-0, +0, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4361 <pre>int lua_rawequal (lua_State *L, int index1, int index2);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4362
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4363 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4364 Returns 1 if the two values in indices <code>index1</code> and
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4365 <code>index2</code> are primitively equal
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4366 (that is, without calling metamethods).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4367 Otherwise returns&nbsp;0.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4368 Also returns&nbsp;0 if any of the indices are non valid.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4369
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4370
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4371
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4372
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4373
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4374 <hr><h3><a name="lua_rawget"><code>lua_rawget</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4375 <span class="apii">[-1, +1, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4376 <pre>void lua_rawget (lua_State *L, int index);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4377
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4378 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4379 Similar to <a href="#lua_gettable"><code>lua_gettable</code></a>, but does a raw access
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4380 (i.e., without metamethods).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4381
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4382
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4383
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4384
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4385
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4386 <hr><h3><a name="lua_rawgeti"><code>lua_rawgeti</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4387 <span class="apii">[-0, +1, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4388 <pre>void lua_rawgeti (lua_State *L, int index, int n);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4389
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4390 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4391 Pushes onto the stack the value <code>t[n]</code>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4392 where <code>t</code> is the table at the given index.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4393 The access is raw;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4394 that is, it does not invoke metamethods.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4395
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4396
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4397
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4398
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4399
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4400 <hr><h3><a name="lua_rawgetp"><code>lua_rawgetp</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4401 <span class="apii">[-0, +1, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4402 <pre>void lua_rawgetp (lua_State *L, int index, const void *p);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4403
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4404 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4405 Pushes onto the stack the value <code>t[k]</code>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4406 where <code>t</code> is the table at the given index and
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4407 <code>k</code> is the pointer <code>p</code> represented as a light userdata.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4408 The access is raw;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4409 that is, it does not invoke metamethods.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4410
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4411
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4412
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4413
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4414
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4415 <hr><h3><a name="lua_rawlen"><code>lua_rawlen</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4416 <span class="apii">[-0, +0, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4417 <pre>size_t lua_rawlen (lua_State *L, int index);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4418
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4419 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4420 Returns the raw "length" of the value at the given index:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4421 for strings, this is the string length;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4422 for tables, this is the result of the length operator ('<code>#</code>')
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4423 with no metamethods;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4424 for userdata, this is the size of the block of memory allocated
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4425 for the userdata;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4426 for other values, it is&nbsp;0.
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4432 <hr><h3><a name="lua_rawset"><code>lua_rawset</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4433 <span class="apii">[-2, +0, <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4434 <pre>void lua_rawset (lua_State *L, int index);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4435
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4436 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4437 Similar to <a href="#lua_settable"><code>lua_settable</code></a>, but does a raw assignment
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4438 (i.e., without metamethods).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4439
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4440
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4441
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4442
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4443
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4444 <hr><h3><a name="lua_rawseti"><code>lua_rawseti</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4445 <span class="apii">[-1, +0, <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4446 <pre>void lua_rawseti (lua_State *L, int index, int n);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4447
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4448 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4449 Does the equivalent of <code>t[n] = v</code>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4450 where <code>t</code> is the table at the given index
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4451 and <code>v</code> is the value at the top of the stack.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4452
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4453
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4454 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4455 This function pops the value from the stack.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4456 The assignment is raw;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4457 that is, it does not invoke metamethods.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4458
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4459
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4460
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4461
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4462
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4463 <hr><h3><a name="lua_rawsetp"><code>lua_rawsetp</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4464 <span class="apii">[-1, +0, <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4465 <pre>void lua_rawsetp (lua_State *L, int index, const void *p);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4466
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4467 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4468 Does the equivalent of <code>t[k] = v</code>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4469 where <code>t</code> is the table at the given index,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4470 <code>k</code> is the pointer <code>p</code> represented as a light userdata,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4471 and <code>v</code> is the value at the top of the stack.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
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 This function pops the value from the stack.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4476 The assignment is raw;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4477 that is, it does not invoke metamethods.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4478
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4479
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4480
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4481
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4482
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4483 <hr><h3><a name="lua_Reader"><code>lua_Reader</code></a></h3>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4484 <pre>typedef const char * (*lua_Reader) (lua_State *L,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4485 void *data,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4486 size_t *size);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4487
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4488 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4489 The reader function used by <a href="#lua_load"><code>lua_load</code></a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4490 Every time it needs another piece of the chunk,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4491 <a href="#lua_load"><code>lua_load</code></a> calls the reader,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4492 passing along its <code>data</code> parameter.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4493 The reader must return a pointer to a block of memory
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4494 with a new piece of the chunk
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4495 and set <code>size</code> to the block size.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4496 The block must exist until the reader function is called again.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4497 To signal the end of the chunk,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4498 the reader must return <code>NULL</code> or set <code>size</code> to zero.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4499 The reader function may return pieces of any size greater than zero.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4500
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4501
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4502
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4503
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4504
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4505 <hr><h3><a name="lua_register"><code>lua_register</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4506 <span class="apii">[-0, +0, <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4507 <pre>void lua_register (lua_State *L, const char *name, lua_CFunction f);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4508
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4509 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4510 Sets the C function <code>f</code> as the new value of global <code>name</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4511 It is defined as a macro:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4512
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4513 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4514 #define lua_register(L,n,f) \
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4515 (lua_pushcfunction(L, f), lua_setglobal(L, n))
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4516 </pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4517
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4518
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4519
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4520
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4521 <hr><h3><a name="lua_remove"><code>lua_remove</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4522 <span class="apii">[-1, +0, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4523 <pre>void lua_remove (lua_State *L, int index);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4524
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4525 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4526 Removes the element at the given valid index,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4527 shifting down the elements above this index to fill the gap.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4528 This function cannot be called with a pseudo-index,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4529 because a pseudo-index is not an actual stack position.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4530
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4531
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4532
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4533
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4534
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4535 <hr><h3><a name="lua_replace"><code>lua_replace</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4536 <span class="apii">[-1, +0, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4537 <pre>void lua_replace (lua_State *L, int index);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4538
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4539 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4540 Moves the top element into the given valid index
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4541 without shifting any element
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4542 (therefore replacing the value at the given index),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4543 and then pops the top element.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4544
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4545
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4546
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4547
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4548
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4549 <hr><h3><a name="lua_resume"><code>lua_resume</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4550 <span class="apii">[-?, +?, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4551 <pre>int lua_resume (lua_State *L, lua_State *from, int nargs);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4552
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4553 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4554 Starts and resumes a coroutine in a given thread.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4555
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4556
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4557 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4558 To start a coroutine,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4559 you push onto the thread stack the main function plus any arguments;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4560 then you call <a href="#lua_resume"><code>lua_resume</code></a>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4561 with <code>nargs</code> being the number of arguments.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4562 This call returns when the coroutine suspends or finishes its execution.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4563 When it returns, the stack contains all values passed to <a href="#lua_yield"><code>lua_yield</code></a>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4564 or all values returned by the body function.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4565 <a href="#lua_resume"><code>lua_resume</code></a> returns
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4566 <a href="#pdf-LUA_YIELD"><code>LUA_YIELD</code></a> if the coroutine yields,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4567 <a href="#pdf-LUA_OK"><code>LUA_OK</code></a> if the coroutine finishes its execution
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4568 without errors,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4569 or an error code in case of errors (see <a href="#lua_pcall"><code>lua_pcall</code></a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
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 In case of errors,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4574 the stack is not unwound,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4575 so you can use the debug API over it.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4576 The error message is on the top of the stack.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4577
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4578
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4579 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4580 To resume a coroutine,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4581 you remove any results from the last <a href="#lua_yield"><code>lua_yield</code></a>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4582 put on its stack only the values to
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4583 be passed as results from <code>yield</code>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4584 and then call <a href="#lua_resume"><code>lua_resume</code></a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4585
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4586
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4587 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4588 The parameter <code>from</code> represents the coroutine that is resuming <code>L</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4589 If there is no such coroutine,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4590 this parameter can be <code>NULL</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4591
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4592
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4593
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4594
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4595
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4596 <hr><h3><a name="lua_setallocf"><code>lua_setallocf</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4597 <span class="apii">[-0, +0, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4598 <pre>void lua_setallocf (lua_State *L, lua_Alloc f, void *ud);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4599
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4600 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4601 Changes the allocator function of a given state to <code>f</code>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4602 with user data <code>ud</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4603
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4604
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4605
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4606
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4607
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4608 <hr><h3><a name="lua_setfield"><code>lua_setfield</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4609 <span class="apii">[-1, +0, <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4610 <pre>void lua_setfield (lua_State *L, int index, const char *k);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4611
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4612 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4613 Does the equivalent to <code>t[k] = v</code>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4614 where <code>t</code> is the value at the given index
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4615 and <code>v</code> is the value at the top of the stack.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4619 This function pops the value from the stack.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4620 As in Lua, this function may trigger a metamethod
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4621 for the "newindex" event (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
4622
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4623
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4624
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4625
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4626
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4627 <hr><h3><a name="lua_setglobal"><code>lua_setglobal</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4628 <span class="apii">[-1, +0, <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4629 <pre>void lua_setglobal (lua_State *L, const char *name);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4630
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4631 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4632 Pops a value from the stack and
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4633 sets it as the new value of global <code>name</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4639 <hr><h3><a name="lua_setmetatable"><code>lua_setmetatable</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4640 <span class="apii">[-1, +0, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4641 <pre>void lua_setmetatable (lua_State *L, int index);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4642
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4643 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4644 Pops a table from the stack and
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4645 sets it as the new metatable for the value at the given index.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4646
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4647
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4648
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4649
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4650
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4651 <hr><h3><a name="lua_settable"><code>lua_settable</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4652 <span class="apii">[-2, +0, <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4653 <pre>void lua_settable (lua_State *L, int index);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
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 Does the equivalent to <code>t[k] = v</code>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4657 where <code>t</code> is the value at the given index,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4658 <code>v</code> is the value at the top of the stack,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4659 and <code>k</code> is the value just below the top.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4660
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4661
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4662 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4663 This function pops both the key and the value from the stack.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4664 As in Lua, this function may trigger a metamethod
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4665 for the "newindex" event (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
4666
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4667
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4668
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4669
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4670
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4671 <hr><h3><a name="lua_settop"><code>lua_settop</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4672 <span class="apii">[-?, +?, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4673 <pre>void lua_settop (lua_State *L, int index);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4674
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4675 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4676 Accepts any index, or&nbsp;0,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4677 and sets the stack top to this index.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4678 If the new top is larger than the old one,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4679 then the new elements are filled with <b>nil</b>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4680 If <code>index</code> is&nbsp;0, then all stack elements are removed.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4681
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4682
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4683
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4684
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4685
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4686 <hr><h3><a name="lua_setuservalue"><code>lua_setuservalue</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4687 <span class="apii">[-1, +0, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4688 <pre>void lua_setuservalue (lua_State *L, int index);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4689
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4690 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4691 Pops a table or <b>nil</b> from the stack and sets it as
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4692 the new value associated to the userdata at the given index.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4693
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4694
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4695
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4696
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4697
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4698 <hr><h3><a name="lua_State"><code>lua_State</code></a></h3>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4699 <pre>typedef struct lua_State lua_State;</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4700
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4701 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4702 An opaque structure that points to a thread and indirectly
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4703 (through the thread) to the whole state of a Lua interpreter.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4704 The Lua library is fully reentrant:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4705 it has no global variables.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4706 All information about a state is accessible through this structure.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4707
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4708
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4709 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4710 A pointer to this structure must be passed as the first argument to
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4711 every function in the library, except to <a href="#lua_newstate"><code>lua_newstate</code></a>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4712 which creates a Lua state from scratch.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4713
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4714
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4715
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4716
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4717
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4718 <hr><h3><a name="lua_status"><code>lua_status</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4719 <span class="apii">[-0, +0, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4720 <pre>int lua_status (lua_State *L);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4721
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4722 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4723 Returns the status of the thread <code>L</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4724
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4725
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4726 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4727 The status can be 0 (<a href="#pdf-LUA_OK"><code>LUA_OK</code></a>) for a normal thread,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4728 an error code if the thread finished the execution
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4729 of a <a href="#lua_resume"><code>lua_resume</code></a> with an error,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4730 or <a name="pdf-LUA_YIELD"><code>LUA_YIELD</code></a> if the thread is suspended.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4731
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4734 You can only call functions in threads with status <a href="#pdf-LUA_OK"><code>LUA_OK</code></a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4735 You can resume threads with status <a href="#pdf-LUA_OK"><code>LUA_OK</code></a>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4736 (to start a new coroutine) or <a href="#pdf-LUA_YIELD"><code>LUA_YIELD</code></a>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4737 (to resume a coroutine).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4738
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4739
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4740
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4741
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4742
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4743 <hr><h3><a name="lua_toboolean"><code>lua_toboolean</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4744 <span class="apii">[-0, +0, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4745 <pre>int lua_toboolean (lua_State *L, int index);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
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 Converts the Lua value at the given index to a C&nbsp;boolean
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4749 value (0&nbsp;or&nbsp;1).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4750 Like all tests in Lua,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4751 <a href="#lua_toboolean"><code>lua_toboolean</code></a> returns true for any Lua value
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4752 different from <b>false</b> and <b>nil</b>;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4753 otherwise it returns false.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4754 (If you want to accept only actual boolean values,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4755 use <a href="#lua_isboolean"><code>lua_isboolean</code></a> to test the value's type.)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4756
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4757
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4758
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4759
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4760
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4761 <hr><h3><a name="lua_tocfunction"><code>lua_tocfunction</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4762 <span class="apii">[-0, +0, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4763 <pre>lua_CFunction lua_tocfunction (lua_State *L, int index);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4764
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4765 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4766 Converts a value at the given index to a C&nbsp;function.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4767 That value must be a C&nbsp;function;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4768 otherwise, returns <code>NULL</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4769
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4770
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4771
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4772
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4773
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4774 <hr><h3><a name="lua_tointeger"><code>lua_tointeger</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4775 <span class="apii">[-0, +0, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4776 <pre>lua_Integer lua_tointeger (lua_State *L, int index);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4777
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4778 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4779 Equivalent to <a href="#lua_tointegerx"><code>lua_tointegerx</code></a> with <code>isnum</code> equal to <code>NULL</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4780
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4781
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4782
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4783
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4784
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4785 <hr><h3><a name="lua_tointegerx"><code>lua_tointegerx</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4786 <span class="apii">[-0, +0, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4787 <pre>lua_Integer lua_tointegerx (lua_State *L, int index, int *isnum);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4788
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4789 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4790 Converts the Lua value at the given index
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4791 to the signed integral type <a href="#lua_Integer"><code>lua_Integer</code></a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4792 The Lua value must be a number or a string convertible to a number
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4793 (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
4794 otherwise, <code>lua_tointegerx</code> returns&nbsp;0.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4795
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4796
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4797 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4798 If the number is not an integer,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4799 it is truncated in some non-specified way.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4800
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4801
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4802 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4803 If <code>isnum</code> is not <code>NULL</code>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4804 its referent is assigned a boolean value that
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4805 indicates whether the operation succeeded.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4806
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4807
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4808
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4809
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4810
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4811 <hr><h3><a name="lua_tolstring"><code>lua_tolstring</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4812 <span class="apii">[-0, +0, <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4813 <pre>const char *lua_tolstring (lua_State *L, int index, size_t *len);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4814
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4815 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4816 Converts the Lua value at the given index to a C&nbsp;string.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4817 If <code>len</code> is not <code>NULL</code>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4818 it also sets <code>*len</code> with the string length.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4819 The Lua value must be a string or a number;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4820 otherwise, the function returns <code>NULL</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4821 If the value is a number,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4822 then <code>lua_tolstring</code> also
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4823 <em>changes the actual value in the stack to a string</em>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4824 (This change confuses <a href="#lua_next"><code>lua_next</code></a>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4825 when <code>lua_tolstring</code> is applied to keys during a table traversal.)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4826
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4827
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4828 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4829 <code>lua_tolstring</code> returns a fully aligned pointer
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4830 to a string inside the Lua state.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4831 This string always has a zero ('<code>\0</code>')
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4832 after its last character (as in&nbsp;C),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4833 but can contain other zeros in its body.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4834 Because Lua has garbage collection,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4835 there is no guarantee that the pointer returned by <code>lua_tolstring</code>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4836 will be valid after the corresponding value is removed from the stack.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4837
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4838
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4839
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4840
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4841
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4842 <hr><h3><a name="lua_tonumber"><code>lua_tonumber</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4843 <span class="apii">[-0, +0, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4844 <pre>lua_Number lua_tonumber (lua_State *L, int index);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4845
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4846 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4847 Equivalent to <a href="#lua_tonumberx"><code>lua_tonumberx</code></a> with <code>isnum</code> equal to <code>NULL</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4848
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4849
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4850
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4851
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4852
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4853 <hr><h3><a name="lua_tonumberx"><code>lua_tonumberx</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4854 <span class="apii">[-0, +0, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4855 <pre>lua_Number lua_tonumberx (lua_State *L, int index, int *isnum);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4856
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4857 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4858 Converts the Lua value at the given index
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4859 to the C&nbsp;type <a href="#lua_Number"><code>lua_Number</code></a> (see <a href="#lua_Number"><code>lua_Number</code></a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4860 The Lua value must be a number or a string convertible to a number
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4861 (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
4862 otherwise, <a href="#lua_tonumberx"><code>lua_tonumberx</code></a> returns&nbsp;0.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4863
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4864
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4865 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4866 If <code>isnum</code> is not <code>NULL</code>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4867 its referent is assigned a boolean value that
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4868 indicates whether the operation succeeded.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4869
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4870
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4871
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4872
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4873
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4874 <hr><h3><a name="lua_topointer"><code>lua_topointer</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4875 <span class="apii">[-0, +0, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4876 <pre>const void *lua_topointer (lua_State *L, int index);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4877
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4878 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4879 Converts the value at the given index to a generic
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4880 C&nbsp;pointer (<code>void*</code>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4881 The value can be a userdata, a table, a thread, or a function;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4882 otherwise, <code>lua_topointer</code> returns <code>NULL</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4883 Different objects will give different pointers.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4884 There is no way to convert the pointer back to its original value.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4885
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4886
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4887 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4888 Typically this function is used only for debug information.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4889
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4890
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4891
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4892
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4893
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4894 <hr><h3><a name="lua_tostring"><code>lua_tostring</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4895 <span class="apii">[-0, +0, <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4896 <pre>const char *lua_tostring (lua_State *L, int index);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4897
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4898 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4899 Equivalent to <a href="#lua_tolstring"><code>lua_tolstring</code></a> with <code>len</code> equal to <code>NULL</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
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 <hr><h3><a name="lua_tothread"><code>lua_tothread</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4906 <span class="apii">[-0, +0, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4907 <pre>lua_State *lua_tothread (lua_State *L, int index);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
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 Converts the value at the given index to a Lua thread
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4911 (represented as <code>lua_State*</code>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4912 This value must be a thread;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4913 otherwise, the function returns <code>NULL</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4914
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4915
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4916
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4917
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4918
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4919 <hr><h3><a name="lua_tounsigned"><code>lua_tounsigned</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4920 <span class="apii">[-0, +0, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4921 <pre>lua_Unsigned lua_tounsigned (lua_State *L, int index);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
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 Equivalent to <a href="#lua_tounsignedx"><code>lua_tounsignedx</code></a> with <code>isnum</code> equal to <code>NULL</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4925
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4926
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4927
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4928
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4929
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4930 <hr><h3><a name="lua_tounsignedx"><code>lua_tounsignedx</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4931 <span class="apii">[-0, +0, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4932 <pre>lua_Unsigned lua_tounsignedx (lua_State *L, int index, int *isnum);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4933
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4934 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4935 Converts the Lua value at the given index
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4936 to the unsigned integral type <a href="#lua_Unsigned"><code>lua_Unsigned</code></a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4937 The Lua value must be a number or a string convertible to a number
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4938 (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
4939 otherwise, <code>lua_tounsignedx</code> returns&nbsp;0.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4940
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4941
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4942 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4943 If the number is not an integer,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4944 it is truncated in some non-specified way.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4945 If the number is outside the range of representable values,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4946 it is normalized to the remainder of its division by
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4947 one more than the maximum representable value.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4948
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4951 If <code>isnum</code> is not <code>NULL</code>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4952 its referent is assigned a boolean value that
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4953 indicates whether the operation succeeded.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4954
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4955
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4956
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4957
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4958
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4959 <hr><h3><a name="lua_touserdata"><code>lua_touserdata</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4960 <span class="apii">[-0, +0, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4961 <pre>void *lua_touserdata (lua_State *L, int index);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4962
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4963 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4964 If the value at the given index is a full userdata,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4965 returns its block address.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4966 If the value is a light userdata,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4967 returns its pointer.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4968 Otherwise, returns <code>NULL</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4969
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4970
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4971
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4972
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4973
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4974 <hr><h3><a name="lua_type"><code>lua_type</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4975 <span class="apii">[-0, +0, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4976 <pre>int lua_type (lua_State *L, int index);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4977
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4978 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4979 Returns the type of the value in the given valid index,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4980 or <code>LUA_TNONE</code> for a non-valid (but acceptable) index.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4981 The types returned by <a href="#lua_type"><code>lua_type</code></a> are coded by the following constants
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4982 defined in <code>lua.h</code>:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4983 <a name="pdf-LUA_TNIL"><code>LUA_TNIL</code></a>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4984 <a name="pdf-LUA_TNUMBER"><code>LUA_TNUMBER</code></a>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4985 <a name="pdf-LUA_TBOOLEAN"><code>LUA_TBOOLEAN</code></a>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4986 <a name="pdf-LUA_TSTRING"><code>LUA_TSTRING</code></a>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4987 <a name="pdf-LUA_TTABLE"><code>LUA_TTABLE</code></a>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4988 <a name="pdf-LUA_TFUNCTION"><code>LUA_TFUNCTION</code></a>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4989 <a name="pdf-LUA_TUSERDATA"><code>LUA_TUSERDATA</code></a>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4990 <a name="pdf-LUA_TTHREAD"><code>LUA_TTHREAD</code></a>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4991 and
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4992 <a name="pdf-LUA_TLIGHTUSERDATA"><code>LUA_TLIGHTUSERDATA</code></a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4993
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4994
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4995
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4996
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4997
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4998 <hr><h3><a name="lua_typename"><code>lua_typename</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4999 <span class="apii">[-0, +0, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5000 <pre>const char *lua_typename (lua_State *L, int tp);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5001
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5002 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5003 Returns the name of the type encoded by the value <code>tp</code>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5004 which must be one the values returned by <a href="#lua_type"><code>lua_type</code></a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5010 <hr><h3><a name="lua_Unsigned"><code>lua_Unsigned</code></a></h3>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5011 <pre>typedef unsigned long lua_Unsigned;</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
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 The type used by the Lua API to represent unsigned integral values.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5015 It must have at least 32 bits.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5016
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5017
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5018 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5019 By default it is an <code>unsigned int</code> or an <code>unsigned long</code>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5020 whichever can hold 32-bit values.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5021
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5022
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5023
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5024
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5025
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5026 <hr><h3><a name="lua_upvalueindex"><code>lua_upvalueindex</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5027 <span class="apii">[-0, +0, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5028 <pre>int lua_upvalueindex (int i);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
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 Returns the pseudo-index that represents the <code>i</code>-th upvalue of
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5032 the running function (see <a href="#4.4">&sect;4.4</a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5033
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5034
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5035
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5036
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5037
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5038 <hr><h3><a name="lua_version"><code>lua_version</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5039 <span class="apii">[-0, +0, <em>v</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5040 <pre>const lua_Number *lua_version (lua_State *L);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5041
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5042 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5043 Returns the address of the version number stored in the Lua core.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5044 When called with a valid <a href="#lua_State"><code>lua_State</code></a>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5045 returns the address of the version used to create that state.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5046 When called with <code>NULL</code>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5047 returns the address of the version running the call.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5048
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5049
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5050
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5051
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5052
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5053 <hr><h3><a name="lua_Writer"><code>lua_Writer</code></a></h3>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5054 <pre>typedef int (*lua_Writer) (lua_State *L,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5055 const void* p,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5056 size_t sz,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5057 void* ud);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5058
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5059 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5060 The type of the writer function used by <a href="#lua_dump"><code>lua_dump</code></a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5061 Every time it produces another piece of chunk,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5062 <a href="#lua_dump"><code>lua_dump</code></a> calls the writer,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5063 passing along the buffer to be written (<code>p</code>),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5064 its size (<code>sz</code>),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5065 and the <code>data</code> parameter supplied to <a href="#lua_dump"><code>lua_dump</code></a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
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 The writer returns an error code:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5070 0&nbsp;means no errors;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5071 any other value means an error and stops <a href="#lua_dump"><code>lua_dump</code></a> from
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5072 calling the writer again.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5073
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5074
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5075
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5076
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5077
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5078 <hr><h3><a name="lua_xmove"><code>lua_xmove</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5079 <span class="apii">[-?, +?, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5080 <pre>void lua_xmove (lua_State *from, lua_State *to, int n);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5081
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5082 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5083 Exchange values between different threads of the same state.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5087 This function pops <code>n</code> values from the stack <code>from</code>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5088 and pushes them onto the stack <code>to</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5089
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5090
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5091
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5092
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5093
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5094 <hr><h3><a name="lua_yield"><code>lua_yield</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5095 <span class="apii">[-?, +?, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5096 <pre>int lua_yield (lua_State *L, int nresults);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5097
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5098 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5099 This function is equivalent to <a href="#lua_yieldk"><code>lua_yieldk</code></a>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5100 but it has no continuation (see <a href="#4.7">&sect;4.7</a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5101 Therefore, when the thread resumes,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5102 it returns to the function that called
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5103 the function calling <code>lua_yield</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5104
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5105
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5106
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5107
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5108
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5109 <hr><h3><a name="lua_yieldk"><code>lua_yieldk</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5110 <span class="apii">[-?, +?, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5111 <pre>int lua_yieldk (lua_State *L, int nresults, int ctx, lua_CFunction k);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
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 Yields a coroutine.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5115
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5116
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5117 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5118 This function should only be called as the
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5119 return expression of a C&nbsp;function, as follows:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5120
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5121 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5122 return lua_yieldk (L, n, i, k);
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5123 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5124 When a C&nbsp;function calls <a href="#lua_yieldk"><code>lua_yieldk</code></a> in that way,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5125 the running coroutine suspends its execution,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5126 and the call to <a href="#lua_resume"><code>lua_resume</code></a> that started this coroutine returns.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5127 The parameter <code>nresults</code> is the number of values from the stack
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5128 that are passed as results to <a href="#lua_resume"><code>lua_resume</code></a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5129
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5130
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5131 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5132 When the coroutine is resumed again,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5133 Lua calls the given continuation function <code>k</code> to continue
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5134 the execution of the C function that yielded (see <a href="#4.7">&sect;4.7</a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5135 This continuation function receives the same stack
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5136 from the previous function,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5137 with the results removed and
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5138 replaced by the arguments passed to <a href="#lua_resume"><code>lua_resume</code></a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5139 Moreover,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5140 the continuation function may access the value <code>ctx</code>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5141 by calling <a href="#lua_getctx"><code>lua_getctx</code></a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5142
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5143
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5144
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5145
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5146
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5147
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5148
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5149 <h2>4.9 &ndash; <a name="4.9">The Debug Interface</a></h2>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
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 Lua has no built-in debugging facilities.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5153 Instead, it offers a special interface
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5154 by means of functions and <em>hooks</em>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5155 This interface allows the construction of different
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5156 kinds of debuggers, profilers, and other tools
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5157 that need "inside information" from the interpreter.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5158
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5159
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5160
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5161 <hr><h3><a name="lua_Debug"><code>lua_Debug</code></a></h3>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5162 <pre>typedef struct lua_Debug {
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5163 int event;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5164 const char *name; /* (n) */
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5165 const char *namewhat; /* (n) */
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5166 const char *what; /* (S) */
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5167 const char *source; /* (S) */
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5168 int currentline; /* (l) */
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5169 int linedefined; /* (S) */
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5170 int lastlinedefined; /* (S) */
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5171 unsigned char nups; /* (u) number of upvalues */
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5172 unsigned char nparams; /* (u) number of parameters */
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5173 char isvararg; /* (u) */
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5174 char istailcall; /* (t) */
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5175 char short_src[LUA_IDSIZE]; /* (S) */
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5176 /* private part */
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5177 <em>other fields</em>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5178 } lua_Debug;</pre>
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5181 A structure used to carry different pieces of
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5182 information about a function or an activation record.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5183 <a href="#lua_getstack"><code>lua_getstack</code></a> fills only the private part
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5184 of this structure, for later use.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5185 To fill the other fields of <a href="#lua_Debug"><code>lua_Debug</code></a> with useful information,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5186 call <a href="#lua_getinfo"><code>lua_getinfo</code></a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5187
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5188
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5189 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5190 The fields of <a href="#lua_Debug"><code>lua_Debug</code></a> have the following meaning:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5191
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5192 <ul>
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 <li><b><code>source</code>: </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5195 the source of the chunk that created the function.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5196 If <code>source</code> starts with a '<code>@</code>',
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5197 it means that the function was defined in a file where
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5198 the file name follows the '<code>@</code>'.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5199 If <code>source</code> starts with a '<code>=</code>',
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5200 the remainder of its contents describe the source in a user-dependent manner.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5201 Otherwise,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5202 the function was defined in a string where
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5203 <code>source</code> is that string.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5204 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5205
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5206 <li><b><code>short_src</code>: </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5207 a "printable" version of <code>source</code>, to be used in error messages.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5208 </li>
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 <li><b><code>linedefined</code>: </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5211 the line number where the definition of the function starts.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5212 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5213
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5214 <li><b><code>lastlinedefined</code>: </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5215 the line number where the definition of the function ends.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5216 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5217
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5218 <li><b><code>what</code>: </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5219 the string <code>"Lua"</code> if the function is a Lua function,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5220 <code>"C"</code> if it is a C&nbsp;function,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5221 <code>"main"</code> if it is the main part of a chunk.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5222 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5223
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5224 <li><b><code>currentline</code>: </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5225 the current line where the given function is executing.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5226 When no line information is available,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5227 <code>currentline</code> is set to -1.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5228 </li>
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 <li><b><code>name</code>: </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5231 a reasonable name for the given function.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5232 Because functions in Lua are first-class values,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5233 they do not have a fixed name:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5234 some functions can be the value of multiple global variables,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5235 while others can be stored only in a table field.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5236 The <code>lua_getinfo</code> function checks how the function was
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5237 called to find a suitable name.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5238 If it cannot find a name,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5239 then <code>name</code> is set to <code>NULL</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5240 </li>
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 <li><b><code>namewhat</code>: </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5243 explains the <code>name</code> field.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5244 The value of <code>namewhat</code> can be
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5245 <code>"global"</code>, <code>"local"</code>, <code>"method"</code>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5246 <code>"field"</code>, <code>"upvalue"</code>, or <code>""</code> (the empty string),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5247 according to how the function was called.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5248 (Lua uses the empty string when no other option seems to apply.)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5249 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5250
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5251 <li><b><code>istailcall</code>: </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5252 true if this function invocation was called by a tail call.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5253 In this case, the caller of this level is not in the stack.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5254 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5255
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5256 <li><b><code>nups</code>: </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5257 the number of upvalues of the function.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5258 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5259
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5260 <li><b><code>nparams</code>: </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5261 the number of fixed parameters of the function
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5262 (always 0&nbsp;for C&nbsp;functions).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5263 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5264
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5265 <li><b><code>isvararg</code>: </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5266 true if the function is a vararg function
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5267 (always true for C&nbsp;functions).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5268 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5269
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5270 </ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5271
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5272
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5273
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5274
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5275 <hr><h3><a name="lua_gethook"><code>lua_gethook</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5276 <span class="apii">[-0, +0, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5277 <pre>lua_Hook lua_gethook (lua_State *L);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5278
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5279 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5280 Returns the current hook function.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5281
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5282
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5283
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5284
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5285
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5286 <hr><h3><a name="lua_gethookcount"><code>lua_gethookcount</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5287 <span class="apii">[-0, +0, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5288 <pre>int lua_gethookcount (lua_State *L);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5289
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5290 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5291 Returns the current hook count.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5292
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5293
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5294
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5295
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5296
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5297 <hr><h3><a name="lua_gethookmask"><code>lua_gethookmask</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5298 <span class="apii">[-0, +0, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5299 <pre>int lua_gethookmask (lua_State *L);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
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 Returns the current hook mask.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5303
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5304
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5305
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5306
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5307
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5308 <hr><h3><a name="lua_getinfo"><code>lua_getinfo</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5309 <span class="apii">[-(0|1), +(0|1|2), <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5310 <pre>int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5311
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5312 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5313 Gets information about a specific function or function invocation.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5314
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5315
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5316 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5317 To get information about a function invocation,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5318 the parameter <code>ar</code> must be a valid activation record that was
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5319 filled by a previous call to <a href="#lua_getstack"><code>lua_getstack</code></a> or
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5320 given as argument to a hook (see <a href="#lua_Hook"><code>lua_Hook</code></a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5321
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5322
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5323 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5324 To get information about a function you push it onto the stack
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5325 and start the <code>what</code> string with the character '<code>&gt;</code>'.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5326 (In that case,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5327 <code>lua_getinfo</code> pops the function from the top of the stack.)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5328 For instance, to know in which line a function <code>f</code> was defined,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5329 you can write the following code:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
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 lua_Debug ar;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5333 lua_getglobal(L, "f"); /* get global 'f' */
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5334 lua_getinfo(L, "&gt;S", &amp;ar);
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5335 printf("%d\n", ar.linedefined);
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5336 </pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5337
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5338 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5339 Each character in the string <code>what</code>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5340 selects some fields of the structure <code>ar</code> to be filled or
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5341 a value to be pushed on the stack:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5342
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5343 <ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5344
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5345 <li><b>'<code>n</code>': </b> fills in the field <code>name</code> and <code>namewhat</code>;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5346 </li>
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 <li><b>'<code>S</code>': </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5349 fills in the fields <code>source</code>, <code>short_src</code>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5350 <code>linedefined</code>, <code>lastlinedefined</code>, and <code>what</code>;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5351 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5352
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5353 <li><b>'<code>l</code>': </b> fills in the field <code>currentline</code>;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5354 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5355
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5356 <li><b>'<code>t</code>': </b> fills in the field <code>istailcall</code>;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5357 </li>
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 <li><b>'<code>u</code>': </b> fills in the fields
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5360 <code>nups</code>, <code>nparams</code>, and <code>isvararg</code>;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5361 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5362
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5363 <li><b>'<code>f</code>': </b>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5364 pushes onto the stack the function that is
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5365 running at the given level;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5366 </li>
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 <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
5369 pushes onto the stack a table whose indices are the
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5370 numbers of the lines that are valid on the function.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5371 (A <em>valid line</em> is a line with some associated code,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5372 that is, a line where you can put a break point.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5373 Non-valid lines include empty lines and comments.)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5374 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5375
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5376 </ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5377
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5378 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5379 This function returns 0 on error
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5380 (for instance, an invalid option in <code>what</code>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5381
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5382
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5383
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5384
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5385
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5386 <hr><h3><a name="lua_getlocal"><code>lua_getlocal</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5387 <span class="apii">[-0, +(0|1), &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5388 <pre>const char *lua_getlocal (lua_State *L, lua_Debug *ar, int n);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5389
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5390 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5391 Gets information about a local variable of
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5392 a given activation record or a given function.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5393
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5394
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5395 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5396 In the first case,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5397 the parameter <code>ar</code> must be a valid activation record that was
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5398 filled by a previous call to <a href="#lua_getstack"><code>lua_getstack</code></a> or
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5399 given as argument to a hook (see <a href="#lua_Hook"><code>lua_Hook</code></a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5400 The index <code>n</code> selects which local variable to inspect;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5401 see <a href="#pdf-debug.getlocal"><code>debug.getlocal</code></a> for details about variable indices
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5402 and names.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5403
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5404
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5405 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5406 <a href="#lua_getlocal"><code>lua_getlocal</code></a> pushes the variable's value onto the stack
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5407 and returns its name.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5408
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5409
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5410 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5411 In the second case, <code>ar</code> should be <code>NULL</code> and the function
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5412 to be inspected must be at the top of the stack.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5413 In this case, only parameters of Lua functions are visible
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5414 (as there is no information about what variables are active)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5415 and no values are pushed onto the stack.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5416
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5417
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5418 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5419 Returns <code>NULL</code> (and pushes nothing)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5420 when the index is greater than
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5421 the number of active local variables.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5422
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5423
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5424
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5425
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5426
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5427 <hr><h3><a name="lua_getstack"><code>lua_getstack</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5428 <span class="apii">[-0, +0, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5429 <pre>int lua_getstack (lua_State *L, int level, lua_Debug *ar);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5430
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5431 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5432 Gets information about the interpreter runtime stack.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5433
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5434
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5435 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5436 This function fills parts of a <a href="#lua_Debug"><code>lua_Debug</code></a> structure with
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5437 an identification of the <em>activation record</em>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5438 of the function executing at a given level.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5439 Level&nbsp;0 is the current running function,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5440 whereas level <em>n+1</em> is the function that has called level <em>n</em>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5441 (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
5442 When there are no errors, <a href="#lua_getstack"><code>lua_getstack</code></a> returns 1;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5443 when called with a level greater than the stack depth,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5444 it returns 0.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5445
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5446
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5447
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5448
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5449
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5450 <hr><h3><a name="lua_getupvalue"><code>lua_getupvalue</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5451 <span class="apii">[-0, +(0|1), &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5452 <pre>const char *lua_getupvalue (lua_State *L, int funcindex, int n);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5453
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5454 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5455 Gets information about a closure's upvalue.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5456 (For Lua functions,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5457 upvalues are the external local variables that the function uses,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5458 and that are consequently included in its closure.)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5459 <a href="#lua_getupvalue"><code>lua_getupvalue</code></a> gets the index <code>n</code> of an upvalue,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5460 pushes the upvalue's value onto the stack,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5461 and returns its name.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5462 <code>funcindex</code> points to the closure in the stack.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5463 (Upvalues have no particular order,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5464 as they are active through the whole function.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5465 So, they are numbered in an arbitrary order.)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5466
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5467
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5468 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5469 Returns <code>NULL</code> (and pushes nothing)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5470 when the index is greater than the number of upvalues.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5471 For C&nbsp;functions, this function uses the empty string <code>""</code>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5472 as a name for all upvalues.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5473
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5474
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5475
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5476
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5477
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5478 <hr><h3><a name="lua_Hook"><code>lua_Hook</code></a></h3>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5479 <pre>typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5480
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5481 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5482 Type for debugging hook functions.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5483
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5484
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5485 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5486 Whenever a hook is called, its <code>ar</code> argument has its field
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5487 <code>event</code> set to the specific event that triggered the hook.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5488 Lua identifies these events with the following constants:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5489 <a name="pdf-LUA_HOOKCALL"><code>LUA_HOOKCALL</code></a>, <a name="pdf-LUA_HOOKRET"><code>LUA_HOOKRET</code></a>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5490 <a name="pdf-LUA_HOOKTAILCALL"><code>LUA_HOOKTAILCALL</code></a>, <a name="pdf-LUA_HOOKLINE"><code>LUA_HOOKLINE</code></a>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5491 and <a name="pdf-LUA_HOOKCOUNT"><code>LUA_HOOKCOUNT</code></a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5492 Moreover, for line events, the field <code>currentline</code> is also set.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5493 To get the value of any other field in <code>ar</code>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5494 the hook must call <a href="#lua_getinfo"><code>lua_getinfo</code></a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5495
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5496
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5497 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5498 For call events, <code>event</code> can be <code>LUA_HOOKCALL</code>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5499 the normal value, or <code>LUA_HOOKTAILCALL</code>, for a tail call;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5500 in this case, there will be no corresponding return event.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5501
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5502
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5503 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5504 While Lua is running a hook, it disables other calls to hooks.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5505 Therefore, if a hook calls back Lua to execute a function or a chunk,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5506 this execution occurs without any calls to hooks.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5507
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5508
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5509 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5510 Hook functions cannot have continuations,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5511 that is, they cannot call <a href="#lua_yieldk"><code>lua_yieldk</code></a>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5512 <a href="#lua_pcallk"><code>lua_pcallk</code></a>, or <a href="#lua_callk"><code>lua_callk</code></a> with a non-null <code>k</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5513
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5514
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5515 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5516 Hook functions can yield under the following conditions:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5517 Only count and line events can yield
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5518 and they cannot yield any value;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5519 to yield a hook function must finish its execution
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5520 calling <a href="#lua_yield"><code>lua_yield</code></a> with <code>nresults</code> equal to zero.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5521
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5522
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5523
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5524
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5525
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5526 <hr><h3><a name="lua_sethook"><code>lua_sethook</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5527 <span class="apii">[-0, +0, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5528 <pre>int lua_sethook (lua_State *L, lua_Hook f, int mask, int count);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5529
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5530 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5531 Sets the debugging hook function.
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5535 Argument <code>f</code> is the hook function.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5536 <code>mask</code> specifies on which events the hook will be called:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5537 it is formed by a bitwise or of the constants
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5538 <a name="pdf-LUA_MASKCALL"><code>LUA_MASKCALL</code></a>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5539 <a name="pdf-LUA_MASKRET"><code>LUA_MASKRET</code></a>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5540 <a name="pdf-LUA_MASKLINE"><code>LUA_MASKLINE</code></a>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5541 and <a name="pdf-LUA_MASKCOUNT"><code>LUA_MASKCOUNT</code></a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5542 The <code>count</code> argument is only meaningful when the mask
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5543 includes <code>LUA_MASKCOUNT</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5544 For each event, the hook is called as explained below:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5545
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5546 <ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5547
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5548 <li><b>The call hook: </b> is called when the interpreter calls a function.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5549 The hook is called just after Lua enters the new function,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5550 before the function gets its arguments.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5551 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5552
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5553 <li><b>The return hook: </b> is called when the interpreter returns from a function.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5554 The hook is called just before Lua leaves the function.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5555 There is no standard way to access the values
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5556 to be returned by the function.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5557 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5558
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5559 <li><b>The line hook: </b> is called when the interpreter is about to
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5560 start the execution of a new line of code,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5561 or when it jumps back in the code (even to the same line).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5562 (This event only happens while Lua is executing a Lua function.)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5563 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5564
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5565 <li><b>The count hook: </b> is called after the interpreter executes every
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5566 <code>count</code> instructions.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5567 (This event only happens while Lua is executing a Lua function.)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5568 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5569
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5570 </ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5571
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5572 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5573 A hook is disabled by setting <code>mask</code> to zero.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5574
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5575
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5576
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5577
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5578
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5579 <hr><h3><a name="lua_setlocal"><code>lua_setlocal</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5580 <span class="apii">[-(0|1), +0, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5581 <pre>const char *lua_setlocal (lua_State *L, lua_Debug *ar, int n);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5582
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5583 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5584 Sets the value of a local variable of a given activation record.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5585 Parameters <code>ar</code> and <code>n</code> are as in <a href="#lua_getlocal"><code>lua_getlocal</code></a>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5586 (see <a href="#lua_getlocal"><code>lua_getlocal</code></a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5587 <a href="#lua_setlocal"><code>lua_setlocal</code></a> assigns the value at the top of the stack
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5588 to the variable and returns its name.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5589 It also pops the value from the stack.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5590
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5591
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5592 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5593 Returns <code>NULL</code> (and pops nothing)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5594 when the index is greater than
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5595 the number of active local variables.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5596
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5597
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5598
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5599
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5600
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5601 <hr><h3><a name="lua_setupvalue"><code>lua_setupvalue</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5602 <span class="apii">[-(0|1), +0, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5603 <pre>const char *lua_setupvalue (lua_State *L, int funcindex, int n);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5604
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5605 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5606 Sets the value of a closure's upvalue.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5607 It assigns the value at the top of the stack
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5608 to the upvalue and returns its name.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5609 It also pops the value from the stack.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5610 Parameters <code>funcindex</code> and <code>n</code> are as in the <a href="#lua_getupvalue"><code>lua_getupvalue</code></a>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5611 (see <a href="#lua_getupvalue"><code>lua_getupvalue</code></a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5612
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5613
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5614 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5615 Returns <code>NULL</code> (and pops nothing)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5616 when the index is greater than the number of upvalues.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5617
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5618
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5619
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5620
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5621
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5622 <hr><h3><a name="lua_upvalueid"><code>lua_upvalueid</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5623 <span class="apii">[-0, +0, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5624 <pre>void *lua_upvalueid (lua_State *L, int funcindex, int n);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5625
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5626 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5627 Returns an unique identifier for the upvalue numbered <code>n</code>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5628 from the closure at index <code>funcindex</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5629 Parameters <code>funcindex</code> and <code>n</code> are as in the <a href="#lua_getupvalue"><code>lua_getupvalue</code></a>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5630 (see <a href="#lua_getupvalue"><code>lua_getupvalue</code></a>)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5631 (but <code>n</code> cannot be greater than the number of upvalues).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5632
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5633
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5634 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5635 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
5636 closures share upvalues.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5637 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
5638 (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
5639 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
5640
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5641
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5642
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5643
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5644
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5645 <hr><h3><a name="lua_upvaluejoin"><code>lua_upvaluejoin</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5646 <span class="apii">[-0, +0, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5647 <pre>void lua_upvaluejoin (lua_State *L, int funcindex1, int n1,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5648 int funcindex2, int n2);</pre>
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5651 Make the <code>n1</code>-th upvalue of the Lua closure at index <code>funcindex1</code>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5652 refer to the <code>n2</code>-th upvalue of the Lua closure at index <code>funcindex2</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5653
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5654
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5655
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5656
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5657
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5658
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5659
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5660 <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
5661
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5662 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5663
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5664 The <em>auxiliary library</em> provides several convenient functions
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5665 to interface C with Lua.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5666 While the basic API provides the primitive functions for all
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5667 interactions between C and Lua,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5668 the auxiliary library provides higher-level functions for some
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5669 common tasks.
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5672 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5673 All functions and types from the auxiliary library
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5674 are defined in header file <code>lauxlib.h</code> and
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5675 have a prefix <code>luaL_</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5676
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5677
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5678 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5679 All functions in the auxiliary library are built on
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5680 top of the basic API,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5681 and so they provide nothing that cannot be done with that API.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5682 Nevertheless, the use of the auxiliary library ensures
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5683 more consistency to your code.
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
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5686 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5687 Several functions in the auxiliary library use internally some
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5688 extra stack slots.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5689 When a function in the auxiliary library uses less than five slots,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5690 it does not check the stack size;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5691 it simply assumes that there are enough slots.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
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 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5695 Several functions in the auxiliary library are used to
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5696 check C&nbsp;function arguments.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5697 Because the error message is formatted for arguments
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5698 (e.g., "<code>bad argument #1</code>"),
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5699 you should not use these functions for other stack values.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5700
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5701
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5702 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5703 Functions called <code>luaL_check*</code>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5704 always throw an error if the check is not satisfied.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5705
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5706
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5707
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5708 <h2>5.1 &ndash; <a name="5.1">Functions and Types</a></h2>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5709
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5710 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5711 Here we list all functions and types from the auxiliary library
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5712 in alphabetical order.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5713
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5714
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5715
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5716 <hr><h3><a name="luaL_addchar"><code>luaL_addchar</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5717 <span class="apii">[-?, +?, <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5718 <pre>void luaL_addchar (luaL_Buffer *B, char c);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5719
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5720 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5721 Adds the byte <code>c</code> to the buffer <code>B</code>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5722 (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5723
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5724
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5725
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5726
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5727
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5728 <hr><h3><a name="luaL_addlstring"><code>luaL_addlstring</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5729 <span class="apii">[-?, +?, <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5730 <pre>void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5731
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5732 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5733 Adds the string pointed to by <code>s</code> with length <code>l</code> to
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5734 the buffer <code>B</code>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5735 (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5736 The string can contain embedded zeros.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5737
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5738
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5739
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5740
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5741
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5742 <hr><h3><a name="luaL_addsize"><code>luaL_addsize</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5743 <span class="apii">[-?, +?, <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5744 <pre>void luaL_addsize (luaL_Buffer *B, size_t n);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5745
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5746 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5747 Adds to the buffer <code>B</code> (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5748 a string of length <code>n</code> previously copied to the
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5749 buffer area (see <a href="#luaL_prepbuffer"><code>luaL_prepbuffer</code></a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5750
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5751
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5752
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5753
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5754
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5755 <hr><h3><a name="luaL_addstring"><code>luaL_addstring</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5756 <span class="apii">[-?, +?, <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5757 <pre>void luaL_addstring (luaL_Buffer *B, const char *s);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5758
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5759 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5760 Adds the zero-terminated string pointed to by <code>s</code>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5761 to the buffer <code>B</code>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5762 (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5763 The string cannot contain embedded zeros.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5764
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5765
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5766
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5767
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5768
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5769 <hr><h3><a name="luaL_addvalue"><code>luaL_addvalue</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5770 <span class="apii">[-1, +?, <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5771 <pre>void luaL_addvalue (luaL_Buffer *B);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5772
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5773 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5774 Adds the value at the top of the stack
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5775 to the buffer <code>B</code>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5776 (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5777 Pops the value.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5778
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5779
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5780 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5781 This is the only function on string buffers that can (and must)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5782 be called with an extra element on the stack,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5783 which is the value to be added to the buffer.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5784
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5785
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5786
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5787
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5788
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5789 <hr><h3><a name="luaL_argcheck"><code>luaL_argcheck</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5790 <span class="apii">[-0, +0, <em>v</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5791 <pre>void luaL_argcheck (lua_State *L,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5792 int cond,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5793 int arg,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5794 const char *extramsg);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5795
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5796 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5797 Checks whether <code>cond</code> is true.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5798 If not, raises an error with a standard message.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5799
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5800
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5801
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5802
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5803
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5804 <hr><h3><a name="luaL_argerror"><code>luaL_argerror</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5805 <span class="apii">[-0, +0, <em>v</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5806 <pre>int luaL_argerror (lua_State *L, int arg, const char *extramsg);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5807
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5808 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5809 Raises an error with a standard message
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5810 that includes <code>extramsg</code> as a comment.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5811
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5812
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5813 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5814 This function never returns,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5815 but it is an idiom to use it in C&nbsp;functions
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5816 as <code>return luaL_argerror(<em>args</em>)</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5817
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5818
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5819
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5820
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5821
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5822 <hr><h3><a name="luaL_Buffer"><code>luaL_Buffer</code></a></h3>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5823 <pre>typedef struct luaL_Buffer luaL_Buffer;</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5824
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5825 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5826 Type for a <em>string buffer</em>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5827
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5828
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5829 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5830 A string buffer allows C&nbsp;code to build Lua strings piecemeal.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5831 Its pattern of use is as follows:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5832
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5833 <ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5834
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5835 <li>First declare a variable <code>b</code> of type <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>.</li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5836
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5837 <li>Then initialize it with a call <code>luaL_buffinit(L, &amp;b)</code>.</li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5838
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5839 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5840 Then add string pieces to the buffer calling any of
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5841 the <code>luaL_add*</code> functions.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5842 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5843
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5844 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5845 Finish by calling <code>luaL_pushresult(&amp;b)</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5846 This call leaves the final string on the top of the stack.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5847 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5848
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5849 </ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5850
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5851 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5852 If you know beforehand the total size of the resulting string,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5853 you can use the buffer like this:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5854
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5855 <ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5856
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5857 <li>First declare a variable <code>b</code> of type <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>.</li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5858
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5859 <li>Then initialize it and preallocate a space of
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5860 size <code>sz</code> with a call <code>luaL_buffinitsize(L, &amp;b, sz)</code>.</li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5861
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5862 <li>Then copy the string into that space.</li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5863
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5864 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5865 Finish by calling <code>luaL_pushresultsize(&amp;b, sz)</code>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5866 where <code>sz</code> is the total size of the resulting string
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5867 copied into that space.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5868 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5869
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5870 </ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5871
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5872 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5873 During its normal operation,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5874 a string buffer uses a variable number of stack slots.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5875 So, while using a buffer, you cannot assume that you know where
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5876 the top of the stack is.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5877 You can use the stack between successive calls to buffer operations
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5878 as long as that use is balanced;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5879 that is,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5880 when you call a buffer operation,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5881 the stack is at the same level
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5882 it was immediately after the previous buffer operation.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5883 (The only exception to this rule is <a href="#luaL_addvalue"><code>luaL_addvalue</code></a>.)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5884 After calling <a href="#luaL_pushresult"><code>luaL_pushresult</code></a> the stack is back to its
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5885 level when the buffer was initialized,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5886 plus the final string on its top.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5887
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5888
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5889
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5890
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5891
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5892 <hr><h3><a name="luaL_buffinit"><code>luaL_buffinit</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5893 <span class="apii">[-0, +0, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5894 <pre>void luaL_buffinit (lua_State *L, luaL_Buffer *B);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5895
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5896 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5897 Initializes a buffer <code>B</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5898 This function does not allocate any space;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5899 the buffer must be declared as a variable
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5900 (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5901
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5902
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5903
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5904
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5905
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5906 <hr><h3><a name="luaL_buffinitsize"><code>luaL_buffinitsize</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5907 <span class="apii">[-?, +?, <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5908 <pre>char *luaL_buffinitsize (lua_State *L, luaL_Buffer *B, size_t sz);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5909
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5910 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5911 Equivalent to the sequence
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5912 <a href="#luaL_buffinit"><code>luaL_buffinit</code></a>, <a href="#luaL_prepbuffsize"><code>luaL_prepbuffsize</code></a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5913
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5914
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5915
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5916
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5917
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5918 <hr><h3><a name="luaL_callmeta"><code>luaL_callmeta</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5919 <span class="apii">[-0, +(0|1), <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5920 <pre>int luaL_callmeta (lua_State *L, int obj, const char *e);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5921
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5922 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5923 Calls a metamethod.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5924
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5925
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5926 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5927 If the object at index <code>obj</code> has a metatable and this
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5928 metatable has a field <code>e</code>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5929 this function calls this field passing the object as its only argument.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5930 In this case this function returns true and pushes onto the
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5931 stack the value returned by the call.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5932 If there is no metatable or no metamethod,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5933 this function returns false (without pushing any value on the stack).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5934
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5935
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5936
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5937
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5938
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5939 <hr><h3><a name="luaL_checkany"><code>luaL_checkany</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5940 <span class="apii">[-0, +0, <em>v</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5941 <pre>void luaL_checkany (lua_State *L, int arg);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5942
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5943 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5944 Checks whether the function has an argument
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5945 of any type (including <b>nil</b>) at position <code>arg</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5946
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5947
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5948
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5949
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5950
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5951 <hr><h3><a name="luaL_checkint"><code>luaL_checkint</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5952 <span class="apii">[-0, +0, <em>v</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5953 <pre>int luaL_checkint (lua_State *L, int arg);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5954
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5955 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5956 Checks whether the function argument <code>arg</code> is a number
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5957 and returns this number cast to an <code>int</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5958
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5959
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5960
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5961
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5962
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5963 <hr><h3><a name="luaL_checkinteger"><code>luaL_checkinteger</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5964 <span class="apii">[-0, +0, <em>v</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5965 <pre>lua_Integer luaL_checkinteger (lua_State *L, int arg);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5966
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5967 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5968 Checks whether the function argument <code>arg</code> is a number
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5969 and returns this number cast to a <a href="#lua_Integer"><code>lua_Integer</code></a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5970
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5971
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5972
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5973
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5974
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5975 <hr><h3><a name="luaL_checklong"><code>luaL_checklong</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5976 <span class="apii">[-0, +0, <em>v</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5977 <pre>long luaL_checklong (lua_State *L, int arg);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5978
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5979 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5980 Checks whether the function argument <code>arg</code> is a number
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5981 and returns this number cast to a <code>long</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5982
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5983
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5984
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5985
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5986
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5987 <hr><h3><a name="luaL_checklstring"><code>luaL_checklstring</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5988 <span class="apii">[-0, +0, <em>v</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5989 <pre>const char *luaL_checklstring (lua_State *L, int arg, size_t *l);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5990
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5991 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5992 Checks whether the function argument <code>arg</code> is a string
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5993 and returns this string;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5994 if <code>l</code> is not <code>NULL</code> fills <code>*l</code>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5995 with the string's length.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5996
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5997
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5998 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
5999 This function uses <a href="#lua_tolstring"><code>lua_tolstring</code></a> to get its result,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6000 so all conversions and caveats of that function apply here.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6001
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6002
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6003
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6004
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6005
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6006 <hr><h3><a name="luaL_checknumber"><code>luaL_checknumber</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6007 <span class="apii">[-0, +0, <em>v</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6008 <pre>lua_Number luaL_checknumber (lua_State *L, int arg);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6009
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6010 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6011 Checks whether the function argument <code>arg</code> is a number
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6012 and returns this number.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6013
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6014
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6015
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6016
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6017
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6018 <hr><h3><a name="luaL_checkoption"><code>luaL_checkoption</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6019 <span class="apii">[-0, +0, <em>v</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6020 <pre>int luaL_checkoption (lua_State *L,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6021 int arg,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6022 const char *def,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6023 const char *const lst[]);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6024
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6025 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6026 Checks whether the function argument <code>arg</code> is a string and
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6027 searches for this string in the array <code>lst</code>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6028 (which must be NULL-terminated).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6029 Returns the index in the array where the string was found.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6030 Raises an error if the argument is not a string or
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6031 if the string cannot be found.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6032
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6033
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6034 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6035 If <code>def</code> is not <code>NULL</code>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6036 the function uses <code>def</code> as a default value when
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6037 there is no argument <code>arg</code> or when this argument is <b>nil</b>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6038
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6039
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6040 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6041 This is a useful function for mapping strings to C&nbsp;enums.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6042 (The usual convention in Lua libraries is
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6043 to use strings instead of numbers to select options.)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6044
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6045
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6046
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6047
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6048
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6049 <hr><h3><a name="luaL_checkstack"><code>luaL_checkstack</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6050 <span class="apii">[-0, +0, <em>v</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6051 <pre>void luaL_checkstack (lua_State *L, int sz, const char *msg);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6052
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6053 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6054 Grows the stack size to <code>top + sz</code> elements,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6055 raising an error if the stack cannot grow to that size.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6056 <code>msg</code> is an additional text to go into the error message
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6057 (or <code>NULL</code> for no additional text).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6058
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6059
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6060
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6061
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6062
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6063 <hr><h3><a name="luaL_checkstring"><code>luaL_checkstring</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6064 <span class="apii">[-0, +0, <em>v</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6065 <pre>const char *luaL_checkstring (lua_State *L, int arg);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6066
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6067 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6068 Checks whether the function argument <code>arg</code> is a string
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6069 and returns this string.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6070
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6071
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6072 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6073 This function uses <a href="#lua_tolstring"><code>lua_tolstring</code></a> to get its result,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6074 so all conversions and caveats of that function apply here.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6075
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6076
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6077
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6078
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6079
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6080 <hr><h3><a name="luaL_checktype"><code>luaL_checktype</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6081 <span class="apii">[-0, +0, <em>v</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6082 <pre>void luaL_checktype (lua_State *L, int arg, int t);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6083
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6084 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6085 Checks whether the function argument <code>arg</code> has type <code>t</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6086 See <a href="#lua_type"><code>lua_type</code></a> for the encoding of types for <code>t</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6087
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6088
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6089
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6090
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6091
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6092 <hr><h3><a name="luaL_checkudata"><code>luaL_checkudata</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6093 <span class="apii">[-0, +0, <em>v</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6094 <pre>void *luaL_checkudata (lua_State *L, int arg, const char *tname);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6095
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6096 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6097 Checks whether the function argument <code>arg</code> is a userdata
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6098 of the type <code>tname</code> (see <a href="#luaL_newmetatable"><code>luaL_newmetatable</code></a>) and
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6099 returns the userdata address (see <a href="#lua_touserdata"><code>lua_touserdata</code></a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6100
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6101
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6102
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6103
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6104
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6105 <hr><h3><a name="luaL_checkunsigned"><code>luaL_checkunsigned</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6106 <span class="apii">[-0, +0, <em>v</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6107 <pre>lua_Unsigned luaL_checkunsigned (lua_State *L, int arg);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6108
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6109 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6110 Checks whether the function argument <code>arg</code> is a number
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6111 and returns this number cast to a <a href="#lua_Unsigned"><code>lua_Unsigned</code></a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6112
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6113
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6114
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6115
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6116
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6117 <hr><h3><a name="luaL_checkversion"><code>luaL_checkversion</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6118 <span class="apii">[-0, +0, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6119 <pre>void luaL_checkversion (lua_State *L);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6120
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6121 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6122 Checks whether the core running the call,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6123 the core that created the Lua state,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6124 and the code making the call are all using the same version of Lua.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6125 Also checks whether the core running the call
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6126 and the core that created the Lua state
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6127 are using the same address space.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6128
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6129
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6130
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6131
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6132
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6133 <hr><h3><a name="luaL_dofile"><code>luaL_dofile</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6134 <span class="apii">[-0, +?, <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6135 <pre>int luaL_dofile (lua_State *L, const char *filename);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6136
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6137 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6138 Loads and runs the given file.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6139 It is defined as the following macro:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6140
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6141 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6142 (luaL_loadfile(L, filename) || lua_pcall(L, 0, LUA_MULTRET, 0))
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6143 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6144 It returns false if there are no errors
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6145 or true in case of errors.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6146
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6147
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6148
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6149
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6150
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6151 <hr><h3><a name="luaL_dostring"><code>luaL_dostring</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6152 <span class="apii">[-0, +?, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6153 <pre>int luaL_dostring (lua_State *L, const char *str);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6154
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6155 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6156 Loads and runs the given string.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6157 It is defined as the following macro:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6158
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6159 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6160 (luaL_loadstring(L, str) || lua_pcall(L, 0, LUA_MULTRET, 0))
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6161 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6162 It returns false if there are no errors
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6163 or true in case of errors.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6164
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6165
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6166
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6167
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6168
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6169 <hr><h3><a name="luaL_error"><code>luaL_error</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6170 <span class="apii">[-0, +0, <em>v</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6171 <pre>int luaL_error (lua_State *L, const char *fmt, ...);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6172
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6173 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6174 Raises an error.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6175 The error message format is given by <code>fmt</code>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6176 plus any extra arguments,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6177 following the same rules of <a href="#lua_pushfstring"><code>lua_pushfstring</code></a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6178 It also adds at the beginning of the message the file name and
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6179 the line number where the error occurred,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6180 if this information is available.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6181
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6182
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6183 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6184 This function never returns,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6185 but it is an idiom to use it in C&nbsp;functions
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6186 as <code>return luaL_error(<em>args</em>)</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6187
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6188
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6189
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6190
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6191
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6192 <hr><h3><a name="luaL_execresult"><code>luaL_execresult</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6193 <span class="apii">[-0, +3, <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6194 <pre>int luaL_execresult (lua_State *L, int stat);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6195
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6196 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6197 This function produces the return values for
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6198 process-related functions in the standard library
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6199 (<a href="#pdf-os.execute"><code>os.execute</code></a> and <a href="#pdf-io.close"><code>io.close</code></a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6200
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6201
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6202
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6203
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6204
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6205 <hr><h3><a name="luaL_fileresult"><code>luaL_fileresult</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6206 <span class="apii">[-0, +(1|3), <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6207 <pre>int luaL_fileresult (lua_State *L, int stat, const char *fname);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6208
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6209 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6210 This function produces the return values for
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6211 file-related functions in the standard library
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6212 (<a href="#pdf-io.open"><code>io.open</code></a>, <a href="#pdf-os.rename"><code>os.rename</code></a>, <a href="#pdf-file:seek"><code>file:seek</code></a>, etc.).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6213
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6214
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6215
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6216
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6217
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6218 <hr><h3><a name="luaL_getmetafield"><code>luaL_getmetafield</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6219 <span class="apii">[-0, +(0|1), <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6220 <pre>int luaL_getmetafield (lua_State *L, int obj, const char *e);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6221
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6222 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6223 Pushes onto the stack the field <code>e</code> from the metatable
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6224 of the object at index <code>obj</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6225 If the object does not have a metatable,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6226 or if the metatable does not have this field,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6227 returns false and pushes nothing.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6228
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6229
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6230
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6231
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6232
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6233 <hr><h3><a name="luaL_getmetatable"><code>luaL_getmetatable</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6234 <span class="apii">[-0, +1, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6235 <pre>void luaL_getmetatable (lua_State *L, const char *tname);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6236
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6237 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6238 Pushes onto the stack the metatable associated with name <code>tname</code>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6239 in the registry (see <a href="#luaL_newmetatable"><code>luaL_newmetatable</code></a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6240
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6241
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6242
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6243
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6244
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6245 <hr><h3><a name="luaL_getsubtable"><code>luaL_getsubtable</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6246 <span class="apii">[-0, +1, <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6247 <pre>int luaL_getsubtable (lua_State *L, int idx, const char *fname);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6248
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6249 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6250 Ensures that the value <code>t[fname]</code>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6251 where <code>t</code> is the value at index <code>idx</code>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6252 is a table,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6253 and pushes that table onto the stack.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6254 Returns true if it finds a previous table there
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6255 and false if it creates a new table.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6256
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6257
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6258
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6259
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6260
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6261 <hr><h3><a name="luaL_gsub"><code>luaL_gsub</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6262 <span class="apii">[-0, +1, <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6263 <pre>const char *luaL_gsub (lua_State *L,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6264 const char *s,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6265 const char *p,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6266 const char *r);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6267
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6268 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6269 Creates a copy of string <code>s</code> by replacing
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6270 any occurrence of the string <code>p</code>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6271 with the string <code>r</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6272 Pushes the resulting string on the stack and returns it.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6273
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6274
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6275
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6276
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6277
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6278 <hr><h3><a name="luaL_len"><code>luaL_len</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6279 <span class="apii">[-0, +0, <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6280 <pre>int luaL_len (lua_State *L, int index);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6281
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6282 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6283 Returns the "length" of the value at the given index
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6284 as a number;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6285 it is equivalent to the '<code>#</code>' operator in Lua (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
6286 Raises an error if the result of the operation is not a number.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6287 (This case only can happen through metamethods.)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6288
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6289
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6290
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6291
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6292
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6293 <hr><h3><a name="luaL_loadbuffer"><code>luaL_loadbuffer</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6294 <span class="apii">[-0, +1, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6295 <pre>int luaL_loadbuffer (lua_State *L,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6296 const char *buff,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6297 size_t sz,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6298 const char *name);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6299
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6300 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6301 Equivalent to <a href="#luaL_loadbufferx"><code>luaL_loadbufferx</code></a> with <code>mode</code> equal to <code>NULL</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6302
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6303
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6304
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6305
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6306
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6307 <hr><h3><a name="luaL_loadbufferx"><code>luaL_loadbufferx</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6308 <span class="apii">[-0, +1, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6309 <pre>int luaL_loadbufferx (lua_State *L,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6310 const char *buff,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6311 size_t sz,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6312 const char *name,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6313 const char *mode);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6314
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6315 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6316 Loads a buffer as a Lua chunk.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6317 This function uses <a href="#lua_load"><code>lua_load</code></a> to load the chunk in the
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6318 buffer pointed to by <code>buff</code> with size <code>sz</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6319
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6320
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6321 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6322 This function returns the same results as <a href="#lua_load"><code>lua_load</code></a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6323 <code>name</code> is the chunk name,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6324 used for debug information and error messages.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6325 The string <code>mode</code> works as in function <a href="#lua_load"><code>lua_load</code></a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6326
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6327
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6328
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6329
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6330
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6331 <hr><h3><a name="luaL_loadfile"><code>luaL_loadfile</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6332 <span class="apii">[-0, +1, <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6333 <pre>int luaL_loadfile (lua_State *L, const char *filename);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6334
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6335 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6336 Equivalent to <a href="#luaL_loadfilex"><code>luaL_loadfilex</code></a> with <code>mode</code> equal to <code>NULL</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6337
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6338
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6339
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6340
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6341
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6342 <hr><h3><a name="luaL_loadfilex"><code>luaL_loadfilex</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6343 <span class="apii">[-0, +1, <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6344 <pre>int luaL_loadfilex (lua_State *L, const char *filename,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6345 const char *mode);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6346
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6347 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6348 Loads a file as a Lua chunk.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6349 This function uses <a href="#lua_load"><code>lua_load</code></a> to load the chunk in the file
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6350 named <code>filename</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6351 If <code>filename</code> is <code>NULL</code>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6352 then it loads from the standard input.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6353 The first line in the file is ignored if it starts with a <code>#</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6354
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6355
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6356 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6357 The string <code>mode</code> works as in function <a href="#lua_load"><code>lua_load</code></a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6358
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6359
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6360 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6361 This function returns the same results as <a href="#lua_load"><code>lua_load</code></a>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6362 but it has an extra error code <a name="pdf-LUA_ERRFILE"><code>LUA_ERRFILE</code></a>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6363 if it cannot open/read the file or the file has a wrong mode.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6364
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6365
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6366 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6367 As <a href="#lua_load"><code>lua_load</code></a>, this function only loads the chunk;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6368 it does not run it.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6369
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6370
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6371
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6372
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6373
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6374 <hr><h3><a name="luaL_loadstring"><code>luaL_loadstring</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6375 <span class="apii">[-0, +1, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6376 <pre>int luaL_loadstring (lua_State *L, const char *s);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6377
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6378 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6379 Loads a string as a Lua chunk.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6380 This function uses <a href="#lua_load"><code>lua_load</code></a> to load the chunk in
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6381 the zero-terminated string <code>s</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6382
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6383
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6384 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6385 This function returns the same results as <a href="#lua_load"><code>lua_load</code></a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6386
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6387
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6388 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6389 Also as <a href="#lua_load"><code>lua_load</code></a>, this function only loads the chunk;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6390 it does not run it.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6391
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6392
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6393
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6394
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6395
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6396 <hr><h3><a name="luaL_newlib"><code>luaL_newlib</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6397 <span class="apii">[-0, +1, <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6398 <pre>void luaL_newlib (lua_State *L, const luaL_Reg *l);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6399
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6400 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6401 Creates a new table and registers there
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6402 the functions in list <code>l</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6403 It is implemented as the following macro:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6404
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6405 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6406 (luaL_newlibtable(L,l), luaL_setfuncs(L,l,0))
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6407 </pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6408
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6409
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6410
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6411
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6412 <hr><h3><a name="luaL_newlibtable"><code>luaL_newlibtable</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6413 <span class="apii">[-0, +1, <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6414 <pre>void luaL_newlibtable (lua_State *L, const luaL_Reg l[]);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6415
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6416 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6417 Creates a new table with a size optimized
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6418 to store all entries in the array <code>l</code>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6419 (but does not actually store them).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6420 It is intended to be used in conjunction with <a href="#luaL_setfuncs"><code>luaL_setfuncs</code></a>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6421 (see <a href="#luaL_newlib"><code>luaL_newlib</code></a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6422
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6423
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6424 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6425 It is implemented as a macro.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6426 The array <code>l</code> must be the actual array,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6427 not a pointer to it.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6428
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6429
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6430
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6431
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6432
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6433 <hr><h3><a name="luaL_newmetatable"><code>luaL_newmetatable</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6434 <span class="apii">[-0, +1, <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6435 <pre>int luaL_newmetatable (lua_State *L, const char *tname);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6436
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6437 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6438 If the registry already has the key <code>tname</code>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6439 returns 0.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6440 Otherwise,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6441 creates a new table to be used as a metatable for userdata,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6442 adds it to the registry with key <code>tname</code>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6443 and returns 1.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6444
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6445
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6446 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6447 In both cases pushes onto the stack the final value associated
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6448 with <code>tname</code> in the registry.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6449
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6450
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6451
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6452
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6453
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6454 <hr><h3><a name="luaL_newstate"><code>luaL_newstate</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6455 <span class="apii">[-0, +0, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6456 <pre>lua_State *luaL_newstate (void);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6457
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6458 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6459 Creates a new Lua state.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6460 It calls <a href="#lua_newstate"><code>lua_newstate</code></a> with an
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6461 allocator based on the standard&nbsp;C <code>realloc</code> function
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6462 and then sets a panic function (see <a href="#4.6">&sect;4.6</a>) that prints
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6463 an error message to the standard error output in case of fatal
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6464 errors.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6465
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6466
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6467 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6468 Returns the new state,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6469 or <code>NULL</code> if there is a memory allocation error.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6470
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6471
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6472
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6473
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6474
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6475 <hr><h3><a name="luaL_openlibs"><code>luaL_openlibs</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6476 <span class="apii">[-0, +0, <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6477 <pre>void luaL_openlibs (lua_State *L);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6478
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6479 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6480 Opens all standard Lua libraries into the given state.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6481
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6482
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6483
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6484
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6485
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6486 <hr><h3><a name="luaL_optint"><code>luaL_optint</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6487 <span class="apii">[-0, +0, <em>v</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6488 <pre>int luaL_optint (lua_State *L, int arg, int d);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6489
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6490 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6491 If the function argument <code>arg</code> is a number,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6492 returns this number cast to an <code>int</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6493 If this argument is absent or is <b>nil</b>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6494 returns <code>d</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6495 Otherwise, raises an error.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6496
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6497
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6498
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6499
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6500
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6501 <hr><h3><a name="luaL_optinteger"><code>luaL_optinteger</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6502 <span class="apii">[-0, +0, <em>v</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6503 <pre>lua_Integer luaL_optinteger (lua_State *L,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6504 int arg,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6505 lua_Integer d);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6506
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6507 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6508 If the function argument <code>arg</code> is a number,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6509 returns this number cast to a <a href="#lua_Integer"><code>lua_Integer</code></a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6510 If this argument is absent or is <b>nil</b>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6511 returns <code>d</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6512 Otherwise, raises an error.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6513
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6514
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6515
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6516
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6517
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6518 <hr><h3><a name="luaL_optlong"><code>luaL_optlong</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6519 <span class="apii">[-0, +0, <em>v</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6520 <pre>long luaL_optlong (lua_State *L, int arg, long d);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6521
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6522 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6523 If the function argument <code>arg</code> is a number,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6524 returns this number cast to a <code>long</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6525 If this argument is absent or is <b>nil</b>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6526 returns <code>d</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6527 Otherwise, raises an error.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6528
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6529
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6530
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6531
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6532
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6533 <hr><h3><a name="luaL_optlstring"><code>luaL_optlstring</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6534 <span class="apii">[-0, +0, <em>v</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6535 <pre>const char *luaL_optlstring (lua_State *L,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6536 int arg,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6537 const char *d,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6538 size_t *l);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6539
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6540 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6541 If the function argument <code>arg</code> is a string,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6542 returns this string.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6543 If this argument is absent or is <b>nil</b>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6544 returns <code>d</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6545 Otherwise, raises an error.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6546
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6547
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6548 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6549 If <code>l</code> is not <code>NULL</code>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6550 fills the position <code>*l</code> with the result's length.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6551
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6552
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6553
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6554
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6555
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6556 <hr><h3><a name="luaL_optnumber"><code>luaL_optnumber</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6557 <span class="apii">[-0, +0, <em>v</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6558 <pre>lua_Number luaL_optnumber (lua_State *L, int arg, lua_Number d);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6559
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6560 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6561 If the function argument <code>arg</code> is a number,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6562 returns this number.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6563 If this argument is absent or is <b>nil</b>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6564 returns <code>d</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6565 Otherwise, raises an error.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6566
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6567
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6568
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6569
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6570
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6571 <hr><h3><a name="luaL_optstring"><code>luaL_optstring</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6572 <span class="apii">[-0, +0, <em>v</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6573 <pre>const char *luaL_optstring (lua_State *L,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6574 int arg,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6575 const char *d);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6576
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6577 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6578 If the function argument <code>arg</code> is a string,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6579 returns this string.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6580 If this argument is absent or is <b>nil</b>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6581 returns <code>d</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6582 Otherwise, raises an error.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6583
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6584
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6585
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6586
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6587
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6588 <hr><h3><a name="luaL_optunsigned"><code>luaL_optunsigned</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6589 <span class="apii">[-0, +0, <em>v</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6590 <pre>lua_Unsigned luaL_optunsigned (lua_State *L,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6591 int arg,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6592 lua_Unsigned u);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6593
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6594 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6595 If the function argument <code>arg</code> is a number,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6596 returns this number cast to a <a href="#lua_Unsigned"><code>lua_Unsigned</code></a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6597 If this argument is absent or is <b>nil</b>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6598 returns <code>u</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6599 Otherwise, raises an error.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6600
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6601
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6602
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6603
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6604
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6605 <hr><h3><a name="luaL_prepbuffer"><code>luaL_prepbuffer</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6606 <span class="apii">[-?, +?, <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6607 <pre>char *luaL_prepbuffer (luaL_Buffer *B);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6608
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6609 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6610 Equivalent to <a href="#luaL_prepbuffsize"><code>luaL_prepbuffsize</code></a>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6611 with the predefined size <a name="pdf-LUAL_BUFFERSIZE"><code>LUAL_BUFFERSIZE</code></a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6612
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6613
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6614
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6615
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6616
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6617 <hr><h3><a name="luaL_prepbuffsize"><code>luaL_prepbuffsize</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6618 <span class="apii">[-?, +?, <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6619 <pre>char *luaL_prepbuffsize (luaL_Buffer *B, size_t sz);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6620
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6621 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6622 Returns an address to a space of size <code>sz</code>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6623 where you can copy a string to be added to buffer <code>B</code>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6624 (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6625 After copying the string into this space you must call
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6626 <a href="#luaL_addsize"><code>luaL_addsize</code></a> with the size of the string to actually add
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6627 it to the buffer.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6628
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6629
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6630
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6631
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6632
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6633 <hr><h3><a name="luaL_pushresult"><code>luaL_pushresult</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6634 <span class="apii">[-?, +1, <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6635 <pre>void luaL_pushresult (luaL_Buffer *B);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6636
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6637 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6638 Finishes the use of buffer <code>B</code> leaving the final string on
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6639 the top of the stack.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6640
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6641
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6642
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6643
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6644
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6645 <hr><h3><a name="luaL_pushresultsize"><code>luaL_pushresultsize</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6646 <span class="apii">[-?, +1, <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6647 <pre>void luaL_pushresultsize (luaL_Buffer *B, size_t sz);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6648
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6649 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6650 Equivalent to the sequence <a href="#luaL_addsize"><code>luaL_addsize</code></a>, <a href="#luaL_pushresult"><code>luaL_pushresult</code></a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6651
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6652
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6653
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6654
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6655
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6656 <hr><h3><a name="luaL_ref"><code>luaL_ref</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6657 <span class="apii">[-1, +0, <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6658 <pre>int luaL_ref (lua_State *L, int t);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6659
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6660 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6661 Creates and returns a <em>reference</em>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6662 in the table at index <code>t</code>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6663 for the object at the top of the stack (and pops the object).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6664
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6665
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6666 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6667 A reference is a unique integer key.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6668 As long as you do not manually add integer keys into table <code>t</code>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6669 <a href="#luaL_ref"><code>luaL_ref</code></a> ensures the uniqueness of the key it returns.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6670 You can retrieve an object referred by reference <code>r</code>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6671 by calling <code>lua_rawgeti(L, t, r)</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6672 Function <a href="#luaL_unref"><code>luaL_unref</code></a> frees a reference and its associated object.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6673
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6674
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6675 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6676 If the object at the top of the stack is <b>nil</b>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6677 <a href="#luaL_ref"><code>luaL_ref</code></a> returns the constant <a name="pdf-LUA_REFNIL"><code>LUA_REFNIL</code></a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6678 The constant <a name="pdf-LUA_NOREF"><code>LUA_NOREF</code></a> is guaranteed to be different
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6679 from any reference returned by <a href="#luaL_ref"><code>luaL_ref</code></a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6680
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6681
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6682
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6683
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6684
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6685 <hr><h3><a name="luaL_Reg"><code>luaL_Reg</code></a></h3>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6686 <pre>typedef struct luaL_Reg {
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6687 const char *name;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6688 lua_CFunction func;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6689 } luaL_Reg;</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6690
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6691 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6692 Type for arrays of functions to be registered by
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6693 <a href="#luaL_setfuncs"><code>luaL_setfuncs</code></a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6694 <code>name</code> is the function name and <code>func</code> is a pointer to
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6695 the function.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6696 Any array of <a href="#luaL_Reg"><code>luaL_Reg</code></a> must end with an sentinel entry
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6697 in which both <code>name</code> and <code>func</code> are <code>NULL</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6698
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6699
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6700
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6701
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6702
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6703 <hr><h3><a name="luaL_requiref"><code>luaL_requiref</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6704 <span class="apii">[-0, +1, <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6705 <pre>void luaL_requiref (lua_State *L, const char *modname,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6706 lua_CFunction openf, int glb);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6707
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6708 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6709 Calls function <code>openf</code> with string <code>modname</code> as an argument
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6710 and sets the call result in <code>package.loaded[modname]</code>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6711 as if that function has been called through <a href="#pdf-require"><code>require</code></a>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6712
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6713
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6714 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6715 If <code>glb</code> is true,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6716 also stores the result into global <code>modname</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6717
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6718
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6719 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6720 Leaves a copy of that result on the stack.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6721
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6722
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6723
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6724
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6725
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6726 <hr><h3><a name="luaL_setfuncs"><code>luaL_setfuncs</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6727 <span class="apii">[-nup, +0, <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6728 <pre>void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6729
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6730 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6731 Registers all functions in the array <code>l</code>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6732 (see <a href="#luaL_Reg"><code>luaL_Reg</code></a>) into the table on the top of the stack
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6733 (below optional upvalues, see next).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6734
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6735
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6736 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6737 When <code>nup</code> is not zero,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6738 all functions are created sharing <code>nup</code> upvalues,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6739 which must be previously pushed on the stack
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6740 on top of the library table.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6741 These values are popped from the stack after the registration.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6742
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6743
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6744
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6745
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6746
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6747 <hr><h3><a name="luaL_setmetatable"><code>luaL_setmetatable</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6748 <span class="apii">[-0, +0, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6749 <pre>void luaL_setmetatable (lua_State *L, const char *tname);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6750
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6751 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6752 Sets the metatable of the object at the top of the stack
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6753 as the metatable associated with name <code>tname</code>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6754 in the registry (see <a href="#luaL_newmetatable"><code>luaL_newmetatable</code></a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6755
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6756
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6757
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6758
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6759
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6760 <hr><h3><a name="luaL_testudata"><code>luaL_testudata</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6761 <span class="apii">[-0, +0, <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6762 <pre>void *luaL_testudata (lua_State *L, int arg, const char *tname);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6763
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6764 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6765 This function works like <a href="#luaL_checkudata"><code>luaL_checkudata</code></a>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6766 except that, when the test fails,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6767 it returns <code>NULL</code> instead of throwing an error.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6768
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6769
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6770
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6771
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6772
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6773 <hr><h3><a name="luaL_tolstring"><code>luaL_tolstring</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6774 <span class="apii">[-0, +1, <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6775 <pre>const char *luaL_tolstring (lua_State *L, int idx, size_t *len);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6776
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6777 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6778 Converts any Lua value at the given index to a C&nbsp;string
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6779 in a reasonable format.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6780 The resulting string is pushed onto the stack and also
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6781 returned by the function.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6782 If <code>len</code> is not <code>NULL</code>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6783 the function also sets <code>*len</code> with the string length.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6784
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6785
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6786 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6787 If the value has a metatable with a <code>"__tostring"</code> field,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6788 then <code>luaL_tolstring</code> calls the corresponding metamethod
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6789 with the value as argument,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6790 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
6791
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6792
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6793
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6794
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6795
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6796 <hr><h3><a name="luaL_traceback"><code>luaL_traceback</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6797 <span class="apii">[-0, +1, <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6798 <pre>void luaL_traceback (lua_State *L, lua_State *L1, const char *msg,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6799 int level);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6800
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6801 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6802 Creates and pushes a traceback of the stack <code>L1</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6803 If <code>msg</code> is not <code>NULL</code> it is appended
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6804 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
6805 The <code>level</code> parameter tells at which level
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6806 to start the traceback.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6807
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6808
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6809
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6810
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6811
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6812 <hr><h3><a name="luaL_typename"><code>luaL_typename</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6813 <span class="apii">[-0, +0, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6814 <pre>const char *luaL_typename (lua_State *L, int index);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6815
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6816 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6817 Returns the name of the type of the value at the given index.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6818
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6819
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6820
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6821
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6822
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6823 <hr><h3><a name="luaL_unref"><code>luaL_unref</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6824 <span class="apii">[-0, +0, &ndash;]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6825 <pre>void luaL_unref (lua_State *L, int t, int ref);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6826
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6827 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6828 Releases reference <code>ref</code> from the table at index <code>t</code>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6829 (see <a href="#luaL_ref"><code>luaL_ref</code></a>).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6830 The entry is removed from the table,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6831 so that the referred object can be collected.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6832 The reference <code>ref</code> is also freed to be used again.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6833
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6834
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6835 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6836 If <code>ref</code> is <a href="#pdf-LUA_NOREF"><code>LUA_NOREF</code></a> or <a href="#pdf-LUA_REFNIL"><code>LUA_REFNIL</code></a>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6837 <a href="#luaL_unref"><code>luaL_unref</code></a> does nothing.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6838
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6839
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6840
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6841
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6842
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6843 <hr><h3><a name="luaL_where"><code>luaL_where</code></a></h3><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6844 <span class="apii">[-0, +1, <em>e</em>]</span>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6845 <pre>void luaL_where (lua_State *L, int lvl);</pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6846
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6847 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6848 Pushes onto the stack a string identifying the current position
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6849 of the control at level <code>lvl</code> in the call stack.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6850 Typically this string has the following format:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6851
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6852 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6853 <em>chunkname</em>:<em>currentline</em>:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6854 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6855 Level&nbsp;0 is the running function,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6856 level&nbsp;1 is the function that called the running function,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6857 etc.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6858
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6859
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6860 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6861 This function is used to build a prefix for error messages.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6862
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6863
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6864
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6865
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6866
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6867
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6868
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6869 <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
6870
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6871 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6872 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
6873 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
6874 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
6875 (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
6876 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
6877 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
6878 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
6879 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
6880
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6881
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6882 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6883 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
6884 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
6885 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
6886
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6887 <ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6888
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6889 <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
6890
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6891 <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
6892
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6893 <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
6894
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6895 <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
6896
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6897 <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
6898
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6899 <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
6900
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6901 <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
6902
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6903 <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
6904
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6905 <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
6906
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6907 <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
6908
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6909 </ul><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6910 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
6911 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
6912 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
6913
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6914
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6915 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6916 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
6917 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
6918 which opens all standard libraries.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6919 Alternatively,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6920 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
6921 <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
6922 <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
6923 <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
6924 <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
6925 <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
6926 <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
6927 <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
6928 <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
6929 <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
6930 <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
6931 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
6932 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
6933
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6934
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6935
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6936 <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
6937
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6938 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6939 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
6940 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
6941 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
6942 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
6943
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6944
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6945 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6946 <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
6947 Issues an error when
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6948 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
6949 otherwise, returns all its arguments.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6950 <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
6951 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
6952
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6953
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6954
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6955
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6956 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6957 <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
6958
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6959
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6960 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6961 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
6962 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
6963
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6964 <ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6965
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6966 <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
6967 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
6968 This is the default option.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6969 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6970
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6971 <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
6972 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
6973 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
6974 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
6975 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6976
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6977 <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
6978 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
6979 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6980
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6981 <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
6982 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
6983 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
6984 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
6985 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
6986
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6987 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6988 k, b = collectgarbage("count")
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6989 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
6990 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6991 (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
6992 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
6993 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6994
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6995 <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
6996 performs a garbage-collection step.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6997 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
6998 (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
6999 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
7000 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
7001 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
7002 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7003
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7004 <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
7005 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
7006 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
7007 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
7008 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7009
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7010 <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
7011 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
7012 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
7013 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
7014 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7015
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7016 <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
7017 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
7018 (i.e., not stopped).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7019 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7020
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7021 <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
7022 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
7023 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
7024 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7025
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7026 <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
7027 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
7028 This is the default mode.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7029 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7030
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7031 </ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7032
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7033
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7034
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7035 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7036 <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
7037 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
7038 When called without arguments,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7039 <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
7040 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
7041 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
7042 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
7043
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7044
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7045
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7046
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7047 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7048 <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
7049 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
7050 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
7051 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
7052
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7053
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7054 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7055 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
7056 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
7057 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
7058 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
7059 <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
7060 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
7061 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
7062 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
7063 to the message.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7064
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7065
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7066
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7067
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7068 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7069 <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
7070 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
7071 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
7072 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
7073 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
7074 nor vice-versa.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7075
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7076
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7077
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7078
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7079 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7080 <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
7081
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7082
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7083 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7084 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
7085 Otherwise,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7086 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
7087 returns the associated value.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7088 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
7089
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7090
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7091
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7092
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7093 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7094 <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
7095
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7096
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7097 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7098 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
7099 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
7100 results from the call.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7101
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7102
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7103 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7104 Otherwise,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7105 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
7106 so that the construction
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7107
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7108 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7109 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
7110 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7111 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
7112 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
7113
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7114
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7115
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7116
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7117 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7118 <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
7119
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7120
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7121 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7122 Loads a chunk.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7123
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7124
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7125 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7126 If <code>ld</code> is a 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
7127 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
7128 <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
7129 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
7130 with previous results.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7131 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
7132
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7133
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7134 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7135 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
7136 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
7137 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
7138
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7139
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7140 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7141 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
7142 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
7143 if that parameter is given,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7144 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
7145 (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
7146 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
7147 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
7148 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
7149 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
7150
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7151
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7152 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7153 <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
7154 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
7155 When absent,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7156 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
7157 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
7158
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7159
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7160 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7161 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
7162 (that is, a precompiled chunk).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7163 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
7164 "<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
7165 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
7166 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
7167
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7168
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7169
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7170
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7171 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7172 <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
7173
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7174
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7175 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7176 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
7177 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
7178 or from the standard input,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7179 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
7180
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7181
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7182
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7183
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7184 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7185 <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
7186
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7187
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7188 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7189 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
7190 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
7191 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
7192 <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
7193 and its associated value.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7194 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
7195 <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
7196 and its associated value.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7197 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
7198 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
7199 <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
7200 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
7201 In particular,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7202 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
7203
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7204
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7205 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7206 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
7207 <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
7208 (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
7209 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
7210
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7211
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7212 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7213 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
7214 during the traversal,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7215 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
7216 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
7217 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
7218
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7219
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7220
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7221
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7222 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7223 <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
7224
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7225
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7226 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7227 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
7228 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
7229 results from the call.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7230
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7231
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7232 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7233 Otherwise,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7234 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
7235 so that the construction
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7236
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7237 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7238 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
7239 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7240 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
7241
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7242
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7243 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7244 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
7245 the table during its traversal.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7246
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7247
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7248
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7249
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7250 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7251 <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
7252
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7253
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7254 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7255 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
7256 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
7257 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
7258 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
7259 and returns a status code.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7260 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
7261 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
7262 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
7263 after this first result.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7264 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
7265
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7266
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7267
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7268
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7269 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7270 <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
7271 Receives any number of arguments
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7272 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
7273 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
7274 <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
7275 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
7276 for instance for debugging.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7277 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
7278 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
7279
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7280
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7281
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7282
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7283 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7284 <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
7285 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
7286 without invoking any metamethod.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7287 Returns a boolean.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7288
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7289
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7290
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7291
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7292 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7293 <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
7294 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
7295 without invoking any metamethod.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7296 <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
7297 <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
7298
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7299
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7300
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7301
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7302 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7303 <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
7304 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
7305 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
7306 without invoking any metamethod.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7307 Returns an integer number.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7308
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7309
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7310
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7311
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7312 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7313 <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
7314 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
7315 without invoking any metamethod.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7316 <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
7317 <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
7318 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
7319
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7320
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7321 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7322 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
7323
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7324
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7325
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7326
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7327 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7328 <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
7329
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7330
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7331 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7332 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
7333 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
7334 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
7335 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
7336 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
7337
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7338
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7339
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7340
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7341 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7342 <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
7343
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7344
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7345 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7346 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
7347 (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
7348 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
7349 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
7350 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
7351 raises an error.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7352
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7353
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7354 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7355 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
7356
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7357
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7358
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7359
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7360 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7361 <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
7362
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7363
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7364 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7365 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
7366 <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
7367 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
7368 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
7369 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
7370 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
7371
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7372
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7373 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7374 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
7375 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
7376 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
7377 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
7378 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
7379 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
7380 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
7381 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
7382 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
7383
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7384
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7385
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7386
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7387 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7388 <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
7389 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
7390 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
7391 (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
7392 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
7393
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7394
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7395 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7396 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
7397 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
7398 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
7399 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
7400
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7401
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7402
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7403
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7404 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7405 <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
7406 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
7407 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
7408 "<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
7409 "<code>number</code>",
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7410 "<code>string</code>",
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7411 "<code>boolean</code>",
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7412 "<code>table</code>",
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7413 "<code>function</code>",
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7414 "<code>thread</code>",
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7415 and "<code>userdata</code>".
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7416
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7417
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7418
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7419
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7420 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7421 <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
7422 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
7423 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
7424 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
7425
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7426
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7427
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7428
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7429 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7430 <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
7431
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7432
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7433 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7434 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
7435 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
7436
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7437
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7438
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7439
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7440
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7441
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7442
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7443 <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
7444
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7445 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7446 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
7447 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
7448 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
7449
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7450
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7451 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7452 <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
7453
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7454
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7455 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7456 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
7457 <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
7458 Returns this new coroutine,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7459 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
7460
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7461
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7462
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7463
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7464 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7465 <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
7466
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7467
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7468 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7469 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
7470 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
7471 it starts running its body.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7472 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
7473 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
7474 If the coroutine has yielded,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7475 <code>resume</code> restarts it;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7476 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
7477 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
7478
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7479
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7480 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7481 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
7482 <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
7483 (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
7484 (if the coroutine terminates).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7485 If there is any error,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7486 <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
7487
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7488
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7489
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7490
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7491 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7492 <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
7493
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7494
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7495 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7496 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
7497 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
7498
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7499
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7500
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7501
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7502 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7503 <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
7504
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7505
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7506 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7507 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
7508 <code>"running"</code>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7509 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
7510 <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
7511 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
7512 <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
7513 (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
7514 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
7515 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
7516
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7517
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7518
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7519
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7520 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7521 <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
7522
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7523
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7524 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7525 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
7526 <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
7527 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
7528 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
7529 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
7530 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
7531 except the first boolean.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7532 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
7533
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7534
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7535
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7536
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7537 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7538 <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
7539
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7540
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7541 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7542 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
7543 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
7544
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7545
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7546
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7547
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7548
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7549
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7550
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7551 <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
7552
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7553 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7554 The package library provides basic
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7555 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
7556 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
7557 <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
7558 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
7559
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7560
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7561 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7562 <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
7563
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7564
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7565 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7566 Loads the given module.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7567 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
7568 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
7569 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
7570 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
7571 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
7572
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7573
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7574 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7575 To find a loader,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7576 <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
7577 By changing this sequence,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7578 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
7579 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
7580 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
7581
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7582
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7583 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7584 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
7585 If it has a value,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7586 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
7587 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
7588 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
7589 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
7590 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
7591 If that also fails,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7592 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
7593
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7594
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7595 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7596 Once a loader is found,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7597 <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
7598 <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
7599 (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
7600 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
7601 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
7602 <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
7603 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
7604 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
7605 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
7606 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
7607 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
7608
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7609
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7610 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7611 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
7612 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
7613 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
7614
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7615
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7616
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7617
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7618 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7619 <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
7620
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7621
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7622 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7623 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
7624 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
7625
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7626 <ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7627
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7628 <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
7629 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
7630
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7631 <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
7632 Default is '<code>;</code>'.</li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7633
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7634 <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
7635 substitution points in a template.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7636 Default is '<code>?</code>'.</li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7637
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7638 <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
7639 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
7640 Default is '<code>!</code>'.</li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7641
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7642 <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
7643 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
7644 Default is '<code>-</code>'.</li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7645
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7646 </ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7647
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7648
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7649
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7650 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7651 <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
7652
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7653
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7654 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7655 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
7656
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7657
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7658 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7659 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
7660 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
7661 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
7662 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
7663 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
7664
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7665
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7666
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7667
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7668 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7669 <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
7670
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7671
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7672 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7673 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
7674 modules are already loaded.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7675 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
7676 <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
7677 <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
7678
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7679
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7680 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7681 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
7682 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
7683 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
7684
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7685
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7686
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7687
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7688 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7689 <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
7690
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7691
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7692 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7693 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
7694
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7695
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7696 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7697 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
7698 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
7699 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
7700 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
7701 Otherwise,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7702 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
7703 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
7704 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
7705 (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
7706
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7707
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7708 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7709 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
7710 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
7711 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
7712 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
7713 does not automatically adds extensions.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7714 <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
7715 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
7716 <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
7717 (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
7718
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7719
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7720 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7721 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
7722 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
7723 (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
7724 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
7725
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7726
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7727
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7728
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7729 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7730 <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
7731
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7732
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7733 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7734 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
7735
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7736
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7737 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7738 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
7739 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
7740 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
7741 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
7742 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
7743 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
7744 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
7745
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7746
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7747
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7748
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7749 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7750 <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
7751
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7752
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7753 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7754 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
7755 (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
7756
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7757
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7758 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7759 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
7760 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
7761 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
7762
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7763
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7764
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7765
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7766 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7767 <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
7768
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7769
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7770 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7771 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
7772
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7773
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7774 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7775 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
7776 When looking for a module,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7777 <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
7778 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
7779 sole parameter.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7780 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
7781 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
7782 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
7783 (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
7784
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7785
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7786 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7787 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
7788
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7789
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7790 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7791 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
7792 <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
7793
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7794
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7795 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7796 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
7797 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
7798 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
7799
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7800
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7801 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7802 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
7803 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
7804 Again,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7805 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
7806 For instance,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7807 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
7808
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7809 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7810 "./?.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
7811 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7812 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
7813 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
7814 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
7815 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
7816 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
7817 application with the library.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7818 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
7819 be used as the loader.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7820 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
7821 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
7822 is replaced by an underscore.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7823 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
7824 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
7825 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
7826 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
7827
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7828
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7829 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7830 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
7831 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
7832 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
7833 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
7834 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
7835 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
7836 the submodule;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7837 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
7838 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
7839 into one single library,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7840 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
7841
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7842
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7843 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7844 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
7845 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
7846 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
7847 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
7848
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7849
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7850
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7851
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7852 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7853 <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
7854
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7855
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7856 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7857 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
7858
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7859
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7860 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7861 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
7862 <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
7863 For each template,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7864 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
7865 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
7866 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
7867 (a dot, by default)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7868 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
7869 (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
7870 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
7871
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7872
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7873 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7874 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
7875
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7876 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7877 "./?.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
7878 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7879 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
7880 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
7881 <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
7882 <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
7883
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7884
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7885 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7886 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
7887 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
7888 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
7889 (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
7890
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7891
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7892
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7893
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7894
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7895
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7896
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7897 <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
7898
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7899 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7900 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
7901 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
7902 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
7903 (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
7904 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
7905 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
7906 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
7907
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7908
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7909 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7910 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
7911 <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
7912 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
7913 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
7914 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
7915 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
7916 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
7917
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7918
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7919 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7920 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
7921
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7922
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7923 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7924 <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
7925 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
7926 <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
7927 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
7928 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
7929 These indices are corrected
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7930 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
7931
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7932
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7933 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7934 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
7935
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7936
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7937
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7938
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7939 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7940 <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
7941 Receives zero or more integers.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7942 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
7943 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
7944 to its corresponding argument.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7945
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7946
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7947 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7948 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
7949
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7950
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7951
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7952
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7953 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7954 <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
7955
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7956
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7957 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7958 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
7959 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
7960 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
7961
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7962
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7963
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7964
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7965 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7966 <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
7967
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7968
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7969 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7970 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
7971 <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
7972 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
7973 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
7974 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
7975 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
7976 where to start the search;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7977 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
7978 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
7979 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
7980 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
7981 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
7982 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
7983
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7984
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7985 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7986 If the pattern has captures,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7987 then in a successful match
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7988 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
7989 after the two indices.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7990
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7991
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7992
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7993
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7994 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7995 <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
7996
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7997
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7998 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7999 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
8000 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
8001 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
8002 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
8003 <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
8004 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
8005 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
8006 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
8007 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
8008 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
8009 For instance, the call
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8010
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8011 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8012 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
8013 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8014 may produce the string:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8015
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8016 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8017 "a string with \"quotes\" and \
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8018 new line"
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8019 </pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8020
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8021 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8022 Options
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8023 <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
8024 <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
8025 <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
8026 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
8027 <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
8028 also expect a number,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8029 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
8030 the underlying C&nbsp;implementation.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8031 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
8032 the number cannot be negative.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8033 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
8034 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
8035 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
8036 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
8037
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8038
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8039
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8040
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8041 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8042 <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
8043 Returns an iterator function that,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8044 each time it is called,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8045 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
8046 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
8047 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
8048
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8049
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8050 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8051 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
8052 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
8053 printing one per line:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8054
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8055 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8056 s = "hello world from Lua"
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8057 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
8058 print(w)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8059 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8060 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8061 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
8062 given string into a table:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8063
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8064 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8065 t = {}
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8066 s = "from=world, to=Lua"
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8067 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
8068 t[k] = v
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8069 end
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8070 </pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8071
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8072 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8073 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
8074 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
8075
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8076
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8077
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8078
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8079 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8080 <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
8081 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
8082 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
8083 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
8084 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
8085 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
8086 <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
8087 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
8088 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
8089
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8090
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8091 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8092 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
8093 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
8094 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
8095 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
8096 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
8097 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
8098 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
8099
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8100
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8101 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8102 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
8103 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
8104
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8105
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8106 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8107 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
8108 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
8109 in order.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8110
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8111
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8112 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8113 In any case,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8114 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
8115 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
8116
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8117
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8118 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8119 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
8120 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
8121 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
8122 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
8123 then there is no replacement
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8124 (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
8125
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8126
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8127 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8128 Here are some examples:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8129
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8130 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8131 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
8132 --&gt; x="hello hello world world"
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8133
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8134 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
8135 --&gt; x="hello hello world"
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8136
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8137 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
8138 --&gt; x="world hello Lua from"
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8139
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8140 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
8141 --&gt; x="home = /home/roberto, user = roberto"
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8142
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8143 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
8144 return load(s)()
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8145 end)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8146 --&gt; x="4+5 = 9"
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8147
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8148 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
8149 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
8150 --&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
8151 </pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8152
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8153
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8154
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8155 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8156 <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
8157 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
8158 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
8159 Embedded zeros are counted,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8160 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
8161
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8162
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8163
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8164
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8165 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8166 <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
8167 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
8168 uppercase letters changed to lowercase.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8169 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
8170 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
8171
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8172
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8173
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8174
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8175 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8176 <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
8177 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
8178 <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
8179 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
8180 the captures from the pattern;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8181 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
8182 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
8183 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
8184 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
8185 where to start the search;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8186 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
8187
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8188
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8189
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8190
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8191 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8192 <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
8193 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
8194 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
8195 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
8196 (that is, no separator).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8197
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8198
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8199
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8200
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8201 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8202 <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
8203 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
8204
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8205
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8206
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8207
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8208 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8209 <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
8210 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
8211 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
8212 <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
8213 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
8214 (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
8215 In particular,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8216 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
8217 with length <code>j</code>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8218 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
8219 with length <code>i</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8220
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8221
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8222 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8223 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
8224 <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
8225 it is corrected to 1.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8226 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
8227 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
8228 If, after these corrections,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8229 <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
8230 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
8231
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8232
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8233
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8234
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8235 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8236 <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
8237 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
8238 lowercase letters changed to uppercase.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8239 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
8240 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
8241
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8242
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8243
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8244 <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
8245
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8246
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8247 <h4>Character Class:</h4><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8248 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
8249 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
8250
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8251 <ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8252
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8253 <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
8254 (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
8255 <code>^$()%.[]*+-?</code>)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8256 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
8257 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8258
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8259 <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
8260
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8261 <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
8262
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8263 <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
8264
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8265 <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
8266
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8267 <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
8268
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8269 <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
8270
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8271 <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
8272
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8273 <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
8274
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8275 <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
8276
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8277 <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
8278
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8279 <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
8280
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8281 <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
8282 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
8283 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
8284 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
8285 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
8286 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
8287 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8288
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8289 <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
8290 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
8291 characters in <em>set</em>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8292 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
8293 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
8294 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
8295 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
8296 components in <em>set</em>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8297 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
8298 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
8299 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
8300 <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
8301 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
8302 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
8303
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8304
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8305 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8306 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
8307 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
8308 have no meaning.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8309 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8310
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8311 <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
8312 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
8313 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
8314 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8315
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8316 </ul><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8317 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
8318 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
8319 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
8320
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8321
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8322 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8323 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
8324 depend on the current locale.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8325 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
8326
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8327
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8328
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8329
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8330
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8331 <h4>Pattern Item:</h4><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8332 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
8333
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8334 <ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8335
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8336 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8337 a single character class,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8338 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
8339 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8340
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8341 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8342 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
8343 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
8344 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
8345 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8346
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8347 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8348 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
8349 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
8350 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
8351 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8352
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8353 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8354 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
8355 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
8356 Unlike '<code>*</code>',
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8357 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
8358 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8359
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8360 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8361 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
8362 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
8363 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8364
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8365 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8366 <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
8367 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
8368 (see below);
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8369 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8370
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8371 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8372 <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
8373 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
8374 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
8375 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
8376 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
8377 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
8378 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
8379 balanced parentheses.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8380 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8381
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8382 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8383 <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
8384 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
8385 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
8386 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
8387 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
8388 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
8389 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
8390 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8391
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8392 </ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8393
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8394
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8395
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8396
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8397 <h4>Pattern:</h4><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8398 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
8399 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
8400 beginning of the subject string.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8401 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
8402 end of the subject string.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8403 At other positions,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8404 '<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
8405
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8406
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8407
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8408
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8409
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8410 <h4>Captures:</h4><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8411 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
8412 they describe <em>captures</em>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8413 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
8414 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
8415 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
8416 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
8417 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
8418 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
8419 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
8420 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
8421
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8422
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8423 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8424 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
8425 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
8426 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
8427 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
8428
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8429
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8430
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8431
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8432
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8433
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8434
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8435
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8436
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8437
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8438
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8439 <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
8440
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8441 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8442 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
8443 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
8444
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8445
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8446 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8447 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
8448 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
8449 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
8450 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
8451 in tables given as arguments.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8452
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8453
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8454 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8455 For performance reasons,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8456 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
8457
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8458
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8459 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8460 <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
8461
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8462
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8463 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8464 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
8465 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
8466 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
8467 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
8468 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
8469 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
8470
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8471
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8472
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8473
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8474 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8475 <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
8476
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8477
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8478 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8479 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
8480 shifting up the elements
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8481 <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
8482 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
8483 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
8484 of list <code>t</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8485
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8486
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8487
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8488
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8489 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8490 <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
8491
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8492
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8493 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8494 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
8495 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
8496 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
8497
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8498
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8499
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8500
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8501 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8502 <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
8503
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8504
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8505 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8506 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
8507 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
8508 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
8509 it shifts down the elements
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8510 <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
8511 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
8512 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
8513 or <code>#list + 1</code>;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8514 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
8515
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8516
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8517 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8518 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
8519 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
8520 of list <code>t</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8521
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8522
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8523
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8524
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8525 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8526 <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
8527
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8528
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8529 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8530 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
8531 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
8532 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
8533 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
8534 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
8535 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
8536 (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
8537 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
8538 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
8539
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8540
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8541 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8542 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
8543 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
8544 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
8545
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8546
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8547
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8548
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8549 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8550 <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
8551
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8552
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8553 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8554 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
8555 This function is equivalent to
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8556
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8557 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8558 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
8559 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8560 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
8561
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8562
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8563
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8564
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8565
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8566
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8567
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8568 <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
8569
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8570 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8571 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
8572 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
8573
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8574
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8575 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8576 <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
8577
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8578
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8579 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8580 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
8581
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8582
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8583
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8584
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8585 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8586 <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
8587
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8588
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8589 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8590 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
8591
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8592
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8593
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8594
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8595 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8596 <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
8597
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8598
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8599 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8600 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
8601
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8602
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8603
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8604
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8605 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8606 <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
8607
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8608
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8609 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8610 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
8611
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8612
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8613
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8614
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8615 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8616 <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
8617
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8618
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8619 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8620 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
8621 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
8622 quadrant of the result.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8623 (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
8624
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8625
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8626
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8627
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8628 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8629 <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
8630
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8631
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8632 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8633 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
8634
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8635
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8636
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8637
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8638 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8639 <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
8640
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8641
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8642 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8643 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
8644
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8645
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8646
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8647
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8648 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8649 <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
8650
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8651
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8652 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8653 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
8654
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8655
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8656
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8657
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8658 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8659 <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
8660
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8661
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8662 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8663 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
8664
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8665
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8666
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8667
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8668 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8669 <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
8670
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8671
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8672 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8673 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
8674
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8675
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8676
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8677
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8678 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8679 <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
8680
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8681
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8682 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8683 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
8684
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8685
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8686
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8687
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8688 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8689 <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
8690
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8691
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8692 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8693 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
8694 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
8695
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8696
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8697
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8698
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8699 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8700 <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
8701
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8702
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8703 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8704 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
8705 <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
8706 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
8707 (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
8708
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8709
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8710
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8711
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8712 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8713 <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
8714
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8715
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8716 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8717 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
8718 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
8719
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8720
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8721
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8722
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8723 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8724 <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
8725
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8726
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8727 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8728 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
8729
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8730
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8731
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8732
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8733 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8734 <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
8735
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8736
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8737 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8738 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
8739 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
8740 (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
8741
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8742
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8743
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8744
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8745 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8746 <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
8747
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8748
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8749 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8750 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
8751
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8752
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8753
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8754
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8755 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8756 <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
8757
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8758
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8759 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8760 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
8761
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8762
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8763
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8764
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8765 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8766 <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
8767
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8768
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8769 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8770 Returns two numbers,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8771 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
8772
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8773
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8774
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8775
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8776 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8777 <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
8778
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8779
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8780 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8781 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
8782
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8783
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8784
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8785
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8786 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8787 <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
8788
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8789
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8790 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8791 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
8792 (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
8793
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8794
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8795
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8796
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8797 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8798 <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
8799
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8800
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8801 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8802 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
8803
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8804
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8805
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8806
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8807 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8808 <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
8809
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8810
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8811 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8812 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
8813 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
8814 (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
8815
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8816
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8817 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8818 When called without arguments,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8819 returns a uniform pseudo-random real number
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8820 in the range <em>[0,1)</em>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8821 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
8822 <code>math.random</code> returns
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8823 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
8824 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
8825 <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
8826 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
8827
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8828
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8829
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8830
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8831 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8832 <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
8833
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8834
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8835 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8836 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
8837 for the pseudo-random generator:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8838 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
8839
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8840
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8841
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8842
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8843 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8844 <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
8845
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8846
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8847 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8848 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
8849
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8850
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8851
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8852
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8853 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8854 <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
8855
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8856
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8857 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8858 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
8859
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8860
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8861
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8862
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8863 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8864 <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
8865
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8866
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8867 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8868 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
8869 (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
8870
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8871
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8872
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8873
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8874 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8875 <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
8876
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8877
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8878 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8879 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
8880
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8881
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8882
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8883
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8884 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8885 <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
8886
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8887
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8888 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8889 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
8890
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8891
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8892
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8893
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8894
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8895
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8896
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8897 <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
8898
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8899 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8900 This library provides bitwise operations.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8901 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
8902
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8903
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8904 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8905 Unless otherwise stated,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8906 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
8907 <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
8908 each argument is normalized to
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8909 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
8910 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
8911 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
8912 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
8913 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
8914 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
8915
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8916
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8917 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8918 <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
8919
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8920
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8921 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8922 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
8923 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
8924 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
8925
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8926
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8927 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8928 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
8929 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
8930 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
8931 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
8932 In particular,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8933 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
8934 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
8935
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8936
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8937
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8938
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8939 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8940 <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
8941
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8942
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8943 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8944 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
8945
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8946
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8947
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8948
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8949 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8950 <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
8951
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8952
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8953 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8954 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
8955 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
8956 the following identity holds:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8957
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8958 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8959 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
8960 </pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8961
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8962
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8963
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8964 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8965 <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
8966
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8967
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8968 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8969 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
8970
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8971
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8972
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8973
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8974 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8975 <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
8976
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8977
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8978 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8979 Returns a boolean signaling
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8980 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
8981
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8982
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8983
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8984
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8985 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8986 <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
8987
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8988
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8989 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8990 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
8991
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8992
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8993
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8994
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8995 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8996 <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
8997
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8998
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8999 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9000 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
9001 <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
9002 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
9003 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
9004
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9005
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9006 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9007 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
9008
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9009
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9010
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9011
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9012 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9013 <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
9014
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9015
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9016 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9017 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
9018 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
9019 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
9020 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
9021
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9022
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9023
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9024
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9025 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9026 <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
9027
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9028
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9029 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9030 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
9031 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
9032
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9033
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9034 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9035 For any valid displacement,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9036 the following identity holds:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9037
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9038 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9039 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
9040 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9041 In particular,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9042 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
9043
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9044
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9045
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9046
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9047 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9048 <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
9049
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9050
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9051 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9052 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
9053 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
9054 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
9055 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
9056 In particular,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9057 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
9058 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
9059
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9060
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9061 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9062 For positive displacements,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9063 the following equality holds:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9064
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9065 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9066 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
9067 </pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9068
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9069
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9070
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9071 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9072 <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
9073
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9074
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9075 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9076 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
9077 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
9078
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9079
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9080 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9081 For any valid displacement,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9082 the following identity holds:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9083
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9084 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9085 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
9086 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9087 In particular,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9088 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
9089
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9090
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9091
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9092
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9093 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9094 <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
9095
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9096
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9097 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9098 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
9099 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
9100 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
9101 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
9102 In particular,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9103 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
9104 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
9105
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9106
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9107 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9108 For positive displacements,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9109 the following equality holds:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9110
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9111 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9112 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
9113 </pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9114
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9115 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9116 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
9117
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9118
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9119
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9120
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9121
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9122
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9123
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9124 <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
9125
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9126 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9127 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
9128 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
9129 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
9130 default output file,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9131 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
9132 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
9133
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9134
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9135 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9136 When using implicit file descriptors,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9137 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
9138 When using explicit file descriptors,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9139 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
9140 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
9141
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9142
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9143 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9144 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
9145 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
9146 <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
9147 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
9148
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9149
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9150 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9151 Unless otherwise stated,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9152 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
9153 (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
9154 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
9155 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
9156 On non-Posix systems,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9157 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
9158 in case of errors
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9159 may be not thread safe,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9160 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
9161
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9162
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9163 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9164 <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
9165
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9166
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9167 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9168 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
9169 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
9170
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9171
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9172
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9173
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9174 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9175 <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
9176
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9177
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9178 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9179 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
9180
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9181
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9182
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9183
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9184 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9185 <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
9186
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9187
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9188 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9189 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
9190 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
9191 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
9192 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
9193 When called without parameters,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9194 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
9195
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9196
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9197 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9198 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
9199 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
9200
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9201
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9202
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9203
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9204 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9205 <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
9206
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9207
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9208 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9209 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
9210 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
9211 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
9212 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
9213 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
9214
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9215
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9216 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9217 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
9218 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
9219 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
9220 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
9221
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9222
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9223 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9224 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
9225 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
9226
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9227
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9228
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9229
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9230 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9231 <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
9232
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9233
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9234 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9235 This function opens a file,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9236 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
9237 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
9238 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
9239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9240
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9241 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9242 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
9243
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9244 <ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9245 <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
9246 <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
9247 <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
9248 <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
9249 <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
9250 <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
9251 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
9252 </ul><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9253 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
9254 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
9255
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9256
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9257
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9258
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9259 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9260 <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
9261
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9262
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9263 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9264 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
9265
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9266
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9267
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9268
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9269 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9270 <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
9271
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9272
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9273 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9274 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
9275 on all platforms.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9276
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9277
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9278 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9279 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
9280 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
9281 (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
9282 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
9283 (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
9284
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9285
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9286
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9287
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9288 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9289 <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
9290
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9291
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9292 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9293 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
9294
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9295
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9296
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9297
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9298 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9299 <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
9300
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9301
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9302 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9303 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
9304 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
9305 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
9306
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9307
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9308
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9309
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9310 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9311 <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
9312
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9313
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9314 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9315 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
9316 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
9317 <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
9318 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
9319
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9320
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9321
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9322
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9323 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9324 <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
9325
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9326
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9327 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9328 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
9329
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9330
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9331
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9332
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9333 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9334 <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
9335
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9336
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9337 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9338 Closes <code>file</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9339 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
9340 their handles are garbage collected,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9341 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
9342
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9343
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9344 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9345 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
9346 <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
9347 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
9348
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9349
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9350
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9351
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9352 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9353 <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
9354
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9355
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9356 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9357 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
9358
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9359
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9360
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9361
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9362 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9363 <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
9364
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9365
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9366 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9367 Returns an iterator function that,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9368 each time it is called,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9369 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
9370 When no format is given,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9371 uses "*l" as a default.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9372 As an example, the construction
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9373
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9374 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9375 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
9376 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9377 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
9378 starting at the current position.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9379 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
9380 when the loop ends.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9381
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9382
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9383 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9384 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
9385 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
9386
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9387
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9388
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9389
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9390 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9391 <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
9392
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9393
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9394 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9395 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
9396 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
9397 For each format,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9398 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
9399 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
9400 When called without formats,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9401 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
9402 (see below).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9403
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9404
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9405 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9406 The available formats are
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9407
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9408 <ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9409
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9410 <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
9411 reads a number;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9412 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
9413 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9414
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9415 <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
9416 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
9417 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
9418 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9419
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9420 <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
9421 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
9422 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
9423 This is the default format.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9424 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9425
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9426 <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
9427 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
9428 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
9429 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9430
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9431 <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
9432 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
9433 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
9434 If number is zero,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9435 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
9436 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
9437 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9438
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9439 </ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9440
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9441
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9442
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9443 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9444 <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
9445
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9446
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9447 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9448 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
9449 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
9450 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
9451 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
9452
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9453 <ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9454 <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
9455 <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
9456 <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
9457 </ul><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9458 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
9459 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
9460 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
9461 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
9462
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9463
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9464 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9465 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
9466 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
9467 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
9468 file position, without changing it;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9469 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
9470 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
9471 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
9472 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
9473
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9474
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9475
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9476
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9477 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9478 <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
9479
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9480
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9481 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9482 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
9483 There are three available modes:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9484
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9485 <ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9486
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9487 <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
9488 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
9489 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9490
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9491 <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
9492 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
9493 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
9494 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
9495 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9496
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9497 <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
9498 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
9499 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
9500 (such as a terminal device).
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9501 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9502
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9503 </ul><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9504 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
9505 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
9506 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
9507
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9508
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9509
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9510
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9511 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9512 <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
9513
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9514
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9515 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9516 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
9517 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
9518
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9519
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9520 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9521 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
9522 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
9523
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9524
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9525
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9526
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9527
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9528
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9529
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9530 <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
9531
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9532 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9533 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
9534
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9535
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9536 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9537 <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
9538
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9539
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9540 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9541 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
9542 used by the program.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9543
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9544
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9545
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9546
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9547 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9548 <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
9549
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9550
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9551 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9552 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
9553 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
9554
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9555
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9556 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9557 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
9558 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
9559 (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
9560 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
9561
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9562
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9563 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9564 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
9565 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
9566 After this optional character,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9567 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
9568 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
9569 <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
9570 <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
9571 <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
9572 <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
9573 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
9574 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
9575 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
9576
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9577
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9578 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9579 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
9580 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
9581 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
9582
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9583
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9584 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9585 When called without arguments,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9586 <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
9587 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
9588 (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
9589
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9590
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9591 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9592 On non-Posix systems,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9593 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
9594 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
9595
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9596
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9597
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9598
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9599 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9600 <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
9601
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9602
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9603 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9604 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
9605 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
9606 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
9607
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9608
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9609
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9610
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9611 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9612 <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
9613
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9614
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9615 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9616 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
9617 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
9618 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
9619 if the command terminated successfully,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9620 or <b>nil</b> otherwise.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9621 After this first result
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9622 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
9623 as follows:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9624
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9625 <ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9626
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9627 <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
9628 the command terminated normally;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9629 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
9630 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9631
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9632 <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
9633 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
9634 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
9635 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9636
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9637 </ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9638
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9639 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9640 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
9641 <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
9642
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9643
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9644
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9645
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9646 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9647 <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
9648
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9649
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9650 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9651 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
9652 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
9653 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
9654 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
9655 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
9656 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
9657 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
9658 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
9659
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9660
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9661 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9662 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
9663 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
9664
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9665
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9666
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9667
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9668 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9669 <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
9670
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9671
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9672 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9673 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
9674 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
9675
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9676
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9677
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9678
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9679 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9680 <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
9681
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9682
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9683 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9684 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
9685 with the given name.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9686 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
9687 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
9688
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9689
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9690
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9691
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9692 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9693 <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
9694
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9695
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9696 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9697 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
9698 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
9699 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
9700
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9701
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9702
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9703
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9704 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9705 <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
9706
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9707
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9708 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9709 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
9710 <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
9711 <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
9712 <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
9713 <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
9714 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
9715 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
9716 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
9717
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9718
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9719 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9720 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
9721 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
9722 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
9723 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
9724
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9725
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9726 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9727 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
9728 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
9729 for the given category.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9730
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9731
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9732 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9733 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
9734 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
9735
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9736
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9737
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9738
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9739 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9740 <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
9741
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9742
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9743 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9744 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
9745 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
9746 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
9747 and may have fields
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9748 <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
9749 <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
9750 <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
9751 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
9752 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
9753
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9754
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9755 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9756 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
9757 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
9758 this number counts the number
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9759 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
9760 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
9761 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
9762 <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
9763
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9764
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9765
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9766
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9767 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9768 <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
9769
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9770
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9771 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9772 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
9773 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
9774 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
9775 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
9776
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9777
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9778 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9779 On POSIX systems,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9780 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
9781 to avoid security risks.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9782 (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
9783 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
9784 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
9785 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
9786
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9787
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9788 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9789 When possible,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9790 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
9791 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
9792
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9793
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9794
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9795
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9796
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9797
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9798
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9799 <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
9800
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9801 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9802 This library provides
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9803 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
9804 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
9805 Several of its functions
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9806 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
9807 (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
9808 cannot be accessed from outside;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9809 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
9810 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
9811 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
9812 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
9813
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9814
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9815 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9816 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
9817 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
9818 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
9819 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
9820 thread to operate over.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9821 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
9822
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9823
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9824 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9825 <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
9826
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9827
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9828 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9829 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
9830 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
9831 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
9832 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
9833 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
9834 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
9835 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
9836
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9837
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9838 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9839 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
9840 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
9841
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9842
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9843
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9844
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9845 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9846 <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
9847
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9848
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9849 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9850 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
9851 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
9852 and the current hook count
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9853 (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
9854
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9855
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9856
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9857
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9858 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9859 <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
9860
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9861
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9862 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9863 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
9864 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
9865 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
9866 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
9867 of the given thread:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9868 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
9869 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
9870 (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
9871 and so on.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9872 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
9873 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
9874
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9875
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9876 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9877 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
9878 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
9879 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
9880 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
9881 If present,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9882 the option '<code>f</code>'
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9883 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
9884 If present,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9885 the option '<code>L</code>'
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9886 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
9887 valid lines.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9888
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9889
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9890 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9891 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
9892 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
9893 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
9894 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
9895 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
9896 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
9897
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9898
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9899
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9900
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9901 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9902 <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
9903
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9904
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9905 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9906 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
9907 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
9908 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
9909 but also parameters, temporaries, etc.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9910
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9911
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9912 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9913 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
9914 until the last active variable.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9915 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
9916 -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
9917 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
9918 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
9919 (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
9920
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9921
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9922 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9923 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
9924 represent internal variables
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9925 (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
9926
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9927
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9928 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9929 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
9930 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
9931
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9932
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9933
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9934
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9935 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9936 <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
9937
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9938
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9939 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9940 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
9941 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
9942
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9943
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9944
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9945
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9946 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9947 <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
9948
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9949
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9950 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9951 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
9952
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9953
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9954
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9955
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9956 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9957 <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
9958
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9959
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9960 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9961 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
9962 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
9963 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
9964
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9965
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9966
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9967
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9968 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9969 <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
9970
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9971
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9972 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9973 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
9974 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
9975 returns <b>nil</b>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9976
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9977
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9978
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9979
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9980 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9981 <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
9982
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9983
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9984 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9985 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
9986 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
9987 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
9988 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
9989 with the given meaning:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9990
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9991 <ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9992 <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
9993 <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
9994 <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
9995 </ul><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9996 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
9997 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
9998
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
9999
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10000 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10001 When called without arguments,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10002 <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
10003
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10004
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10005 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10006 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
10007 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
10008 <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
10009 <code>"return"</code>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10010 <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
10011 For line events,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10012 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
10013 Inside a hook,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10014 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
10015 the running function
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10016 (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
10017 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
10018
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10019
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10020
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10021
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10022 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10023 <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
10024
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10025
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10026 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10027 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
10028 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
10029 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
10030 variable with the given index,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10031 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
10032 (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
10033 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
10034
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10035
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10036 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10037 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
10038 variable indices and names.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10039
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10040
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10041
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10042
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10043 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10044 <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
10045
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10046
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10047 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10048 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
10049 (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
10050 Returns <code>value</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10051
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10052
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10053
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10054
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10055 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10056 <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
10057
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10058
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10059 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10060 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
10061 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
10062 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
10063 with the given index.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10064 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
10065
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10066
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10067
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10068
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10069 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10070 <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
10071
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10072
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10073 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10074 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
10075 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
10076 <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
10077 <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
10078
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10079
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10080 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10081 Returns <code>udata</code>.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10082
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10083
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10084
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10085
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10086 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10087 <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
10088
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10089
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10090 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10091 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
10092 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
10093 Otherwise,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10094 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
10095 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
10096 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
10097 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
10098 to start the traceback
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10099 (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
10100
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10101
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10102
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10103
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10104 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10105 <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
10106
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10107
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10108 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10109 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
10110 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
10111 from the given function.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10112
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10113
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10114 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10115 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
10116 closures share upvalues.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10117 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
10118 (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
10119 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
10120
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10121
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10122
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10123
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10124 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10125 <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
10126
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10127
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10128 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10129 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
10130 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
10131
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10132
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10133
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10134
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10135
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10136
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10137
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10138 <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
10139
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10140 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10141 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
10142 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
10143 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
10144 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
10145 called simply <code>lua</code>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10146 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
10147 The standalone interpreter includes
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10148 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
10149 Its usage is:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10150
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10151 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10152 lua [options] [script [args]]
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10153 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10154 The options are:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10155
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10156 <ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10157 <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
10158 <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
10159 <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
10160 <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
10161 <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
10162 <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
10163 <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
10164 </ul><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10165 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
10166 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
10167 When called without arguments,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10168 <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
10169 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
10170 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
10171
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10172
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10173 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10174 When called without option <code>-E</code>,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10175 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
10176 (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
10177 before running any argument.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10178 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
10179 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
10180 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
10181
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10182
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10183 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10184 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
10185 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
10186 Lua also ignores
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10187 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
10188 setting the values of
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10189 <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
10190 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
10191
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10192
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10193 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10194 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
10195 For instance, an invocation like
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10196
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10197 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10198 $ 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
10199 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10200 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
10201 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
10202 (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
10203
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10204
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10205 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10206 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
10207 <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
10208 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
10209 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
10210 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
10211 and so on.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10212 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
10213 (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
10214 go to negative indices.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10215 For instance, in the call
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10216
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10217 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10218 $ 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
10219 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10220 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
10221 then creates a table
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10222
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10223 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10224 arg = { [-2] = "lua", [-1] = "-la",
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10225 [0] = "b.lua",
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10226 [1] = "t1", [2] = "t2" }
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10227 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10228 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
10229 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
10230 as arguments;
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10231 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
10232
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10233
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10234 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10235 In interactive mode,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10236 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
10237 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
10238 by issuing a different prompt.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10239
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10240
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10241 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10242 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
10243 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
10244 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
10245 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
10246 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
10247 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
10248 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
10249 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
10250
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10251
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10252 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10253 When finishing normally,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10254 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
10255 (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
10256 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
10257 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
10258
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10259
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10260 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10261 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
10262 script interpreter in Unix systems,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10263 the standalone interpreter skips
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10264 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
10265 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
10266 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
10267 as in
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10268
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10269 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10270 #!/usr/local/bin/lua
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10271 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10272 (Of course,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10273 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
10274 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
10275 then
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10276
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10277 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10278 #!/usr/bin/env lua
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10279 </pre><p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10280 is a more portable solution.)
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10281
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10282
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10283
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10284 <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
10285
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10286 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10287 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
10288 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
10289 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
10290 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
10291 However,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10292 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
10293 Similarly,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10294 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
10295 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
10296
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10297
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10298
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10299 <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
10300 <ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10301
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10302 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10303 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
10304 Only Lua functions have environments.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10305 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
10306 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
10307
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10308
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10309 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10310 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
10311 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
10312 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
10313 (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
10314 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
10315
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10316
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10317 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10318 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
10319 (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
10320 use the new functions
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10321 <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
10322 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10323
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10324 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10325 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
10326 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10327
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10328 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10329 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
10330 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
10331 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10332
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10333 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10334 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
10335 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10336
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10337 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10338 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
10339 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
10340 <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
10341 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
10342 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10343
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10344 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10345 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
10346 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
10347 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
10348 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
10349 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10350
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10351 </ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10352
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10353
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10354
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10355
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10356 <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
10357 <ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10358
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10359 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10360 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
10361 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
10362 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
10363 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10364
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10365 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10366 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
10367 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
10368 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10369
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10370 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10371 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
10372 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
10373 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10374
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10375 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10376 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
10377 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
10378 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
10379 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10380
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10381 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10382 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
10383 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
10384 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10385
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10386 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10387 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
10388 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
10389 otherwise.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10390 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10391
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10392 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10393 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
10394 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
10395 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10396
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10397 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10398 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
10399 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
10400 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10401
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10402 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10403 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
10404 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10405
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10406 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10407 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
10408 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
10409 (<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
10410 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
10411 (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
10412 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
10413 When in doubt,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10414 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
10415 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
10416 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10417
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10418 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10419 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
10420 change between versions.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10421 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10422
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10423 </ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10424
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10425
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10426
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10427
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10428 <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
10429 <ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10430
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10431 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10432 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
10433 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
10434 (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
10435 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10436
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10437 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10438 Pseudoindex <code>LUA_ENVIRONINDEX</code>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10439 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
10440 were removed,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10441 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
10442 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10443
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10444 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10445 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
10446 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
10447 (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
10448 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10449
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10450 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10451 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
10452 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
10453 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
10454 (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
10455 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
10456 the block is new.
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10457 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10458
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10459 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10460 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
10461 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
10462 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
10463 (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
10464 Moreover,
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10465 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
10466 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
10467 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
10468 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10469
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10470 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10471 <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
10472 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
10473 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10474
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10475 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10476 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
10477 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
10478 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
10479 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10480
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10481 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10482 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
10483 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
10484 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10485
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10486 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10487 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
10488 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10489
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10490 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10491 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
10492 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
10493 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10494
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10495 <li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10496 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
10497 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
10498 </li>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10499
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10500 </ul>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10501
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10502
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10503
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10504
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10505 <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
10506
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10507 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10508 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
10509 (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
10510
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10511
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10512
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10513
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10514 <pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10515
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10516 chunk ::= block
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10517
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10518 block ::= {stat} [retstat]
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10519
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10520 stat ::= &lsquo;<b>;</b>&rsquo; |
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10521 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
10522 functioncall |
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10523 label |
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10524 <b>break</b> |
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10525 <b>goto</b> Name |
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10526 <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
10527 <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
10528 <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
10529 <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
10530 <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> |
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10531 <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
10532 <b>function</b> funcname funcbody |
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10533 <b>local</b> <b>function</b> Name funcbody |
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10534 <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
10535
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10536 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
10537
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10538 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
10539
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10540 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
10541
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10542 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
10543
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10544 var ::= Name | prefixexp &lsquo;<b>[</b>&rsquo; exp &lsquo;<b>]</b>&rsquo; | 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
10545
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10546 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
10547
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10548 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
10549
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10550 exp ::= <b>nil</b> | <b>false</b> | <b>true</b> | Number | String | &lsquo;<b>...</b>&rsquo; | functiondef |
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10551 prefixexp | tableconstructor | exp binop exp | unop exp
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10552
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10553 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
10554
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10555 functioncall ::= prefixexp args | prefixexp &lsquo;<b>:</b>&rsquo; Name args
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10556
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10557 args ::= &lsquo;<b>(</b>&rsquo; [explist] &lsquo;<b>)</b>&rsquo; | tableconstructor | String
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10558
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10559 functiondef ::= <b>function</b> funcbody
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10560
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10561 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
10562
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10563 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
10564
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10565 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
10566
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10567 fieldlist ::= field {fieldsep field} [fieldsep]
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10568
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10569 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
10570
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10571 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
10572
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10573 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; |
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10574 &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; |
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10575 <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
10576
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10577 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
10578
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10579 </pre>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10580
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10581 <p>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10582
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10583
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10584
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10585
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10586
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10587
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10588
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10589 <HR>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10590 <SMALL CLASS="footer">
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10591 Last update:
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10592 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
10593 </SMALL>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10594 <!--
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10595 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
10596 -->
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10597
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10598 </body></html>
aa7bc9c1df22 add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10599