Mercurial Hosting > luan
annotate docs/manual.html @ 239:aa7bc9c1df22
add unedited Lua manual
git-svn-id: https://luan-java.googlecode.com/svn/trunk@240 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Mon, 06 Oct 2014 22:03:16 +0000 |
parents | |
children | bcc3911285a2 |
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> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6 <link rel="stylesheet" type="text/css" href="http://www.lua.org/lua.css"> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7 <link rel="stylesheet" type="text/css" href="http://www.lua.org/manual/manual.css"> |
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> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
15 <a href="../../home.html"><img src="../../images/logo.gif" alt="" border="0"></a> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
16 Lua 5.2 Reference Manual |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
17 </h1> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
18 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
19 by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
20 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
21 <small> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
22 Copyright © 2011–2013 Lua.org, PUC-Rio. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
23 Freely available under the terms of the |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
24 <a href="../../license.html">Lua license</a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
25 </small> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
26 <hr> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
27 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
28 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
29 <a href="contents.html#contents">contents</A> |
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 <a href="contents.html#index">index</A> |
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 <a href="../">other versions</A> |
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 <!-- ====================================================================== --> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
36 <p> |
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 <!-- $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
|
39 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
40 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
41 <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
|
42 <UL style="padding: 0"> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
43 <LI><A HREF="manual.html#1">1 – Introduction</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
44 <P> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
45 <LI><A HREF="manual.html#2">2 – Basic Concepts</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
46 <UL> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
47 <LI><A HREF="manual.html#2.1">2.1 – Values and Types</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
48 <LI><A HREF="manual.html#2.2">2.2 – Environments and the Global Environment</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
49 <LI><A HREF="manual.html#2.3">2.3 – Error Handling</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
50 <LI><A HREF="manual.html#2.4">2.4 – Metatables and Metamethods</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
51 <LI><A HREF="manual.html#2.5">2.5 – Garbage Collection</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
52 <UL> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
53 <LI><A HREF="manual.html#2.5.1">2.5.1 – Garbage-Collection Metamethods</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
54 <LI><A HREF="manual.html#2.5.2">2.5.2 – Weak Tables</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
55 </UL> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
56 <LI><A HREF="manual.html#2.6">2.6 – Coroutines</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
57 </UL> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
58 <P> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
59 <LI><A HREF="manual.html#3">3 – The Language</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
60 <UL> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
61 <LI><A HREF="manual.html#3.1">3.1 – Lexical Conventions</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
62 <LI><A HREF="manual.html#3.2">3.2 – Variables</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
63 <LI><A HREF="manual.html#3.3">3.3 – Statements</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
64 <UL> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
65 <LI><A HREF="manual.html#3.3.1">3.3.1 – Blocks</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
66 <LI><A HREF="manual.html#3.3.2">3.3.2 – Chunks</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
67 <LI><A HREF="manual.html#3.3.3">3.3.3 – Assignment</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
68 <LI><A HREF="manual.html#3.3.4">3.3.4 – Control Structures</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
69 <LI><A HREF="manual.html#3.3.5">3.3.5 – For Statement</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
70 <LI><A HREF="manual.html#3.3.6">3.3.6 – Function Calls as Statements</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
71 <LI><A HREF="manual.html#3.3.7">3.3.7 – Local Declarations</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
72 </UL> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
73 <LI><A HREF="manual.html#3.4">3.4 – Expressions</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
74 <UL> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
75 <LI><A HREF="manual.html#3.4.1">3.4.1 – Arithmetic Operators</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
76 <LI><A HREF="manual.html#3.4.2">3.4.2 – Coercion</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
77 <LI><A HREF="manual.html#3.4.3">3.4.3 – Relational Operators</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
78 <LI><A HREF="manual.html#3.4.4">3.4.4 – Logical Operators</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
79 <LI><A HREF="manual.html#3.4.5">3.4.5 – Concatenation</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
80 <LI><A HREF="manual.html#3.4.6">3.4.6 – The Length Operator</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
81 <LI><A HREF="manual.html#3.4.7">3.4.7 – Precedence</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
82 <LI><A HREF="manual.html#3.4.8">3.4.8 – Table Constructors</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
83 <LI><A HREF="manual.html#3.4.9">3.4.9 – Function Calls</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
84 <LI><A HREF="manual.html#3.4.10">3.4.10 – Function Definitions</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
85 </UL> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
86 <LI><A HREF="manual.html#3.5">3.5 – Visibility Rules</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
87 </UL> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
88 <P> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
89 <LI><A HREF="manual.html#4">4 – The Application Program Interface</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
90 <UL> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
91 <LI><A HREF="manual.html#4.1">4.1 – The Stack</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
92 <LI><A HREF="manual.html#4.2">4.2 – Stack Size</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
93 <LI><A HREF="manual.html#4.3">4.3 – Valid and Acceptable Indices</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
94 <LI><A HREF="manual.html#4.4">4.4 – C Closures</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
95 <LI><A HREF="manual.html#4.5">4.5 – Registry</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
96 <LI><A HREF="manual.html#4.6">4.6 – Error Handling in C</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
97 <LI><A HREF="manual.html#4.7">4.7 – Handling Yields in C</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
98 <LI><A HREF="manual.html#4.8">4.8 – Functions and Types</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
99 <LI><A HREF="manual.html#4.9">4.9 – The Debug Interface</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
100 </UL> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
101 <P> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
102 <LI><A HREF="manual.html#5">5 – The Auxiliary Library</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
103 <UL> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
104 <LI><A HREF="manual.html#5.1">5.1 – Functions and Types</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
105 </UL> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
106 <P> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
107 <LI><A HREF="manual.html#6">6 – Standard Libraries</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
108 <UL> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
109 <LI><A HREF="manual.html#6.1">6.1 – Basic Functions</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
110 <LI><A HREF="manual.html#6.2">6.2 – Coroutine Manipulation</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
111 <LI><A HREF="manual.html#6.3">6.3 – Modules</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
112 <LI><A HREF="manual.html#6.4">6.4 – String Manipulation</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
113 <UL> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
114 <LI><A HREF="manual.html#6.4.1">6.4.1 – Patterns</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
115 </UL> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
116 <LI><A HREF="manual.html#6.5">6.5 – Table Manipulation</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
117 <LI><A HREF="manual.html#6.6">6.6 – Mathematical Functions</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
118 <LI><A HREF="manual.html#6.7">6.7 – Bitwise Operations</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
119 <LI><A HREF="manual.html#6.8">6.8 – Input and Output Facilities</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
120 <LI><A HREF="manual.html#6.9">6.9 – Operating System Facilities</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
121 <LI><A HREF="manual.html#6.10">6.10 – The Debug Library</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
122 </UL> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
123 <P> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
124 <LI><A HREF="manual.html#7">7 – Lua Standalone</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
125 <P> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
126 <LI><A HREF="manual.html#8">8 – Incompatibilities with the Previous Version</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
127 <UL> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
128 <LI><A HREF="manual.html#8.1">8.1 – Changes in the Language</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
129 <LI><A HREF="manual.html#8.2">8.2 – Changes in the Libraries</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
130 <LI><A HREF="manual.html#8.3">8.3 – Changes in the API</A> |
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 <P> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
133 <LI><A HREF="manual.html#9">9 – The Complete Syntax of Lua</A> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
134 </UL> |
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
137 <h1>1 – <a name="1">Introduction</a></h1> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
138 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
139 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
140 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
|
141 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
|
142 facilities. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
143 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
|
144 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
|
145 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
|
146 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
|
147 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
|
148 the common subset of Standard C and C++. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
149 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
150 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
151 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
152 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
|
153 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
|
154 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
|
155 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
|
156 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
|
157 and can register C functions to be called by Lua code. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
158 Through the use of C functions, Lua can be augmented to cope with |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
159 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
|
160 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
|
161 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
|
162 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
|
163 for interactive or batch use. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
164 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
165 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
166 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
167 Lua is free software, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
168 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
|
169 as stated in its license. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
170 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
|
171 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
|
172 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
173 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
174 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
175 Like any other reference manual, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
176 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
|
177 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
|
178 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
|
179 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
|
180 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
|
181 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
182 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
183 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
184 <h1>2 – <a name="2">Basic Concepts</a></h1> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
185 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
186 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
187 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
|
188 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
189 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
190 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
191 <h2>2.1 – <a name="2.1">Values and Types</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
192 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
193 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
194 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
|
195 This means that |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
196 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
|
197 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
|
198 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
|
199 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
200 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
201 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
202 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
|
203 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
|
204 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
|
205 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
206 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
207 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
208 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
|
209 <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
|
210 <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
|
211 <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
|
212 <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
|
213 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
|
214 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
|
215 <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
|
216 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
|
217 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
|
218 <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
|
219 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
|
220 the underlying C implementation, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
221 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
|
222 (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
|
223 internal representations for numbers, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
224 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
|
225 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
|
226 <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
|
227 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
228 Lua is 8-bit clean: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
229 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
|
230 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
|
231 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
232 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
233 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
234 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
|
235 functions written in C |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
236 (see <a href="#3.4.9">§3.4.9</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
237 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
238 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
239 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
240 The type <em>userdata</em> is provided to allow arbitrary C data to |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
241 be stored in Lua variables. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
242 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
|
243 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
|
244 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
|
245 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
|
246 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
|
247 except assignment and identity test. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
248 By using <em>metatables</em>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
249 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
|
250 (see <a href="#2.4">§2.4</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
251 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
|
252 only through the C API. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
253 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
|
254 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
255 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
256 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
257 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
|
258 and it is used to implement coroutines (see <a href="#2.6">§2.6</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
259 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
|
260 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
|
261 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
|
262 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
263 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
264 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
265 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
|
266 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
|
267 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
|
268 (<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
|
269 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
|
270 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
|
271 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
|
272 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
|
273 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
|
274 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
|
275 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
276 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
277 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
278 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
|
279 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
|
280 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
|
281 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
|
282 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
|
283 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
|
284 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
|
285 (see <a href="#3.4.8">§3.4.8</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
286 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
287 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
288 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
289 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
|
290 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
|
291 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
|
292 which is called the length of the sequence (see <a href="#3.4.6">§3.4.6</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
293 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
294 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
295 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
296 Like indices, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
297 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
|
298 In particular, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
299 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
|
300 table fields can contain functions. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
301 Thus tables can also carry <em>methods</em> (see <a href="#3.4.10">§3.4.10</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
302 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
303 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
304 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
305 The indexing of tables follows |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
306 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
|
307 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
|
308 denote the same table element |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
309 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
|
310 (that is, equal without metamethods). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
311 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
312 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
313 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
314 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
|
315 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
|
316 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
|
317 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
|
318 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
|
319 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
|
320 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
321 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
322 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
323 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
|
324 of a given value (see <a href="#6.1">§6.1</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
325 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
326 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
327 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
328 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
329 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
330 <h2>2.2 – <a name="2.2">Environments and the Global Environment</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
331 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
332 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
333 As will be discussed in <a href="#3.2">§3.2</a> and <a href="#3.3.3">§3.3.3</a>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
334 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
|
335 to <code>_ENV.var</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
336 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
|
337 an external local variable called <code>_ENV</code> (see <a href="#3.3.2">§3.3.2</a>), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
338 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
|
339 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
340 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
341 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
342 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
|
343 the translation of global names, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
344 <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
|
345 In particular, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
346 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
|
347 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
|
348 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
|
349 following the usual visibility rules of Lua (see <a href="#3.5">§3.5</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
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 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
|
354 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
355 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
356 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
357 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
|
358 This value is kept at a special index in the C registry (see <a href="#4.5">§4.5</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
359 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
|
360 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
361 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
362 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
363 When Lua compiles a chunk, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
364 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
|
365 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
|
366 Therefore, by default, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
367 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
|
368 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
|
369 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
|
370 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
|
371 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
|
372 (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
|
373 of its first upvalue.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
374 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
375 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
376 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
377 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
|
378 (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
|
379 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
|
380 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
|
381 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
|
382 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
|
383 (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
|
384 is never updated by Lua. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
385 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
386 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
387 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
388 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
389 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
390 <h2>2.3 – <a name="2.3">Error Handling</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
391 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
392 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
393 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
|
394 all Lua actions start from C code in the host program |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
395 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
|
396 Whenever an error occurs during |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
397 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
|
398 control returns to the host, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
399 which can take appropriate measures |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
400 (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
|
401 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
402 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
403 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
404 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
|
405 <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
|
406 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
|
407 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
|
408 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
|
409 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
410 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
411 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
412 Whenever there is an error, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
413 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
|
414 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
|
415 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
|
416 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
|
417 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
|
418 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
419 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
420 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
421 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
|
422 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
|
423 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
|
424 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
|
425 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
|
426 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
|
427 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
|
428 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
|
429 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
|
430 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
|
431 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
|
432 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
|
433 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
434 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
435 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
436 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
437 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
438 <h2>2.4 – <a name="2.4">Metatables and Metamethods</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
439 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
440 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
441 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
|
442 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
|
443 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
|
444 under certain special operations. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
445 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
|
446 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
|
447 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
|
448 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
|
449 If it finds one, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
450 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
|
451 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
452 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
453 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
454 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
|
455 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
|
456 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
|
457 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
|
458 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
459 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
460 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
461 You can 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
|
462 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
|
463 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
464 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
465 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
466 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
|
467 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
|
468 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
|
469 (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
|
470 you must use the C API for that. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
471 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
472 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
473 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
474 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
|
475 (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
|
476 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
|
477 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
|
478 one for all strings, etc. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
479 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
|
480 but the string library sets a metatable for the string type (see <a href="#6.4">§6.4</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
481 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
482 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
483 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
484 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
|
485 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
|
486 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
|
487 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
|
488 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
|
489 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
|
490 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
|
491 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
|
492 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
493 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
494 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
495 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
|
496 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
|
497 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
|
498 two underscores, '<code>__</code>'; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
499 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
|
500 string "<code>__add</code>". |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
501 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
502 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
503 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
504 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
|
505 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
|
506 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
|
507 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
|
508 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
|
509 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
|
510 (<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
|
511 are described in <a href="#6.1">§6.1</a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
512 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
|
513 we use the expression |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
514 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
515 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
516 metatable(obj)[event] |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
517 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
518 This should be read as |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
519 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
520 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
521 rawget(getmetatable(obj) or {}, event) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
522 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
523 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
|
524 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
|
525 (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
|
526 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
527 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
528 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
529 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
|
530 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
|
531 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
|
532 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
|
533 in the following code. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
534 (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
|
535 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
536 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
537 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
538 <ul> |
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 <li><b>"add": </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
541 the <code>+</code> operation. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
542 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
543 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
544 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
545 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
546 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
|
547 for a binary operation. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
548 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
|
549 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
|
550 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
|
551 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
552 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
553 function getbinhandler (op1, op2, event) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
554 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
|
555 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
556 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
557 By using this function, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
558 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
|
559 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
560 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
561 function add_event (op1, op2) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
562 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
|
563 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
|
564 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
|
565 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
|
566 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
|
567 if h then |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
568 -- 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
|
569 return (h(op1, op2)) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
570 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
|
571 error(···) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
572 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
573 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
574 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
575 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
576 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
577 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
578 <li><b>"sub": </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
579 the <code>-</code> operation. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
580 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
581 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
|
582 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
583 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
584 <li><b>"mul": </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
585 the <code>*</code> operation. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
586 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
587 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
|
588 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
589 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
590 <li><b>"div": </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
591 the <code>/</code> operation. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
592 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
593 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
|
594 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
595 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
596 <li><b>"mod": </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
597 the <code>%</code> operation. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
598 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
599 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
|
600 with the operation |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
601 <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
|
602 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
603 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
604 <li><b>"pow": </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
605 the <code>^</code> (exponentiation) operation. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
606 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
607 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
|
608 with the function <code>pow</code> (from the C math library) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
609 as the primitive operation. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
610 </li> |
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 <li><b>"unm": </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
613 the unary <code>-</code> operation. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
614 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
615 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
616 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
617 function unm_event (op) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
618 local o = tonumber(op) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
619 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
|
620 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
|
621 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
|
622 -- 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
|
623 local h = metatable(op).__unm |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
624 if h then |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
625 -- 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
|
626 return (h(op)) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
627 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
|
628 error(···) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
629 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
630 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
631 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
632 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
633 </li> |
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 <li><b>"concat": </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
636 the <code>..</code> (concatenation) operation. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
637 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
638 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
639 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
640 function concat_event (op1, op2) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
641 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
|
642 (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
|
643 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
|
644 else |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
645 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
|
646 if h then |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
647 return (h(op1, op2)) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
648 else |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
649 error(···) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
650 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
651 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
652 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
653 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
654 </li> |
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 <li><b>"len": </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
657 the <code>#</code> operation. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
658 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
659 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
660 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
661 function len_event (op) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
662 if type(op) == "string" then |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
663 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
|
664 else |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
665 local h = metatable(op).__len |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
666 if h then |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
667 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
|
668 elseif type(op) == "table" then |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
669 return #op -- primitive table length |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
670 else -- no handler available: error |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
671 error(···) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
672 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
673 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
674 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
675 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
676 See <a href="#3.4.6">§3.4.6</a> for a description of the length of a table. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
677 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
678 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
679 <li><b>"eq": </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
680 the <code>==</code> operation. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
681 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
682 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
|
683 for equality. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
684 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
|
685 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
|
686 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
|
687 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
|
688 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
689 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
690 function getequalhandler (op1, op2) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
691 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
|
692 (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
|
693 return nil -- different values |
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 local mm1 = metatable(op1).__eq |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
696 local mm2 = metatable(op2).__eq |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
697 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
|
698 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
699 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
700 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
|
701 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
702 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
703 function eq_event (op1, op2) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
704 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
|
705 return true -- values are equal |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
706 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
707 -- try metamethod |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
708 local h = getequalhandler(op1, op2) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
709 if h then |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
710 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
|
711 else |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
712 return false |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
713 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
714 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
715 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
716 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
|
717 </li> |
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 <li><b>"lt": </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
720 the <code><</code> operation. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
721 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
722 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
723 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
724 function lt_event (op1, op2) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
725 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
|
726 return op1 < op2 -- numeric comparison |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
727 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
|
728 return op1 < op2 -- lexicographic comparison |
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 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
|
731 if h then |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
732 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
|
733 else |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
734 error(···) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
735 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
736 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
737 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
738 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
739 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
|
740 </li> |
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 <li><b>"le": </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
743 the <code><=</code> operation. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
744 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
745 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
746 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
747 function le_event (op1, op2) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
748 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
|
749 return op1 <= op2 -- numeric comparison |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
750 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
|
751 return op1 <= op2 -- lexicographic comparison |
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 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
|
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 not h(op1, op2) |
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 h = getbinhandler(op1, op2, "__lt") |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
758 if h then |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
759 return not h(op2, op1) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
760 else |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
761 error(···) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
762 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
763 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
764 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
765 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
766 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
767 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
|
768 Lua tries the "lt", assuming that <code>a <= b</code> is |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
769 equivalent to <code>not (b < a)</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
770 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
771 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
772 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
773 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
|
774 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
|
775 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
776 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
777 <li><b>"index": </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
778 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
|
779 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
|
780 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
|
781 (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
|
782 no key is ever present, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
783 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
|
784 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
785 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
786 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
787 function gettable_event (table, key) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
788 local h |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
789 if type(table) == "table" then |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
790 local v = rawget(table, key) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
791 -- 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
|
792 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
|
793 h = metatable(table).__index |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
794 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
|
795 else |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
796 h = metatable(table).__index |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
797 if h == nil then |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
798 error(···) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
799 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
800 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
801 if type(h) == "function" then |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
802 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
|
803 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
|
804 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
805 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
806 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
807 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
808 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
809 <li><b>"newindex": </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
810 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
|
811 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
|
812 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
|
813 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
814 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
815 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
816 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
|
817 local h |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
818 if type(table) == "table" then |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
819 local v = rawget(table, key) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
820 -- 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
|
821 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
|
822 h = metatable(table).__newindex |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
823 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
|
824 else |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
825 h = metatable(table).__newindex |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
826 if h == nil then |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
827 error(···) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
828 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
829 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
830 if type(h) == "function" then |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
831 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
|
832 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
|
833 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
834 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
835 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
836 </li> |
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 <li><b>"call": </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
839 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
|
840 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
841 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
842 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
843 function function_event (func, ...) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
844 if type(func) == "function" then |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
845 return func(...) -- primitive call |
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 local h = metatable(func).__call |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
848 if h then |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
849 return h(func, ...) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
850 else |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
851 error(···) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
852 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
853 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
854 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
855 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
856 </li> |
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 </ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
859 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
860 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
861 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
862 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
863 <h2>2.5 – <a name="2.5">Garbage Collection</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
864 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
865 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
866 Lua performs automatic memory management. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
867 This means that |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
868 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
|
869 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
|
870 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
|
871 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
|
872 (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
|
873 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
|
874 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
|
875 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
876 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
877 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
878 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
|
879 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
|
880 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
|
881 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
|
882 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
|
883 (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
|
884 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
885 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
886 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
887 The garbage-collector pause |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
888 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
|
889 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
|
890 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
|
891 start a new cycle. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
892 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
|
893 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
|
894 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
895 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
896 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
897 The garbage-collector step multiplier |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
898 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
|
899 memory allocation. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
900 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
|
901 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
|
902 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
|
903 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
|
904 The default is 200, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
905 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
|
906 the speed of memory allocation. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
907 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
908 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
909 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
910 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
|
911 (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
|
912 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
|
913 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
|
914 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
|
915 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
|
916 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
|
917 memory usage. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
918 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
919 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
920 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
921 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
|
922 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
|
923 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
|
924 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
|
925 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
926 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
927 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
928 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
|
929 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
|
930 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
|
931 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
|
932 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
|
933 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
|
934 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
|
935 To mitigate this second problem, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
936 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
|
937 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
|
938 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
|
939 but check your gains. |
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
942 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
943 <h3>2.5.1 – <a name="2.5.1">Garbage-Collection Metamethods</a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
944 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
945 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
946 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
|
947 and, using the C API, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
948 for full userdata (see <a href="#2.4">§2.4</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
949 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
|
950 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
|
951 with external resource management |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
952 (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
|
953 or freeing your own memory). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
954 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
955 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
956 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
957 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
|
958 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
|
959 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
960 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
|
961 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
|
962 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
|
963 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
|
964 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
|
965 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
|
966 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
|
967 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
968 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
969 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
970 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
|
971 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
|
972 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
|
973 After the collection, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
974 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
|
975 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
|
976 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
977 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
978 function gc_event (obj) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
979 local h = metatable(obj).__gc |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
980 if type(h) == "function" then |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
981 h(obj) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
982 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
983 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
984 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
985 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
986 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
987 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
|
988 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
|
989 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
|
990 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
|
991 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
|
992 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
|
993 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
|
994 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
|
995 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
996 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
997 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
998 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
|
999 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
|
1000 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
|
1001 Usually, this resurrection is transient, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1002 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
|
1003 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
|
1004 (e.g., a global variable), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1005 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
|
1006 In any case, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1007 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
|
1008 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
|
1009 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1010 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1011 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1012 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
|
1013 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
|
1014 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
|
1015 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
|
1016 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
|
1017 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1018 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1019 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1020 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1021 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1022 <h3>2.5.2 – <a name="2.5.2">Weak Tables</a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1023 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1024 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1025 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
|
1026 <em>weak references</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1027 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
|
1028 In other words, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1029 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
|
1030 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
|
1031 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1032 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1033 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1034 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
|
1035 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
|
1036 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
|
1037 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
|
1038 both keys and values. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1039 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
|
1040 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
|
1041 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
|
1042 <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
|
1043 If the <code>__mode</code> field is a string containing the character '<code>k</code>', |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1044 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
|
1045 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
|
1046 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
|
1047 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1048 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1049 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1050 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
|
1051 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
|
1052 In an ephemeron table, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1053 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
|
1054 In particular, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1055 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
|
1056 the pair is removed. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1057 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1058 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1059 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1060 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
|
1061 at the next collect cycle. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1062 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
|
1063 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
|
1064 before the change takes effect. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1065 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1066 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1067 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1068 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
|
1069 are removed from weak tables. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1070 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
|
1071 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
|
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 (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
|
1074 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
|
1075 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
|
1076 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
|
1077 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1078 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1079 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1080 Resurrected objects |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1081 (that is, objects being finalized |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1082 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
|
1083 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
|
1084 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
|
1085 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
|
1086 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
|
1087 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
|
1088 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
|
1089 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1090 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1091 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1092 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
|
1093 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
|
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 |
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1100 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1101 <h2>2.6 – <a name="2.6">Coroutines</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1102 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1103 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1104 Lua supports coroutines, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1105 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
|
1106 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
|
1107 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
|
1108 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
|
1109 a yield function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1110 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1111 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1112 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1113 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
|
1114 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
|
1115 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
|
1116 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
|
1117 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
|
1118 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
|
1119 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1120 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1121 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1122 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
|
1123 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
|
1124 passing as its first argument |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1125 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
|
1126 the coroutine starts its execution, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1127 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
|
1128 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
|
1129 to the coroutine main function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1130 After the coroutine starts running, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1131 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
|
1132 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1133 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1134 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1135 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
|
1136 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
|
1137 (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
|
1138 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
|
1139 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
|
1140 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
|
1141 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
|
1142 plus an error message. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1143 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1144 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1145 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1146 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
|
1147 When a coroutine yields, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1148 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
|
1149 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
|
1150 (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
|
1151 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
|
1152 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
|
1153 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
|
1154 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
|
1155 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
|
1156 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
|
1157 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
|
1158 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1159 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1160 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1161 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
|
1162 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
|
1163 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
|
1164 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
|
1165 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
|
1166 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
|
1167 <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
|
1168 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
|
1169 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
|
1170 <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
|
1171 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
|
1172 |
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1175 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
|
1176 consider the following code: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1177 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1178 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1179 function foo (a) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1180 print("foo", a) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1181 return coroutine.yield(2*a) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1182 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1183 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1184 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
|
1185 print("co-body", a, b) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1186 local r = foo(a+1) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1187 print("co-body", r) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1188 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
|
1189 print("co-body", r, s) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1190 return b, "end" |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1191 end) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1192 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1193 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
|
1194 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
|
1195 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
|
1196 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
|
1197 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1198 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
|
1199 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1200 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1201 co-body 1 10 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1202 foo 2 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1203 main true 4 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1204 co-body r |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1205 main true 11 -9 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1206 co-body x y |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1207 main true 10 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1208 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
|
1209 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1210 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1211 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1212 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
|
1213 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
|
1214 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
|
1215 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1216 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1217 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1218 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1219 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1220 <h1>3 – <a name="3">The Language</a></h1> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1221 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1222 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1223 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
|
1224 In other words, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1225 this section describes |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1226 which tokens are valid, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1227 how they can be combined, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1228 and what their combinations mean. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1229 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1230 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1231 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1232 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
|
1233 in which |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1234 {<em>a</em>} means 0 or more <em>a</em>'s, and |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1235 [<em>a</em>] means an optional <em>a</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1236 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
|
1237 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
|
1238 and other terminal symbols are shown like ‘<b>=</b>’. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1239 The complete syntax of Lua can be found in <a href="#9">§9</a> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1240 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
|
1241 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1242 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1243 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1244 <h2>3.1 – <a name="3.1">Lexical Conventions</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1245 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1246 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1247 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
|
1248 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
|
1249 between lexical elements (tokens), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1250 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
|
1251 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1252 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1253 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1254 <em>Names</em> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1255 (also called <em>identifiers</em>) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1256 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
|
1257 digits, and underscores, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1258 not beginning with a digit. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1259 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
|
1260 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1261 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1262 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1263 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
|
1264 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
|
1265 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1266 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1267 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1268 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
|
1269 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
|
1270 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
|
1271 then true until while |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1272 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1273 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1274 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1275 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
|
1276 <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
|
1277 are two different, valid names. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1278 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
|
1279 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
|
1280 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
|
1281 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1282 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1283 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1284 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
|
1285 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1286 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1287 + - * / % ^ # |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1288 == ~= <= >= < > = |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1289 ( ) { } [ ] :: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1290 ; : , . .. ... |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1291 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1292 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1293 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1294 <em>Literal strings</em> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1295 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
|
1296 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
|
1297 '<code>\a</code>' (bell), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1298 '<code>\b</code>' (backspace), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1299 '<code>\f</code>' (form feed), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1300 '<code>\n</code>' (newline), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1301 '<code>\r</code>' (carriage return), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1302 '<code>\t</code>' (horizontal tab), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1303 '<code>\v</code>' (vertical tab), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1304 '<code>\\</code>' (backslash), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1305 '<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
|
1306 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
|
1307 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
|
1308 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
|
1309 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
|
1310 of white-space characters, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1311 including line breaks; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1312 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
|
1313 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
|
1314 into the string contents. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1315 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1316 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1317 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1318 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
|
1319 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
|
1320 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
|
1321 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
|
1322 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
|
1323 (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
|
1324 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
|
1325 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
|
1326 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
|
1327 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1328 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1329 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1330 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
|
1331 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
|
1332 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
|
1333 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
|
1334 opening square bracket. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1335 So, an opening long bracket of level 0 is written as <code>[[</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1336 an opening long bracket of level 1 is written as <code>[=[</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1337 and so on. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1338 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
|
1339 for instance, a closing long bracket of level 4 is written as <code>]====]</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1340 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
|
1341 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
|
1342 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
|
1343 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
|
1344 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
|
1345 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
|
1346 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
|
1347 (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
|
1348 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
|
1349 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
|
1350 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1351 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1352 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1353 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
|
1354 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
|
1355 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
|
1356 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
|
1357 some control characters. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1358 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
|
1359 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
|
1360 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
|
1361 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1362 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1363 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1364 For convenience, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1365 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
|
1366 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
|
1367 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
|
1368 (in which '<code>a</code>' is coded as 97, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1369 newline is coded as 10, and '<code>1</code>' is coded as 49), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1370 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
|
1371 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1372 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1373 a = 'alo\n123"' |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1374 a = "alo\n123\"" |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1375 a = '\97lo\10\04923"' |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1376 a = [[alo |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1377 123"]] |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1378 a = [==[ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1379 alo |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1380 123"]==] |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1381 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1382 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1383 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1384 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
|
1385 and an optional decimal exponent, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1386 marked by a letter '<code>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
|
1387 Lua also accepts hexadecimal constants, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1388 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
|
1389 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
|
1390 plus an optional binary exponent, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1391 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
|
1392 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
|
1393 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1394 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1395 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
|
1396 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
|
1397 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1398 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1399 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1400 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
|
1401 anywhere outside a string. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1402 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
|
1403 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
|
1404 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
|
1405 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
|
1406 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
|
1407 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
|
1408 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1409 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1410 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1411 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1412 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1413 <h2>3.2 – <a name="3.2">Variables</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1414 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1415 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1416 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
|
1417 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
|
1418 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
|
1419 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1420 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1421 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1422 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
|
1423 (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
|
1424 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
|
1425 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1426 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1427 var ::= Name |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1428 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1429 Name denotes identifiers, as defined in <a href="#3.1">§3.1</a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1430 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1431 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1432 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1433 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
|
1434 as a local (see <a href="#3.3.7">§3.3.7</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1435 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
|
1436 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
|
1437 defined inside their scope (see <a href="#3.5">§3.5</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
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 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
|
1442 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1443 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1444 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1445 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
|
1446 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1447 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1448 var ::= prefixexp ‘<b>[</b>’ exp ‘<b>]</b>’ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1449 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1450 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
|
1451 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
|
1452 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
|
1453 (See <a href="#2.4">§2.4</a> for a complete description of the |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1454 <code>gettable_event</code> function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1455 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
|
1456 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
|
1457 |
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1460 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
|
1461 <code>var["Name"]</code>: |
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 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1464 var ::= prefixexp ‘<b>.</b>’ Name |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1465 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1466 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1467 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1468 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
|
1469 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
|
1470 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
|
1471 <code>_ENV</code> is never a global name (see <a href="#2.2">§2.2</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1472 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1473 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1474 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1475 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1476 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1477 <h2>3.3 – <a name="3.3">Statements</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1478 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1479 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1480 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
|
1481 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
|
1482 This set includes |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1483 assignments, control structures, function calls, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1484 and variable declarations. |
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1487 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1488 <h3>3.3.1 – <a name="3.3.1">Blocks</a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1489 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1490 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1491 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
|
1492 which are executed sequentially: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1493 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1494 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1495 block ::= {stat} |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1496 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1497 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
|
1498 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
|
1499 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
|
1500 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
|
1501 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1502 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1503 stat ::= ‘<b>;</b>’ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1504 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1505 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1506 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1507 Function calls and assignments |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1508 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
|
1509 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
|
1510 Consider the following fragment: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1511 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1512 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1513 a = b + c |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1514 (print or io.write)('done') |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1515 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1516 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
|
1517 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1518 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1519 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
|
1520 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1521 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
|
1522 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1523 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
|
1524 in the first way, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1525 interpreting the open parenthesis |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1526 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
|
1527 To avoid this ambiguity, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1528 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
|
1529 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
|
1530 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1531 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1532 ;(print or io.write)('done') |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1533 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1534 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1535 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1536 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
|
1537 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1538 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1539 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
|
1540 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1541 Explicit blocks are useful |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1542 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
|
1543 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
|
1544 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
|
1545 of another block (see <a href="#3.3.4">§3.3.4</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1546 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1547 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1548 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1549 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1550 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1551 <h3>3.3.2 – <a name="3.3.2">Chunks</a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1552 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1553 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1554 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
|
1555 Syntactically, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1556 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
|
1557 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1558 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1559 chunk ::= block |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1560 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1561 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1562 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1563 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
|
1564 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
|
1565 (see <a href="#3.4.10">§3.4.10</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1566 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
|
1567 receive arguments, and return values. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1568 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
|
1569 scope of an external local variable called <code>_ENV</code> (see <a href="#2.2">§2.2</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1570 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
|
1571 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
|
1572 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1573 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1574 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1575 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
|
1576 To execute a chunk, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1577 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
|
1578 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
|
1579 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
|
1580 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1581 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1582 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1583 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
|
1584 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
|
1585 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
|
1586 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
|
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 |
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1592 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1593 <h3>3.3.3 – <a name="3.3.3">Assignment</a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1594 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1595 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1596 Lua allows multiple assignments. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1597 Therefore, the syntax for assignment |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1598 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
|
1599 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
|
1600 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
|
1601 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1602 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1603 stat ::= varlist ‘<b>=</b>’ explist |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1604 varlist ::= var {‘<b>,</b>’ var} |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1605 explist ::= exp {‘<b>,</b>’ exp} |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1606 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1607 Expressions are discussed in <a href="#3.4">§3.4</a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1608 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1609 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1610 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1611 Before the assignment, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1612 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
|
1613 the list of variables. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1614 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
|
1615 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
|
1616 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
|
1617 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
|
1618 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
|
1619 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
|
1620 before the adjustment |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1621 (except when the call is enclosed in parentheses; see <a href="#3.4">§3.4</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1622 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1623 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1624 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1625 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
|
1626 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
|
1627 Thus the code |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1628 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1629 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1630 i = 3 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1631 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
|
1632 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1633 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
|
1634 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
|
1635 before it is assigned 4. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1636 Similarly, the line |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1637 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1638 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1639 x, y = y, x |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1640 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1641 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
|
1642 and |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1643 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1644 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1645 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
|
1646 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1647 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
|
1648 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1649 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1650 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1651 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
|
1652 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
|
1653 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
|
1654 <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
|
1655 (See <a href="#2.4">§2.4</a> for a complete description of the |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1656 <code>settable_event</code> function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1657 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
|
1658 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
|
1659 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1660 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1661 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1662 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
|
1663 is equivalent to the assignment |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1664 <code>_ENV.x = val</code> (see <a href="#2.2">§2.2</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1665 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1666 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1667 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1668 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1669 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1670 <h3>3.3.4 – <a name="3.3.4">Control Structures</a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1671 The control structures |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1672 <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
|
1673 familiar syntax: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1674 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1675 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1676 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1677 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1678 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1679 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
|
1680 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
|
1681 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
|
1682 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1683 Lua also has a <b>for</b> statement, in two flavors (see <a href="#3.3.5">§3.3.5</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1684 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1685 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1686 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1687 The condition expression of a |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1688 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
|
1689 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
|
1690 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
|
1691 (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
|
1692 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1693 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1694 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1695 In the <b>repeat</b>–<b>until</b> loop, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1696 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
|
1697 but only after the condition. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1698 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
|
1699 declared inside the loop block. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1700 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1701 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1702 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1703 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
|
1704 For syntactical reasons, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1705 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
|
1706 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1707 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1708 |
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 stat ::= <b>goto</b> Name |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1711 stat ::= label |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1712 label ::= ‘<b>::</b>’ Name ‘<b>::</b>’ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1713 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1714 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1715 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1716 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
|
1717 except |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1718 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
|
1719 inside nested functions. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1720 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
|
1721 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
|
1722 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1723 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1724 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1725 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
|
1726 as they perform no actions. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1727 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1728 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1729 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1730 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
|
1731 <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
|
1732 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
|
1733 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1734 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1735 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1736 stat ::= <b>break</b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1737 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1738 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
|
1739 |
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1742 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
|
1743 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
|
1744 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1745 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
|
1746 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
|
1747 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1748 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1749 stat ::= <b>return</b> [explist] [‘<b>;</b>’] |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1750 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1751 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1752 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1753 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
|
1754 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
|
1755 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
|
1756 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
|
1757 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
|
1758 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
|
1759 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1760 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1761 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1762 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1763 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1764 <h3>3.3.5 – <a name="3.3.5">For Statement</a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1765 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1766 <p> |
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 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
|
1769 one numeric and one generic. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1770 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1771 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1772 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1773 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
|
1774 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
|
1775 It has the following syntax: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1776 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1777 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1778 stat ::= <b>for</b> Name ‘<b>=</b>’ exp ‘<b>,</b>’ exp [‘<b>,</b>’ exp] <b>do</b> block <b>end</b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1779 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1780 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
|
1781 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
|
1782 third <em>exp</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1783 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
|
1784 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1785 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1786 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
|
1787 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1788 is equivalent to the code: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1789 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1790 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1791 do |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1792 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
|
1793 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
|
1794 while (<em>step</em> > 0 and <em>var</em> <= <em>limit</em>) or (<em>step</em> <= 0 and <em>var</em> >= <em>limit</em>) do |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1795 local v = <em>var</em> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1796 <em>block</em> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1797 <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
|
1798 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1799 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1800 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1801 Note the following: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1802 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1803 <ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1804 |
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 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
|
1807 before the loop starts. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1808 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
|
1809 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1810 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1811 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1812 <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
|
1813 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
|
1814 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1815 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1816 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1817 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
|
1818 then a step of 1 is used. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
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 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
|
1823 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1824 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1825 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1826 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
|
1827 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
|
1828 If you need this value, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1829 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
|
1830 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1831 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1832 </ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1833 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1834 <p> |
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> statement works over functions, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1836 called <em>iterators</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1837 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
|
1838 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
|
1839 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
|
1840 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1841 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1842 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
|
1843 namelist ::= Name {‘<b>,</b>’ Name} |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1844 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1845 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
|
1846 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1847 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1848 for <em>var_1</em>, ···, <em>var_n</em> in <em>explist</em> do <em>block</em> end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1849 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1850 is equivalent to the code: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1851 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1852 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1853 do |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1854 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
|
1855 while true do |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1856 local <em>var_1</em>, ···, <em>var_n</em> = <em>f</em>(<em>s</em>, <em>var</em>) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1857 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
|
1858 <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
|
1859 <em>block</em> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1860 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1861 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1862 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1863 Note the following: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1864 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1865 <ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1866 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1867 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1868 <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
|
1869 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
|
1870 a <em>state</em>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1871 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
|
1872 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1873 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1874 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1875 <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
|
1876 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
|
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 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
|
1881 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1882 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1883 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1884 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
|
1885 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
|
1886 If you need these values, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1887 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
|
1888 </li> |
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 </ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1891 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1892 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1893 |
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 <h3>3.3.6 – <a name="3.3.6">Function Calls as Statements</a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1896 To allow possible side-effects, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1897 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
|
1898 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1899 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1900 stat ::= functioncall |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1901 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1902 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
|
1903 Function calls are explained in <a href="#3.4.9">§3.4.9</a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1904 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1905 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1906 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1907 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1908 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1909 <h3>3.3.7 – <a name="3.3.7">Local Declarations</a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1910 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
|
1911 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
|
1912 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1913 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1914 stat ::= <b>local</b> namelist [‘<b>=</b>’ explist] |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1915 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1916 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
|
1917 of a multiple assignment (see <a href="#3.3.3">§3.3.3</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1918 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
|
1919 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1920 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1921 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1922 A chunk is also a block (see <a href="#3.3.2">§3.3.2</a>), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1923 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
|
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1927 The visibility rules for local variables are explained in <a href="#3.5">§3.5</a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
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 |
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1934 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1935 <h2>3.4 – <a name="3.4">Expressions</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1936 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1937 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1938 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
|
1939 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1940 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1941 exp ::= prefixexp |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1942 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
|
1943 exp ::= Number |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1944 exp ::= String |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1945 exp ::= functiondef |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1946 exp ::= tableconstructor |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1947 exp ::= ‘<b>...</b>’ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1948 exp ::= exp binop exp |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1949 exp ::= unop exp |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1950 prefixexp ::= var | functioncall | ‘<b>(</b>’ exp ‘<b>)</b>’ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1951 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1952 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1953 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1954 Numbers and literal strings are explained in <a href="#3.1">§3.1</a>; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1955 variables are explained in <a href="#3.2">§3.2</a>; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1956 function definitions are explained in <a href="#3.4.10">§3.4.10</a>; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1957 function calls are explained in <a href="#3.4.9">§3.4.9</a>; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1958 table constructors are explained in <a href="#3.4.8">§3.4.8</a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1959 Vararg expressions, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1960 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
|
1961 directly inside a vararg function; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1962 they are explained in <a href="#3.4.10">§3.4.10</a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1963 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1964 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1965 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1966 Binary operators comprise arithmetic operators (see <a href="#3.4.1">§3.4.1</a>), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1967 relational operators (see <a href="#3.4.3">§3.4.3</a>), logical operators (see <a href="#3.4.4">§3.4.4</a>), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1968 and the concatenation operator (see <a href="#3.4.5">§3.4.5</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1969 Unary operators comprise the unary minus (see <a href="#3.4.1">§3.4.1</a>), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1970 the unary <b>not</b> (see <a href="#3.4.4">§3.4.4</a>), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1971 and the unary <em>length operator</em> (see <a href="#3.4.6">§3.4.6</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1972 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1973 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1974 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1975 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
|
1976 If a function call is used as a statement (see <a href="#3.3.6">§3.3.6</a>), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1977 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
|
1978 thus discarding all returned values. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1979 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
|
1980 of a list of expressions, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1981 then no adjustment is made |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1982 (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
|
1983 In all other contexts, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1984 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
|
1985 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
|
1986 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
|
1987 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1988 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1989 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1990 Here are some examples: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1991 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1992 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1993 f() -- adjusted to 0 results |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1994 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
|
1995 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
|
1996 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
|
1997 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
|
1998 -- 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
|
1999 -- is no corresponding vararg parameter) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2000 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2001 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
|
2002 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
|
2003 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
|
2004 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
|
2005 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
|
2006 {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
|
2007 {...} -- 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
|
2008 {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
|
2009 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2010 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2011 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2012 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
|
2013 Thus, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2014 <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
|
2015 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
|
2016 (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
|
2017 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
|
2018 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2019 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2020 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2021 <h3>3.4.1 – <a name="3.4.1">Arithmetic Operators</a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2022 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
|
2023 the binary <code>+</code> (addition), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2024 <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
|
2025 <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
|
2026 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
|
2027 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
|
2028 numbers (see <a href="#3.4.2">§3.4.2</a>), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2029 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
|
2030 Exponentiation works for any exponent. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2031 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
|
2032 Modulo is defined as |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2033 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2034 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2035 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
|
2036 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2037 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
|
2038 the quotient towards minus infinity. |
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2041 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2042 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2043 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2044 <h3>3.4.2 – <a name="3.4.2">Coercion</a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2045 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2046 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2047 Lua provides automatic conversion between |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2048 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
|
2049 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
|
2050 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
|
2051 (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
|
2052 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
|
2053 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
|
2054 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
|
2055 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
|
2056 (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
|
2057 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2058 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2059 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2060 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2061 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2062 <h3>3.4.3 – <a name="3.4.3">Relational Operators</a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2063 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
|
2064 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2065 <pre> |
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 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2068 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
|
2069 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2070 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2071 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2072 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
|
2073 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
|
2074 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
|
2075 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
|
2076 Tables, userdata, and threads |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2077 are compared by reference: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2078 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
|
2079 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
|
2080 (a table, userdata, or thread), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2081 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
|
2082 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
|
2083 Closures with any detectable difference |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2084 (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
|
2085 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2086 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2087 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2088 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
|
2089 by using the "eq" metamethod (see <a href="#2.4">§2.4</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2090 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2091 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2092 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2093 The conversion rules of <a href="#3.4.2">§3.4.2</a> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2094 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
|
2095 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
|
2096 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
|
2097 entries in a table. |
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 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
|
2102 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2103 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2104 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2105 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
|
2106 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
|
2107 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
|
2108 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
|
2109 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
|
2110 metamethod (see <a href="#2.4">§2.4</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2111 A comparison <code>a > b</code> is translated to <code>b < a</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2112 and <code>a >= b</code> is translated to <code>b <= a</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2113 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2114 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2115 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2116 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2117 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2118 <h3>3.4.4 – <a name="3.4.4">Logical Operators</a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2119 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
|
2120 <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
|
2121 Like the control structures (see <a href="#3.3.4">§3.3.4</a>), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2122 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
|
2123 and anything else as true. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2124 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2125 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2126 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2127 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
|
2128 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
|
2129 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
|
2130 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
|
2131 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
|
2132 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
|
2133 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
|
2134 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
|
2135 that is, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2136 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
|
2137 Here are some examples: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2138 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2139 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2140 10 or 20 --> 10 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2141 10 or error() --> 10 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2142 nil or "a" --> "a" |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2143 nil and 10 --> nil |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2144 false and error() --> false |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2145 false and nil --> false |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2146 false or nil --> nil |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2147 10 and 20 --> 20 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2148 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2149 (In this manual, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2150 <code>--></code> indicates the result of the preceding expression.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2151 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2152 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2153 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2154 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2155 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2156 <h3>3.4.5 – <a name="3.4.5">Concatenation</a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2157 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
|
2158 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
|
2159 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
|
2160 strings according to the rules mentioned in <a href="#3.4.2">§3.4.2</a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2161 Otherwise, the <code>__concat</code> metamethod is called (see <a href="#2.4">§2.4</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2162 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2163 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2164 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2165 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2166 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2167 <h3>3.4.6 – <a name="3.4.6">The Length Operator</a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2168 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2169 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2170 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
|
2171 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
|
2172 (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
|
2173 character is one byte). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2174 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2175 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2176 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2177 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
|
2178 any value but strings through the <code>__len</code> metamethod (see <a href="#2.4">§2.4</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2179 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2180 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2181 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2182 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
|
2183 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
|
2184 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
|
2185 that is, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2186 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
|
2187 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
|
2188 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
|
2189 Note that a table like |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2190 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2191 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2192 {10, 20, nil, 40} |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2193 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2194 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
|
2195 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
|
2196 (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
|
2197 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
|
2198 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
|
2199 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
|
2200 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2201 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2202 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2203 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2204 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2205 <h3>3.4.7 – <a name="3.4.7">Precedence</a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2206 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
|
2207 from lower to higher priority: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2208 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2209 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2210 or |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2211 and |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2212 < > <= >= ~= == |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2213 .. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2214 + - |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2215 * / % |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2216 not # - (unary) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2217 ^ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2218 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2219 As usual, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2220 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
|
2221 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
|
2222 operators are right associative. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2223 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
|
2224 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2225 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2226 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2227 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2228 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2229 <h3>3.4.8 – <a name="3.4.8">Table Constructors</a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2230 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
|
2231 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
|
2232 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
|
2233 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
|
2234 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
|
2235 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2236 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2237 tableconstructor ::= ‘<b>{</b>’ [fieldlist] ‘<b>}</b>’ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2238 fieldlist ::= field {fieldsep field} [fieldsep] |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2239 field ::= ‘<b>[</b>’ exp ‘<b>]</b>’ ‘<b>=</b>’ exp | Name ‘<b>=</b>’ exp | exp |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2240 fieldsep ::= ‘<b>,</b>’ | ‘<b>;</b>’ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2241 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2242 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2243 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2244 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
|
2245 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
|
2246 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
|
2247 <code>["name"] = exp</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2248 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
|
2249 <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
|
2250 starting with 1. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2251 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
|
2252 For example, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2253 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2254 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2255 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
|
2256 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2257 is equivalent to |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2258 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2259 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2260 do |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2261 local t = {} |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2262 t[f(1)] = g |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2263 t[1] = "x" -- 1st exp |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2264 t[2] = "y" -- 2nd exp |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2265 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
|
2266 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
|
2267 t[30] = 23 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2268 t[4] = 45 -- 4th exp |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2269 a = t |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2270 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2271 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2272 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2273 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2274 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
|
2275 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
|
2276 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
|
2277 (see <a href="#3.4.9">§3.4.9</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2278 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2279 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2280 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2281 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
|
2282 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
|
2283 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2284 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2285 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2286 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2287 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2288 <h3>3.4.9 – <a name="3.4.9">Function Calls</a></h3><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2289 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
|
2290 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2291 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2292 functioncall ::= prefixexp args |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2293 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2294 In a function call, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2295 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
|
2296 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
|
2297 then this function is called |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2298 with the given arguments. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2299 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
|
2300 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
|
2301 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
|
2302 (see <a href="#2.4">§2.4</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2303 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2304 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2305 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2306 The form |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2307 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2308 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2309 functioncall ::= prefixexp ‘<b>:</b>’ Name args |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2310 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2311 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
|
2312 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
|
2313 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
|
2314 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
|
2315 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2316 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2317 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2318 Arguments have the following syntax: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2319 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2320 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2321 args ::= ‘<b>(</b>’ [explist] ‘<b>)</b>’ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2322 args ::= tableconstructor |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2323 args ::= String |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2324 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2325 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
|
2326 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
|
2327 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
|
2328 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
|
2329 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
|
2330 (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
|
2331 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
|
2332 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
|
2333 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2334 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2335 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2336 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
|
2337 a <em>tail call</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2338 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
|
2339 (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
|
2340 in a tail call, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2341 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
|
2342 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
|
2343 a program can execute. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2344 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
|
2345 calling function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2346 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
|
2347 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
|
2348 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
|
2349 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
|
2350 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
|
2351 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2352 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2353 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
|
2354 return 2 * f(x) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2355 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
|
2356 f(x); return -- results discarded |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2357 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
|
2358 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2359 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2360 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2361 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2362 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2363 <h3>3.4.10 – <a name="3.4.10">Function Definitions</a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2364 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2365 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2366 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
|
2367 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2368 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2369 functiondef ::= <b>function</b> funcbody |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2370 funcbody ::= ‘<b>(</b>’ [parlist] ‘<b>)</b>’ block <b>end</b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2371 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2372 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2373 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2374 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
|
2375 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2376 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2377 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
|
2378 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
|
2379 funcname ::= Name {‘<b>.</b>’ Name} [‘<b>:</b>’ Name] |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2380 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2381 The statement |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2382 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2383 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2384 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
|
2385 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2386 translates to |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2387 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2388 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2389 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
|
2390 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2391 The statement |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2392 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2393 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2394 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
|
2395 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2396 translates to |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2397 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2398 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2399 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
|
2400 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2401 The statement |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2402 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2403 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2404 local 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
|
2405 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2406 translates to |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2407 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2408 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2409 local f; f = function () <em>body</em> end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2410 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2411 not to |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2412 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2413 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2414 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
|
2415 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2416 (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
|
2417 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
|
2418 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2419 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2420 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2421 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
|
2422 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
|
2423 When Lua precompiles a chunk, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2424 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
|
2425 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
|
2426 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
|
2427 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
|
2428 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
|
2429 |
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2432 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
|
2433 initialized with the argument values: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2434 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2435 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2436 parlist ::= namelist [‘<b>,</b>’ ‘<b>...</b>’] | ‘<b>...</b>’ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2437 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2438 When a function is called, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2439 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
|
2440 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
|
2441 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
|
2442 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
|
2443 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
|
2444 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
|
2445 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
|
2446 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
|
2447 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
|
2448 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
|
2449 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
|
2450 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
|
2451 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
|
2452 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
|
2453 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
|
2454 then no adjustment is made |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2455 (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
|
2456 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2457 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2458 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2459 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
|
2460 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2461 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2462 function f(a, b) end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2463 function g(a, b, ...) end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2464 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
|
2465 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2466 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
|
2467 to the vararg expression: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2468 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2469 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2470 CALL PARAMETERS |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2471 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2472 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
|
2473 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
|
2474 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
|
2475 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
|
2476 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
|
2477 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2478 g(3) a=3, b=nil, ... --> (nothing) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2479 g(3, 4) a=3, b=4, ... --> (nothing) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2480 g(3, 4, 5, 8) a=3, b=4, ... --> 5 8 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2481 g(5, r()) a=5, b=1, ... --> 2 3 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2482 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2483 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2484 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2485 Results are returned using the <b>return</b> statement (see <a href="#3.3.4">§3.3.4</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2486 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
|
2487 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
|
2488 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
|
2489 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2490 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2491 <p> |
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 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
|
2494 that a function may return. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2495 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
|
2496 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2497 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2498 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2499 The <em>colon</em> syntax |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2500 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
|
2501 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
|
2502 Thus, the statement |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2503 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2504 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2505 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
|
2506 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2507 is syntactic sugar for |
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 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2510 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
|
2511 </pre> |
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 |
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 |
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 <h2>3.5 – <a name="3.5">Visibility Rules</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2519 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2520 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2521 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2522 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
|
2523 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
|
2524 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
|
2525 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
|
2526 Consider the following example: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2527 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2528 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2529 x = 10 -- global variable |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2530 do -- new block |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2531 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
|
2532 print(x) --> 10 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2533 x = x+1 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2534 do -- another block |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2535 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
|
2536 print(x) --> 12 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2537 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2538 print(x) --> 11 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2539 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2540 print(x) --> 10 (the global one) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2541 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2542 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2543 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2544 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
|
2545 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
|
2546 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
|
2547 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2548 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2549 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2550 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
|
2551 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
|
2552 defined inside their scope. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2553 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
|
2554 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
|
2555 inside the inner function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2556 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2557 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2558 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2559 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
|
2560 defines new local variables. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2561 Consider the following example: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2562 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2563 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2564 a = {} |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2565 local x = 20 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2566 for i=1,10 do |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2567 local y = 0 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2568 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
|
2569 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2570 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2571 The loop creates ten closures |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2572 (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
|
2573 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
|
2574 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
|
2575 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2576 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2577 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2578 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2579 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2580 <h1>4 – <a name="4">The Application Program Interface</a></h1> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2581 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2582 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2583 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2584 This section describes the C API for Lua, that is, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2585 the set of C functions available to the host program to communicate |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2586 with Lua. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2587 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
|
2588 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
|
2589 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2590 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2591 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2592 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
|
2593 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
|
2594 Except where stated otherwise, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2595 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
|
2596 (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
|
2597 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
|
2598 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2599 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2600 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2601 As in most C libraries, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2602 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
|
2603 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
|
2604 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
|
2605 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2606 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2607 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2608 <h2>4.1 – <a name="4.1">The Stack</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2609 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2610 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2611 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
|
2612 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
|
2613 (<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
|
2614 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2615 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2616 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2617 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
|
2618 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
|
2619 C functions that are still active. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2620 This stack initially contains any arguments to the C function |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2621 and it is where the C function pushes its results |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2622 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
|
2623 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2624 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2625 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2626 For convenience, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2627 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
|
2628 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
|
2629 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
|
2630 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
|
2631 (starting at 1); |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2632 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
|
2633 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
|
2634 then index 1 represents the first element |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2635 (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
|
2636 and |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2637 index <em>n</em> represents the last element; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2638 index -1 also represents the last element |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2639 (that is, the element at the top) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2640 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
|
2641 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2642 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2643 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2644 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2645 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2646 <h2>4.2 – <a name="4.2">Stack Size</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2647 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2648 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2649 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
|
2650 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
|
2651 In particular, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2652 <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
|
2653 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
|
2654 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
|
2655 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2656 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2657 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2658 Whenever Lua calls C, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2659 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
|
2660 <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
|
2661 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
|
2662 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
|
2663 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2664 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2665 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2666 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
|
2667 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
|
2668 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
|
2669 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
|
2670 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
|
2671 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
|
2672 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2673 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2674 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2675 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2676 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2677 <h2>4.3 – <a name="4.3">Valid and Acceptable Indices</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2678 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2679 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2680 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
|
2681 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
|
2682 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2683 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2684 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2685 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
|
2686 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
|
2687 its position lies between 1 and the stack top |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2688 (<code>1 ≤ abs(index) ≤ top</code>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2689 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2690 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
|
2691 require valid indices. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2692 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2693 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2694 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2695 Unless otherwise noted, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2696 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
|
2697 which represent some Lua values that are accessible to C code |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2698 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
|
2699 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
|
2700 and the upvalues of a C function (see <a href="#4.4">§4.4</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2701 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2702 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2703 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2704 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
|
2705 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
|
2706 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
|
2707 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
|
2708 including the pseudo-indices, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2709 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
|
2710 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
|
2711 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
|
2712 (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
|
2713 Except when noted otherwise, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2714 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
|
2715 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2716 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2717 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2718 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
|
2719 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
|
2720 For instance, a C function can query its third argument |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2721 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
|
2722 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
|
2723 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2724 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2725 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2726 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
|
2727 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
|
2728 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
|
2729 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
|
2730 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2731 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2732 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2733 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2734 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2735 <h2>4.4 – <a name="4.4">C Closures</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2736 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2737 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2738 When a C function is created, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2739 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
|
2740 thus creating a <em>C closure</em> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2741 (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
|
2742 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
|
2743 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
|
2744 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2745 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2746 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2747 Whenever a C function is called, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2748 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
|
2749 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
|
2750 <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
|
2751 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
|
2752 <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
|
2753 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
|
2754 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
|
2755 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
|
2756 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
|
2757 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2758 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2759 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2760 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2761 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2762 <h2>4.5 – <a name="4.5">Registry</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2763 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2764 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2765 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
|
2766 a predefined table that can be used by any C code to |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2767 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
|
2768 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
|
2769 <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
|
2770 which is a valid index. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2771 Any C library can store data into this table, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2772 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
|
2773 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
|
2774 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
|
2775 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
|
2776 or a light userdata with the address of a C object in your code, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2777 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
|
2778 As with global names, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2779 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
|
2780 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
|
2781 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2782 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2783 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2784 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
|
2785 implemented by the auxiliary library, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2786 and by some predefined values. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2787 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
|
2788 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2789 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2790 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2791 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
|
2792 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
|
2793 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
|
2794 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
|
2795 The following constants are defined: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2796 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2797 <ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2798 <li><b><a name="pdf-LUA_RIDX_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
|
2799 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
|
2800 (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
|
2801 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2802 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2803 <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
|
2804 the global environment. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2805 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2806 </ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2807 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2808 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2809 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2810 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2811 <h2>4.6 – <a name="4.6">Error Handling in C</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2812 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2813 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2814 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
|
2815 (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
|
2816 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
|
2817 When Lua faces any error |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2818 (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
|
2819 and runtime errors) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2820 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
|
2821 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
|
2822 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
|
2823 to set a recovery point; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2824 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
|
2825 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2826 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2827 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2828 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
|
2829 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
|
2830 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
|
2831 thus exiting the host application. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2832 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
|
2833 never returning |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2834 (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
|
2835 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2836 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2837 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2838 The panic function runs as if it were a message handler (see <a href="#2.3">§2.3</a>); |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2839 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
|
2840 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
|
2841 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
|
2842 the panic function should first check the available space (see <a href="#4.2">§4.2</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2843 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2844 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2845 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2846 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
|
2847 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
|
2848 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
|
2849 it can throw errors. |
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2853 Inside a C function you can throw an error by calling <a href="#lua_error"><code>lua_error</code></a>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2854 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2855 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2856 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2857 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2858 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2859 <h2>4.7 – <a name="4.7">Handling Yields in C</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2860 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2861 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2862 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
|
2863 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
|
2864 and this API function yields |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2865 (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
|
2866 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
|
2867 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
|
2868 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2869 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2870 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2871 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
|
2872 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
|
2873 except for three functions: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2874 <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
|
2875 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
|
2876 (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
|
2877 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2878 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2879 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2880 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
|
2881 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
|
2882 the <em>original function</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2883 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
|
2884 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
|
2885 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
|
2886 (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
|
2887 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
|
2888 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
|
2889 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2890 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2891 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2892 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
|
2893 After the thread resumes, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2894 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
|
2895 However, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2896 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
|
2897 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
|
2898 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
|
2899 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
|
2900 As the name implies, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2901 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
|
2902 of the original function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2903 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2904 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2905 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2906 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
|
2907 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
|
2908 from the original function, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2909 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
|
2910 (For instance, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2911 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
|
2912 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
|
2913 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
|
2914 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
|
2915 of the original function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2916 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2917 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2918 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2919 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
|
2920 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
|
2921 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2922 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2923 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2924 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2925 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2926 <h2>4.8 – <a name="4.8">Functions and Types</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2927 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2928 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2929 Here we list all functions and types from the C API in |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2930 alphabetical order. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2931 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
|
2932 <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
|
2933 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2934 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2935 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2936 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
|
2937 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
|
2938 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
|
2939 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
|
2940 (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
|
2941 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
|
2942 <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
|
2943 depending on the situation; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2944 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
|
2945 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
|
2946 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
|
2947 (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
|
2948 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
|
2949 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
|
2950 '<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
|
2951 '<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
|
2952 '<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
|
2953 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2954 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2955 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2956 <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
|
2957 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2958 <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
|
2959 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2960 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2961 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
|
2962 (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
|
2963 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2964 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2965 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2966 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2967 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2968 <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
|
2969 <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
|
2970 void *ptr, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2971 size_t osize, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2972 size_t nsize);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2973 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2974 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2975 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
|
2976 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
|
2977 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
|
2978 but not exactly the same. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2979 Its arguments are |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2980 <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
|
2981 <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
|
2982 <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
|
2983 is being allocated; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2984 <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
|
2985 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2986 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2987 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2988 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
|
2989 <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
|
2990 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
|
2991 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2992 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2993 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2994 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
|
2995 <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
|
2996 <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
|
2997 <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
|
2998 <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
|
2999 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
|
3000 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
|
3001 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
|
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 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
|
3006 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3007 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3008 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3009 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
|
3010 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
|
3011 and return <code>NULL</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3012 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3013 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3014 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3015 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
|
3016 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
|
3017 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
|
3018 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
|
3019 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
|
3020 <code>osize >= nsize</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3021 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3022 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3023 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3024 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
|
3025 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
|
3026 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3027 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3028 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
|
3029 size_t nsize) { |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3030 (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
|
3031 if (nsize == 0) { |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3032 free(ptr); |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3033 return NULL; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3034 } |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3035 else |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3036 return realloc(ptr, nsize); |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3037 } |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3038 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3039 Note that Standard C ensures |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3040 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
|
3041 <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
|
3042 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
|
3043 (Although Standard C does not ensure this behavior, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3044 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
|
3045 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3046 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3047 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3048 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3049 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3050 <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
|
3051 <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
|
3052 <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
|
3053 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3054 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3055 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
|
3056 (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
|
3057 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
|
3058 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
|
3059 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
|
3060 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
|
3061 (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
|
3062 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3063 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3064 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3065 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
|
3066 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3067 <ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3068 |
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_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
|
3070 <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
|
3071 <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
|
3072 <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
|
3073 <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
|
3074 <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
|
3075 <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
|
3076 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3077 </ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3078 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3079 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3080 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3081 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3082 <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
|
3083 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3084 <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
|
3085 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3086 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3087 Sets a new panic function and returns the old one (see <a href="#4.6">§4.6</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3088 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3089 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3090 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3091 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3092 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3093 <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
|
3094 <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
|
3095 <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
|
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 Calls a function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3099 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3100 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3101 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3102 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
|
3103 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
|
3104 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
|
3105 in direct order; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3106 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
|
3107 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
|
3108 <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
|
3109 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
|
3110 when the function is called. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3111 The function results are pushed onto the stack when the function returns. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3112 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
|
3113 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
|
3114 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
|
3115 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
|
3116 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
|
3117 (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
|
3118 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
|
3119 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3120 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3121 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3122 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
|
3123 (with a <code>longjmp</code>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3124 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3125 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3126 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3127 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
|
3128 equivalent to this Lua code: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3129 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3130 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3131 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
|
3132 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3133 Here it is in C: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3134 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3135 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3136 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
|
3137 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
|
3138 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
|
3139 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
|
3140 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
|
3141 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
|
3142 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
|
3143 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
|
3144 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3145 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
|
3146 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
|
3147 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
|
3148 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3149 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3150 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3151 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3152 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3153 <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
|
3154 <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
|
3155 <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
|
3156 lua_CFunction k);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3157 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3158 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3159 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
|
3160 but allows the called function to yield (see <a href="#4.7">§4.7</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3161 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3162 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3163 |
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3166 <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
|
3167 <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
|
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 Type for C functions. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3171 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3172 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3173 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3174 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
|
3175 a C function must use the following protocol, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3176 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
|
3177 a C function receives its arguments from Lua in its stack |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3178 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
|
3179 So, when the function starts, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3180 <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
|
3181 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
|
3182 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
|
3183 To return values to Lua, a C function just pushes them onto the stack, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3184 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
|
3185 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
|
3186 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
|
3187 discarded by Lua. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3188 Like a Lua function, a C function called by Lua can also return |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3189 many results. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3190 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3191 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3192 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3193 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
|
3194 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
|
3195 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3196 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3197 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
|
3198 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
|
3199 lua_Number sum = 0; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3200 int i; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3201 for (i = 1; i <= n; i++) { |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3202 if (!lua_isnumber(L, i)) { |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3203 lua_pushstring(L, "incorrect argument"); |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3204 lua_error(L); |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3205 } |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3206 sum += lua_tonumber(L, i); |
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 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
|
3209 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
|
3210 return 2; /* number of results */ |
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 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3213 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3214 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3215 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3216 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3217 <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
|
3218 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3219 <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
|
3220 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3221 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3222 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
|
3223 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
|
3224 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
|
3225 (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
|
3226 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
|
3227 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
|
3228 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
|
3229 it is left unchanged. |
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3232 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3233 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3234 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3235 <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
|
3236 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3237 <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
|
3238 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3239 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3240 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
|
3241 (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
|
3242 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
|
3243 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
|
3244 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
|
3245 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
|
3246 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
|
3247 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
|
3248 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3249 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3250 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3251 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3252 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3253 <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
|
3254 <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
|
3255 <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
|
3256 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3257 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3258 Compares two Lua values. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3259 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
|
3260 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
|
3261 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
|
3262 (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
|
3263 Otherwise returns 0. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3264 Also returns 0 if any of the indices is non valid. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3265 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3266 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3267 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3268 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
|
3269 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3270 <ul> |
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 <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
|
3273 <li><b><a name="pdf-LUA_OPLT"><code>LUA_OPLT</code></a>: </b> compares for less than (<code><</code>)</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3274 <li><b><a name="pdf-LUA_OPLE"><code>LUA_OPLE</code></a>: </b> compares for less or equal (<code><=</code>)</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3275 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3276 </ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3277 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3278 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3279 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3280 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3281 <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
|
3282 <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
|
3283 <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
|
3284 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3285 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3286 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
|
3287 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
|
3288 If <code>n</code> is 1, the result is the single value on the stack |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3289 (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
|
3290 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
|
3291 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
|
3292 (see <a href="#3.4.5">§3.4.5</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3293 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3294 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3295 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3296 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3297 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3298 <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
|
3299 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3300 <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
|
3301 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3302 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3303 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
|
3304 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
|
3305 without shifting any element |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3306 (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
|
3307 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3308 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3309 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3310 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3311 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3312 <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
|
3313 <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
|
3314 <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
|
3315 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3316 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3317 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
|
3318 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
|
3319 will have as a sequence; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3320 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
|
3321 the table will have. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3322 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
|
3323 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
|
3324 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
|
3325 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
|
3326 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3327 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3328 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3329 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3330 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3331 <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
|
3332 <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
|
3333 <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
|
3334 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3335 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3336 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
|
3337 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
|
3338 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
|
3339 if loaded again, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3340 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
|
3341 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
|
3342 <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
|
3343 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
|
3344 to write them. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3345 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3346 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3347 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3348 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
|
3349 call to the writer; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3350 0 means no errors. |
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3354 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
|
3355 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3356 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3357 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3358 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3359 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3360 <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
|
3361 <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
|
3362 <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
|
3363 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3364 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3365 Generates a Lua error. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3366 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
|
3367 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
|
3368 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
|
3369 and therefore never returns |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3370 (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
|
3371 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3372 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3373 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3374 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3375 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3376 <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
|
3377 <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
|
3378 <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
|
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 Controls the garbage collector. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3382 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3383 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3384 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3385 This function performs several tasks, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3386 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
|
3387 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3388 <ul> |
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_GCSTOP</code>: </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3391 stops 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_GCRESTART</code>: </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3395 restarts the garbage collector. |
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_GCCOLLECT</code>: </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3399 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
|
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_GCCOUNT</code>: </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3403 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
|
3404 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3405 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3406 <li><b><code>LUA_GCCOUNTB</code>: </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3407 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
|
3408 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
|
3409 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3410 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3411 <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
|
3412 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
|
3413 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
|
3414 (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
|
3415 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
|
3416 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
|
3417 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
|
3418 garbage-collection cycle. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3419 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3420 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3421 <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
|
3422 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
|
3423 for the <em>pause</em> of the collector (see <a href="#2.5">§2.5</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3424 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
|
3425 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3426 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3427 <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
|
3428 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
|
3429 the collector (see <a href="#2.5">§2.5</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3430 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
|
3431 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3432 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3433 <li><b><code>LUA_GCISRUNNING</code>: </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3434 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
|
3435 (i.e., not stopped). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3436 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3437 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3438 <li><b><code>LUA_GCGEN</code>: </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3439 changes the collector to generational mode |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3440 (see <a href="#2.5">§2.5</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3441 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3442 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3443 <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
|
3444 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
|
3445 This is the default mode. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3446 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3447 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3448 </ul> |
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3451 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
|
3452 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
|
3453 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3454 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3455 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3456 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3457 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3458 <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
|
3459 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3460 <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
|
3461 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3462 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3463 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
|
3464 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
|
3465 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
|
3466 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3467 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3468 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3469 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3470 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3471 <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
|
3472 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3473 <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
|
3474 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3475 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3476 This function is called by a continuation function (see <a href="#4.7">§4.7</a>) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3477 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
|
3478 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3479 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3480 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3481 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
|
3482 <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
|
3483 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
|
3484 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
|
3485 <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
|
3486 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
|
3487 (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
|
3488 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
|
3489 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3490 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3491 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3492 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
|
3493 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
|
3494 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
|
3495 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
|
3496 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
|
3497 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
|
3498 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
|
3499 (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
|
3500 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
|
3501 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
|
3502 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3503 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3504 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3505 |
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 <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
|
3508 <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
|
3509 <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
|
3510 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3511 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3512 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
|
3513 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
|
3514 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
|
3515 for the "index" event (see <a href="#2.4">§2.4</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3516 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3517 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3518 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3519 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3520 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3521 <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
|
3522 <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
|
3523 <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
|
3524 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3525 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3526 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
|
3527 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3528 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3529 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3530 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3531 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3532 <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
|
3533 <span class="apii">[-0, +(0|1), –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3534 <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
|
3535 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3536 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3537 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
|
3538 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
|
3539 the function returns 0 and pushes nothing on the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3540 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3541 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3542 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3543 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3544 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3545 <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
|
3546 <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
|
3547 <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
|
3548 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3549 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3550 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
|
3551 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
|
3552 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
|
3553 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3554 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3555 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3556 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
|
3557 (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
|
3558 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
|
3559 for the "index" event (see <a href="#2.4">§2.4</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3560 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3561 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3562 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3563 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3564 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3565 <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
|
3566 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3567 <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
|
3568 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3569 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3570 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
|
3571 Because indices start at 1, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3572 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
|
3573 (and so 0 means an empty stack). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3574 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3575 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3576 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3577 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3578 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3579 <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
|
3580 <span class="apii">[-0, +1, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3581 <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
|
3582 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3583 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3584 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
|
3585 at the given index. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3586 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
|
3587 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3588 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3589 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3590 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3591 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3592 <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
|
3593 <span class="apii">[-1, +1, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3594 <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
|
3595 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3596 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3597 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
|
3598 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
|
3599 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
|
3600 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
|
3601 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3602 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3603 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3604 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3605 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3606 <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
|
3607 <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
|
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 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
|
3611 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3612 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3613 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3614 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
|
3615 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
|
3616 "comfortably". |
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3619 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3620 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3621 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3622 <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
|
3623 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3624 <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
|
3625 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3626 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3627 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
|
3628 and 0 otherwise. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3629 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3630 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3631 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3632 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3633 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3634 <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
|
3635 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3636 <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
|
3637 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3638 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3639 Returns 1 if the value at the given index is a C function, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3640 and 0 otherwise. |
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3643 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3644 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3645 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3646 <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
|
3647 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3648 <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
|
3649 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3650 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3651 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
|
3652 (either C or Lua), and 0 otherwise. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3653 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3654 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3655 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3656 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3657 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3658 <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
|
3659 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3660 <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
|
3661 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3662 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3663 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
|
3664 and 0 otherwise. |
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3667 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3668 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3669 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3670 <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
|
3671 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3672 <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
|
3673 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3674 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3675 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
|
3676 and 0 otherwise. |
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3679 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3680 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3681 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3682 <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
|
3683 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3684 <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
|
3685 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3686 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3687 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
|
3688 and 0 otherwise. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3689 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3690 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3691 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3692 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3693 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3694 <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
|
3695 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3696 <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
|
3697 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3698 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3699 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
|
3700 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
|
3701 and 0 otherwise. |
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3704 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3705 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3706 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3707 <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
|
3708 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3709 <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
|
3710 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3711 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3712 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
|
3713 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
|
3714 and 0 otherwise. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3715 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3716 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3717 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3718 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3719 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3720 <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
|
3721 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3722 <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
|
3723 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3724 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3725 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
|
3726 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
|
3727 and 0 otherwise. |
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3730 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3731 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3732 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3733 <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
|
3734 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3735 <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
|
3736 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3737 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3738 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
|
3739 and 0 otherwise. |
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3742 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3743 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3744 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3745 <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
|
3746 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3747 <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
|
3748 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3749 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3750 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
|
3751 and 0 otherwise. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3752 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3753 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3754 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3755 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3756 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3757 <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
|
3758 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3759 <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
|
3760 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3761 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3762 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
|
3763 (either full or light), and 0 otherwise. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3764 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3765 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3766 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3767 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3768 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3769 <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
|
3770 <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
|
3771 <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
|
3772 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3773 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3774 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
|
3775 it is equivalent to the '<code>#</code>' operator in Lua (see <a href="#3.4.6">§3.4.6</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3776 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
|
3777 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3778 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3779 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3780 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3781 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3782 <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
|
3783 <span class="apii">[-0, +1, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3784 <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
|
3785 lua_Reader reader, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3786 void *data, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3787 const char *source, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3788 const char *mode);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3789 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3790 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3791 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
|
3792 If there are no errors, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3793 <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
|
3794 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
|
3795 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
|
3796 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3797 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3798 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3799 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
|
3800 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3801 <ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3802 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3803 <li><b><a href="#pdf-LUA_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
|
3804 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3805 <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
|
3806 syntax error during precompilation;</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3807 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3808 <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
|
3809 memory allocation error;</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3810 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3811 <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
|
3812 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
|
3813 (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
|
3814 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
|
3815 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3816 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3817 </ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3818 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3819 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3820 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
|
3821 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
|
3822 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
|
3823 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3824 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3825 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3826 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
|
3827 which is used for error messages and in debug information (see <a href="#4.9">§4.9</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3828 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3829 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3830 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3831 <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
|
3832 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
|
3833 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
|
3834 with the addition that |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3835 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
|
3836 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3837 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3838 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3839 <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
|
3840 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
|
3841 unmodified when returning. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3842 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3843 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3844 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3845 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
|
3846 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
|
3847 stored at index <code>LUA_RIDX_GLOBALS</code> in the registry (see <a href="#4.5">§4.5</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3848 When loading main chunks, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3849 this upvalue will be the <code>_ENV</code> variable (see <a href="#2.2">§2.2</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3850 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3851 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3852 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3853 |
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 <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
|
3856 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3857 <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
|
3858 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3859 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3860 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
|
3861 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
|
3862 (due to lack of memory). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3863 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
|
3864 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
|
3865 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
|
3866 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
|
3867 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3868 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3869 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3870 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3871 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3872 <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
|
3873 <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
|
3874 <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
|
3875 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3876 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3877 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
|
3878 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
|
3879 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3880 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3881 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3882 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3883 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3884 <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
|
3885 <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
|
3886 <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
|
3887 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3888 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3889 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
|
3890 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
|
3891 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
|
3892 its global environment, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3893 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
|
3894 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3895 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3896 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3897 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
|
3898 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
|
3899 like any Lua object. |
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3902 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3903 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3904 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3905 <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
|
3906 <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
|
3907 <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
|
3908 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3909 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3910 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
|
3911 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
|
3912 and returns this address. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3913 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
|
3914 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3915 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3916 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3917 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3918 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3919 <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
|
3920 <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
|
3921 <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
|
3922 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3923 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3924 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
|
3925 and pushes a key–value pair from the table at the given index |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3926 (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
|
3927 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
|
3928 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
|
3929 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3930 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3931 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3932 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
|
3933 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3934 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3935 /* 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
|
3936 lua_pushnil(L); /* first key */ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3937 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
|
3938 /* 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
|
3939 printf("%s - %s\n", |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3940 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
|
3941 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
|
3942 /* 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
|
3943 lua_pop(L, 1); |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3944 } |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3945 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3946 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3947 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3948 While traversing a table, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3949 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
|
3950 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
|
3951 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
|
3952 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
|
3953 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
|
3954 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3955 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3956 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3957 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
|
3958 the table during its traversal. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3959 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3960 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3961 |
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3964 <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
|
3965 <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
|
3966 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3967 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3968 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
|
3969 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
|
3970 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
|
3971 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
|
3972 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3973 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3974 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3975 |
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 <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
|
3978 <span class="apii">[-(nargs + 1), +(nresults|1), –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3979 <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
|
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 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
|
3983 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3984 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3985 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3986 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
|
3987 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
|
3988 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
|
3989 <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
|
3990 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
|
3991 <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
|
3992 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
|
3993 and returns an error code. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3994 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
|
3995 <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
|
3996 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
|
3997 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3998 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3999 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4000 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
|
4001 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
|
4002 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
|
4003 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
|
4004 <em>message handler</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4005 (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
|
4006 In case of runtime errors, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4007 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
|
4008 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
|
4009 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
|
4010 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4011 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4012 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4013 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
|
4014 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
|
4015 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
|
4016 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
|
4017 |
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4020 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
|
4021 (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
|
4022 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4023 <ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4024 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4025 <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
|
4026 success.</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_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
|
4029 a runtime error. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4030 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4031 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4032 <li><b><a name="pdf-LUA_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
|
4033 memory allocation error. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4034 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
|
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_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
|
4038 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
|
4039 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4040 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4041 <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
|
4042 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
|
4043 (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
|
4044 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
|
4045 </li> |
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 </ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4048 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4049 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4050 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4051 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4052 <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
|
4053 <span class="apii">[-(nargs + 1), +(nresults|1), –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4054 <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
|
4055 int nargs, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4056 int nresults, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4057 int errfunc, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4058 int ctx, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4059 lua_CFunction k);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4060 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4061 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4062 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
|
4063 but allows the called function to yield (see <a href="#4.7">§4.7</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4064 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4065 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4066 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4067 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4068 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4069 <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
|
4070 <span class="apii">[-n, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4071 <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
|
4072 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4073 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4074 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
|
4075 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4076 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4077 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4078 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4079 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4080 <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
|
4081 <span class="apii">[-0, +1, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4082 <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
|
4083 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4084 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4085 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
|
4086 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4087 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4088 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4089 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4090 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4091 <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
|
4092 <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
|
4093 <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
|
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 Pushes a new C closure onto the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4097 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4098 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4099 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4100 When a C function is created, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4101 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
|
4102 thus creating a C closure (see <a href="#4.4">§4.4</a>); |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4103 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
|
4104 To associate values with a C function, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4105 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
|
4106 (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
|
4107 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
|
4108 is called to create and push the C function onto the stack, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4109 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
|
4110 associated with the function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4111 <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
|
4112 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4113 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4114 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4115 The 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
|
4116 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4117 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4118 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4119 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
|
4120 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
|
4121 which is just a pointer to the C function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4122 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
|
4123 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4124 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4125 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4126 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4127 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4128 <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
|
4129 <span class="apii">[-0, +1, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4130 <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
|
4131 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4132 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4133 Pushes a C function onto the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4134 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
|
4135 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
|
4136 when called, invokes the corresponding C function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4137 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4138 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4139 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4140 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
|
4141 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
|
4142 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
|
4143 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4144 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4145 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4146 <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
|
4147 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4148 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4149 #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
|
4150 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4151 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
|
4152 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4153 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4154 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4155 |
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 <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
|
4158 <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
|
4159 <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
|
4160 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4161 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4162 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
|
4163 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
|
4164 It is similar to the ANSI C function <code>sprintf</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4165 but has some important differences: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4166 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4167 <ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4168 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4169 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4170 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
|
4171 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
|
4172 (and deallocation, through garbage collection). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4173 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4174 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4175 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4176 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
|
4177 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
|
4178 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
|
4179 '<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
|
4180 '<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
|
4181 '<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
|
4182 '<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
|
4183 '<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
|
4184 '<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
|
4185 </li> |
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 </ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4188 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4189 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4190 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4191 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4192 <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
|
4193 <span class="apii">[-0, +1, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4194 <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
|
4195 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4196 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4197 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
|
4198 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4199 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4200 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4201 |
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 <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
|
4204 <span class="apii">[-0, +1, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4205 <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
|
4206 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4207 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4208 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
|
4209 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4210 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4211 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4212 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4213 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4214 <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
|
4215 <span class="apii">[-0, +1, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4216 <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
|
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 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
|
4220 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4221 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4222 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4223 Userdata represent C values in Lua. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4224 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
|
4225 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
|
4226 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
|
4227 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
|
4228 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
|
4229 light userdata with the same C address. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4230 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4231 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4232 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4233 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4234 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4235 <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
|
4236 <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
|
4237 <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
|
4238 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4239 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4240 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
|
4241 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
|
4242 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
|
4243 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4244 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4245 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4246 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4247 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4248 <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
|
4249 <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
|
4250 <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
|
4251 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4252 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4253 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
|
4254 onto the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4255 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
|
4256 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
|
4257 the function returns. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4258 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
|
4259 including embedded zeros. |
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4263 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
|
4264 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4265 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4266 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4267 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4268 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4269 <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
|
4270 <span class="apii">[-0, +1, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4271 <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
|
4272 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4273 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4274 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
|
4275 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4276 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4277 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4278 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4279 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4280 <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
|
4281 <span class="apii">[-0, +1, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4282 <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
|
4283 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4284 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4285 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
|
4286 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4287 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4288 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4289 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4290 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4291 <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
|
4292 <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
|
4293 <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
|
4294 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4295 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4296 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
|
4297 onto the stack. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4298 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
|
4299 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
|
4300 the function returns. |
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 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
|
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4308 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
|
4309 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4310 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4311 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4312 |
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 <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
|
4315 <span class="apii">[-0, +1, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4316 <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
|
4317 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4318 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4319 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
|
4320 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
|
4321 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4322 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4323 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4324 |
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 <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
|
4327 <span class="apii">[-0, +1, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4328 <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
|
4329 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4330 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4331 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
|
4332 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4333 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4334 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4335 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4336 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4337 <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
|
4338 <span class="apii">[-0, +1, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4339 <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
|
4340 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4341 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4342 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
|
4343 onto the stack. |
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4346 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4347 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4348 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4349 <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
|
4350 <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
|
4351 <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
|
4352 const char *fmt, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4353 va_list argp);</pre> |
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4356 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
|
4357 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
|
4358 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4359 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4360 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4361 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4362 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4363 <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
|
4364 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4365 <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
|
4366 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4367 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4368 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
|
4369 <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
|
4370 (that is, without calling metamethods). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4371 Otherwise returns 0. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4372 Also returns 0 if any of the indices are non valid. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4373 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4374 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4375 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4376 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4377 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4378 <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
|
4379 <span class="apii">[-1, +1, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4380 <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
|
4381 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4382 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4383 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
|
4384 (i.e., without metamethods). |
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4387 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4388 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4389 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4390 <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
|
4391 <span class="apii">[-0, +1, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4392 <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
|
4393 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4394 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4395 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
|
4396 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
|
4397 The access is raw; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4398 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
|
4399 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4400 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4401 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4402 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4403 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4404 <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
|
4405 <span class="apii">[-0, +1, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4406 <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
|
4407 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4408 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4409 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
|
4410 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
|
4411 <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
|
4412 The access is raw; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4413 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
|
4414 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4415 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4416 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4417 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4418 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4419 <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
|
4420 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4421 <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
|
4422 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4423 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4424 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
|
4425 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
|
4426 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
|
4427 with no metamethods; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4428 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
|
4429 for the userdata; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4430 for other values, it is 0. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4431 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4432 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4433 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4434 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4435 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4436 <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
|
4437 <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
|
4438 <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
|
4439 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4440 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4441 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
|
4442 (i.e., without metamethods). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4443 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4444 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4445 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4446 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4447 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4448 <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
|
4449 <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
|
4450 <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
|
4451 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4452 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4453 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
|
4454 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
|
4455 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
|
4456 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4457 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4458 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4459 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
|
4460 The assignment is raw; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4461 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
|
4462 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4463 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4464 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4465 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4466 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4467 <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
|
4468 <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
|
4469 <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
|
4470 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4471 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4472 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
|
4473 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
|
4474 <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
|
4475 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
|
4476 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4477 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4478 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4479 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
|
4480 The assignment is raw; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4481 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
|
4482 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4483 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4484 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4485 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4486 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4487 <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
|
4488 <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
|
4489 void *data, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4490 size_t *size);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4491 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4492 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4493 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
|
4494 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
|
4495 <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
|
4496 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
|
4497 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
|
4498 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
|
4499 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
|
4500 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
|
4501 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
|
4502 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
|
4503 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
|
4504 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4505 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4506 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4507 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4508 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4509 <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
|
4510 <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
|
4511 <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
|
4512 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4513 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4514 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
|
4515 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
|
4516 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4517 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4518 #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
|
4519 (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
|
4520 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4521 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4522 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4523 |
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 <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
|
4526 <span class="apii">[-1, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4527 <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
|
4528 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4529 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4530 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
|
4531 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
|
4532 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
|
4533 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
|
4534 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4535 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4536 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4537 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4538 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4539 <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
|
4540 <span class="apii">[-1, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4541 <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
|
4542 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4543 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4544 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
|
4545 without shifting any element |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4546 (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
|
4547 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
|
4548 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4549 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4550 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4551 |
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 <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
|
4554 <span class="apii">[-?, +?, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4555 <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
|
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 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
|
4559 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4560 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4561 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4562 To start a coroutine, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4563 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
|
4564 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
|
4565 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
|
4566 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
|
4567 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
|
4568 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
|
4569 <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
|
4570 <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
|
4571 <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
|
4572 without errors, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4573 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
|
4574 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4575 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4576 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4577 In case of errors, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4578 the stack is not unwound, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4579 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
|
4580 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
|
4581 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4582 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4583 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4584 To resume a coroutine, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4585 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
|
4586 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
|
4587 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
|
4588 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
|
4589 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4590 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4591 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4592 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
|
4593 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
|
4594 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
|
4595 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4596 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4597 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4598 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4599 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4600 <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
|
4601 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4602 <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
|
4603 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4604 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4605 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
|
4606 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
|
4607 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4608 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4609 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4610 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4611 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4612 <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
|
4613 <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
|
4614 <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
|
4615 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4616 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4617 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
|
4618 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
|
4619 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
|
4620 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4621 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4622 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4623 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
|
4624 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
|
4625 for the "newindex" event (see <a href="#2.4">§2.4</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4626 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4627 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4628 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4629 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4630 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4631 <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
|
4632 <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
|
4633 <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
|
4634 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4635 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4636 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
|
4637 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
|
4638 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4639 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4640 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4641 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4642 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4643 <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
|
4644 <span class="apii">[-1, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4645 <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
|
4646 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4647 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4648 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
|
4649 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
|
4650 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4651 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4652 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4653 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4654 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4655 <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
|
4656 <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
|
4657 <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
|
4658 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4659 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4660 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
|
4661 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
|
4662 <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
|
4663 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
|
4664 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4665 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4666 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4667 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
|
4668 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
|
4669 for the "newindex" event (see <a href="#2.4">§2.4</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4670 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4671 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4672 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4673 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4674 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4675 <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
|
4676 <span class="apii">[-?, +?, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4677 <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
|
4678 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4679 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4680 Accepts any index, or 0, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4681 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
|
4682 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
|
4683 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
|
4684 If <code>index</code> is 0, then all stack elements are removed. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4685 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4686 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4687 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4688 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4689 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4690 <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
|
4691 <span class="apii">[-1, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4692 <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
|
4693 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4694 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4695 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
|
4696 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
|
4697 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4698 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4699 |
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4702 <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
|
4703 <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
|
4704 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4705 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4706 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
|
4707 (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
|
4708 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
|
4709 it has no global variables. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4710 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
|
4711 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4712 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4713 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4714 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
|
4715 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
|
4716 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
|
4717 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4718 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4719 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4720 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4721 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4722 <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
|
4723 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4724 <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
|
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 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
|
4728 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4729 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4730 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4731 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
|
4732 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
|
4733 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
|
4734 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
|
4735 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4736 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4737 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4738 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
|
4739 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
|
4740 (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
|
4741 (to resume a coroutine). |
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4744 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4745 |
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 <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
|
4748 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4749 <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
|
4750 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4751 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4752 Converts the Lua value at the given index to a C boolean |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4753 value (0 or 1). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4754 Like all tests in Lua, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4755 <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
|
4756 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
|
4757 otherwise it returns false. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4758 (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
|
4759 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
|
4760 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4761 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4762 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4763 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4764 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4765 <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
|
4766 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4767 <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
|
4768 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4769 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4770 Converts a value at the given index to a C function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4771 That value must be a C function; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4772 otherwise, returns <code>NULL</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4773 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4774 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4775 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4776 |
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 <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
|
4779 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4780 <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
|
4781 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4782 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4783 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
|
4784 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4785 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4786 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4787 |
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 <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
|
4790 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4791 <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
|
4792 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4793 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4794 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
|
4795 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
|
4796 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
|
4797 (see <a href="#3.4.2">§3.4.2</a>); |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4798 otherwise, <code>lua_tointegerx</code> returns 0. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4799 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4800 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4801 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4802 If 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
|
4803 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
|
4804 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4805 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4806 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4807 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
|
4808 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
|
4809 indicates whether the operation succeeded. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4810 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4811 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4812 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4813 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4814 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4815 <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
|
4816 <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
|
4817 <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
|
4818 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4819 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4820 Converts the Lua value at the given index to a C string. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4821 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
|
4822 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
|
4823 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
|
4824 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
|
4825 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
|
4826 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
|
4827 <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
|
4828 (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
|
4829 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
|
4830 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4831 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4832 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4833 <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
|
4834 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
|
4835 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
|
4836 after its last character (as in C), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4837 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
|
4838 Because Lua has garbage collection, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4839 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
|
4840 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
|
4841 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4842 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4843 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4844 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4845 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4846 <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
|
4847 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4848 <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
|
4849 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4850 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4851 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
|
4852 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4853 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4854 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4855 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4856 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4857 <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
|
4858 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4859 <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
|
4860 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4861 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4862 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
|
4863 to the C type <a href="#lua_Number"><code>lua_Number</code></a> (see <a href="#lua_Number"><code>lua_Number</code></a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4864 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
|
4865 (see <a href="#3.4.2">§3.4.2</a>); |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4866 otherwise, <a href="#lua_tonumberx"><code>lua_tonumberx</code></a> returns 0. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4867 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4868 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4869 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4870 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
|
4871 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
|
4872 indicates whether the operation succeeded. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4873 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4874 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4875 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4876 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4877 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4878 <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
|
4879 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4880 <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
|
4881 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4882 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4883 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
|
4884 C pointer (<code>void*</code>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4885 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
|
4886 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
|
4887 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
|
4888 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
|
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4892 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
|
4893 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4894 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4895 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4896 |
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 <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
|
4899 <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
|
4900 <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
|
4901 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4902 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4903 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
|
4904 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4905 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4906 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4907 |
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 <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
|
4910 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4911 <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
|
4912 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4913 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4914 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
|
4915 (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
|
4916 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
|
4917 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
|
4918 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4919 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4920 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4921 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4922 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4923 <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
|
4924 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4925 <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
|
4926 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4927 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4928 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
|
4929 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4930 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4931 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4932 |
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 <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
|
4935 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4936 <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
|
4937 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4938 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4939 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
|
4940 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
|
4941 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
|
4942 (see <a href="#3.4.2">§3.4.2</a>); |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4943 otherwise, <code>lua_tounsignedx</code> returns 0. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4944 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4945 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4946 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4947 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
|
4948 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
|
4949 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
|
4950 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
|
4951 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
|
4952 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4953 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4954 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4955 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
|
4956 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
|
4957 indicates whether the operation succeeded. |
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4960 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4961 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4962 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4963 <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
|
4964 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4965 <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
|
4966 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4967 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4968 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
|
4969 returns its block address. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4970 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
|
4971 returns its pointer. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4972 Otherwise, returns <code>NULL</code>. |
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4975 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4976 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4977 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4978 <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
|
4979 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4980 <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
|
4981 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4982 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4983 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
|
4984 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
|
4985 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
|
4986 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
|
4987 <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
|
4988 <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
|
4989 <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
|
4990 <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
|
4991 <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
|
4992 <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
|
4993 <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
|
4994 <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
|
4995 and |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4996 <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
|
4997 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4998 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4999 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5000 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5001 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5002 <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
|
5003 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5004 <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
|
5005 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5006 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5007 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
|
5008 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
|
5009 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5010 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5011 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5012 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5013 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5014 <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
|
5015 <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
|
5016 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5017 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5018 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
|
5019 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
|
5020 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5021 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5022 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5023 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
|
5024 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
|
5025 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5026 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5027 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5028 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5029 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5030 <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
|
5031 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5032 <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
|
5033 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5034 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5035 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
|
5036 the running function (see <a href="#4.4">§4.4</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5037 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5038 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5039 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5040 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5041 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5042 <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
|
5043 <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
|
5044 <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
|
5045 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5046 <p> |
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 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
|
5048 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
|
5049 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
|
5050 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
|
5051 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
|
5052 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5053 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5054 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5055 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5056 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5057 <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
|
5058 <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
|
5059 const void* p, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5060 size_t sz, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5061 void* ud);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5062 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5063 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5064 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
|
5065 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
|
5066 <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
|
5067 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
|
5068 its size (<code>sz</code>), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5069 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
|
5070 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5071 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5072 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5073 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
|
5074 0 means no errors; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5075 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
|
5076 calling the writer again. |
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5079 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5080 |
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 <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
|
5083 <span class="apii">[-?, +?, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5084 <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
|
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 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
|
5088 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5089 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5090 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5091 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
|
5092 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
|
5093 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5094 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5095 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5096 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5097 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5098 <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
|
5099 <span class="apii">[-?, +?, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5100 <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
|
5101 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5102 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5103 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
|
5104 but it has no continuation (see <a href="#4.7">§4.7</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5105 Therefore, when the thread resumes, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5106 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
|
5107 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
|
5108 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5109 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5110 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5111 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5112 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5113 <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
|
5114 <span class="apii">[-?, +?, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5115 <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
|
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 Yields a coroutine. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5119 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5120 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5121 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5122 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
|
5123 return expression of a C function, as follows: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5124 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5125 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5126 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
|
5127 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5128 When a C function calls <a href="#lua_yieldk"><code>lua_yieldk</code></a> in that way, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5129 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
|
5130 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
|
5131 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
|
5132 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
|
5133 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5134 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5135 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5136 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
|
5137 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
|
5138 the execution of the C function that yielded (see <a href="#4.7">§4.7</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5139 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
|
5140 from the previous function, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5141 with the results removed and |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5142 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
|
5143 Moreover, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5144 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
|
5145 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
|
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 |
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5152 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5153 <h2>4.9 – <a name="4.9">The Debug Interface</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5154 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5155 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5156 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
|
5157 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
|
5158 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
|
5159 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
|
5160 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
|
5161 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
|
5162 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5163 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5164 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5165 <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
|
5166 <pre>typedef struct lua_Debug { |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5167 int event; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5168 const char *name; /* (n) */ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5169 const char *namewhat; /* (n) */ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5170 const char *what; /* (S) */ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5171 const char *source; /* (S) */ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5172 int currentline; /* (l) */ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5173 int linedefined; /* (S) */ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5174 int lastlinedefined; /* (S) */ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5175 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
|
5176 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
|
5177 char isvararg; /* (u) */ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5178 char istailcall; /* (t) */ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5179 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
|
5180 /* private part */ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5181 <em>other fields</em> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5182 } lua_Debug;</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5183 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5184 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5185 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
|
5186 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
|
5187 <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
|
5188 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
|
5189 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
|
5190 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
|
5191 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5192 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5193 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5194 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
|
5195 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5196 <ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5197 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5198 <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
|
5199 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
|
5200 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
|
5201 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
|
5202 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
|
5203 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
|
5204 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
|
5205 Otherwise, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5206 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
|
5207 <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
|
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>short_src</code>: </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5211 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
|
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>linedefined</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 starts. |
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>lastlinedefined</code>: </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5219 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
|
5220 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5221 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5222 <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
|
5223 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
|
5224 <code>"C"</code> if it is a C function, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5225 <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
|
5226 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5227 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5228 <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
|
5229 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
|
5230 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
|
5231 <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
|
5232 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5233 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5234 <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
|
5235 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
|
5236 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
|
5237 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
|
5238 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
|
5239 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
|
5240 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
|
5241 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
|
5242 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
|
5243 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
|
5244 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5245 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5246 <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
|
5247 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
|
5248 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
|
5249 <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
|
5250 <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
|
5251 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
|
5252 (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
|
5253 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5254 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5255 <li><b><code>istailcall</code>: </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5256 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
|
5257 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
|
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>nups</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 upvalues of the function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5262 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5263 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5264 <li><b><code>nparams</code>: </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5265 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
|
5266 (always 0 for C functions). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5267 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5268 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5269 <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
|
5270 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
|
5271 (always true for C functions). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5272 </li> |
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 </ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5275 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5276 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5277 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5278 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5279 <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
|
5280 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5281 <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
|
5282 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5283 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5284 Returns the current hook function. |
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5287 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5288 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5289 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5290 <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
|
5291 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5292 <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
|
5293 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5294 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5295 Returns the current hook count. |
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5298 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5299 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5300 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5301 <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
|
5302 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5303 <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
|
5304 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5305 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5306 Returns the current hook mask. |
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5309 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5310 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5311 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5312 <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
|
5313 <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
|
5314 <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
|
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 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
|
5318 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5319 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5320 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5321 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
|
5322 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
|
5323 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
|
5324 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
|
5325 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5326 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5327 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5328 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
|
5329 and start the <code>what</code> string with the character '<code>></code>'. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5330 (In that case, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5331 <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
|
5332 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
|
5333 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
|
5334 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5335 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5336 lua_Debug ar; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5337 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
|
5338 lua_getinfo(L, ">S", &ar); |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5339 printf("%d\n", ar.linedefined); |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5340 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5341 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5342 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5343 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
|
5344 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
|
5345 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
|
5346 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5347 <ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5348 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5349 <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
|
5350 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5351 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5352 <li><b>'<code>S</code>': </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5353 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
|
5354 <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
|
5355 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5356 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5357 <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
|
5358 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5359 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5360 <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
|
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>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
|
5364 <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
|
5365 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5366 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5367 <li><b>'<code>f</code>': </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5368 pushes onto the stack the function that is |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5369 running at the given level; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5370 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5371 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5372 <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
|
5373 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
|
5374 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
|
5375 (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
|
5376 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
|
5377 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
|
5378 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5379 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5380 </ul> |
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5383 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
|
5384 (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
|
5385 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5386 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5387 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5388 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5389 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5390 <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
|
5391 <span class="apii">[-0, +(0|1), –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5392 <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
|
5393 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5394 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5395 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
|
5396 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
|
5397 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5398 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5399 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5400 In the first case, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5401 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
|
5402 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
|
5403 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
|
5404 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
|
5405 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
|
5406 and names. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5407 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5408 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5409 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5410 <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
|
5411 and returns its name. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5412 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5413 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5414 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5415 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
|
5416 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
|
5417 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
|
5418 (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
|
5419 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
|
5420 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5421 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5422 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5423 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
|
5424 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
|
5425 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
|
5426 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5427 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5428 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5429 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5430 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5431 <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
|
5432 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5433 <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
|
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 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
|
5437 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5438 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5439 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5440 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
|
5441 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
|
5442 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
|
5443 Level 0 is the current running function, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5444 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
|
5445 (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
|
5446 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
|
5447 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
|
5448 it returns 0. |
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5451 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5452 |
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 <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
|
5455 <span class="apii">[-0, +(0|1), –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5456 <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
|
5457 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5458 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5459 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
|
5460 (For Lua functions, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5461 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
|
5462 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
|
5463 <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
|
5464 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
|
5465 and returns its name. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5466 <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
|
5467 (Upvalues have no particular order, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5468 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
|
5469 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
|
5470 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5471 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5472 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5473 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
|
5474 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
|
5475 For C functions, this function uses the empty string <code>""</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5476 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
|
5477 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5478 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5479 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5480 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5481 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5482 <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
|
5483 <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
|
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 Type for debugging hook functions. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5487 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5488 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5489 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5490 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
|
5491 <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
|
5492 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
|
5493 <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
|
5494 <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
|
5495 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
|
5496 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
|
5497 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
|
5498 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
|
5499 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5500 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5501 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5502 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
|
5503 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
|
5504 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
|
5505 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5506 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5507 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5508 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
|
5509 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
|
5510 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
|
5511 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5512 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5513 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5514 Hook functions cannot have continuations, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5515 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
|
5516 <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
|
5517 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5518 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5519 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5520 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
|
5521 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
|
5522 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
|
5523 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
|
5524 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
|
5525 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5526 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5527 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5528 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5529 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5530 <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
|
5531 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5532 <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
|
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 Sets the debugging hook function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5536 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5537 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5538 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5539 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
|
5540 <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
|
5541 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
|
5542 <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
|
5543 <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
|
5544 <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
|
5545 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
|
5546 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
|
5547 includes <code>LUA_MASKCOUNT</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5548 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
|
5549 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5550 <ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5551 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5552 <li><b>The 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
|
5553 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
|
5554 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
|
5555 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5556 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5557 <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
|
5558 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
|
5559 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
|
5560 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
|
5561 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5562 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5563 <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
|
5564 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
|
5565 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
|
5566 (This event only happens while Lua is executing a Lua function.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5567 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5568 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5569 <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
|
5570 <code>count</code> instructions. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5571 (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
|
5572 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5573 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5574 </ul> |
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5577 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
|
5578 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5579 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5580 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5581 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5582 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5583 <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
|
5584 <span class="apii">[-(0|1), +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5585 <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
|
5586 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5587 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5588 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
|
5589 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
|
5590 (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
|
5591 <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
|
5592 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
|
5593 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
|
5594 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5595 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5596 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5597 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
|
5598 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
|
5599 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
|
5600 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5601 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5602 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5603 |
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 <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
|
5606 <span class="apii">[-(0|1), +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5607 <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
|
5608 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5609 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5610 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
|
5611 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
|
5612 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
|
5613 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
|
5614 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
|
5615 (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
|
5616 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5617 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5618 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5619 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
|
5620 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
|
5621 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5622 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5623 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5624 |
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 <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
|
5627 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5628 <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
|
5629 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5630 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5631 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
|
5632 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
|
5633 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
|
5634 (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
|
5635 (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
|
5636 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5637 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5638 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5639 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
|
5640 closures share upvalues. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5641 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
|
5642 (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
|
5643 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
|
5644 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5645 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5646 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5647 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5648 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5649 <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
|
5650 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5651 <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
|
5652 int funcindex2, int n2);</pre> |
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5655 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
|
5656 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
|
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 |
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 |
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 <h1>5 – <a name="5">The Auxiliary Library</a></h1> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5665 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5666 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5667 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5668 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
|
5669 to interface C with Lua. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5670 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
|
5671 interactions between C and Lua, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5672 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
|
5673 common tasks. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5674 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5675 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5676 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5677 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
|
5678 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
|
5679 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
|
5680 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5681 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5682 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5683 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
|
5684 top of the basic API, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5685 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
|
5686 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
|
5687 more consistency to your code. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5688 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5689 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5690 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5691 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
|
5692 extra stack slots. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5693 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
|
5694 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
|
5695 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
|
5696 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5697 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5698 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5699 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
|
5700 check C function arguments. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5701 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
|
5702 (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
|
5703 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
|
5704 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5705 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5706 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5707 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
|
5708 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
|
5709 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5710 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5711 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5712 <h2>5.1 – <a name="5.1">Functions and Types</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5713 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5714 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5715 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
|
5716 in alphabetical order. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5717 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5718 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5719 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5720 <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
|
5721 <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
|
5722 <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
|
5723 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5724 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5725 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
|
5726 (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
|
5727 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5728 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5729 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5730 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5731 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5732 <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
|
5733 <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
|
5734 <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
|
5735 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5736 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5737 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
|
5738 the buffer <code>B</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5739 (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
|
5740 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
|
5741 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5742 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5743 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5744 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5745 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5746 <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
|
5747 <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
|
5748 <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
|
5749 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5750 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5751 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
|
5752 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
|
5753 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
|
5754 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5755 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5756 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5757 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5758 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5759 <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
|
5760 <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
|
5761 <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
|
5762 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5763 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5764 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
|
5765 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
|
5766 (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
|
5767 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
|
5768 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5769 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5770 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5771 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5772 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5773 <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
|
5774 <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
|
5775 <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
|
5776 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5777 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5778 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
|
5779 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
|
5780 (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
|
5781 Pops the value. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5782 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5783 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5784 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5785 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
|
5786 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
|
5787 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
|
5788 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5789 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5790 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5791 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5792 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5793 <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
|
5794 <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
|
5795 <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
|
5796 int cond, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5797 int arg, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5798 const char *extramsg);</pre> |
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5801 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
|
5802 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
|
5803 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5804 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5805 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5806 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5807 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5808 <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
|
5809 <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
|
5810 <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
|
5811 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5812 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5813 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
|
5814 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
|
5815 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5816 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5817 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5818 This function never returns, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5819 but it is an idiom to use it in C functions |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5820 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
|
5821 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5822 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5823 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5824 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5825 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5826 <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
|
5827 <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
|
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 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
|
5831 |
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5834 A string buffer allows C code to build Lua strings piecemeal. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5835 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
|
5836 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5837 <ul> |
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>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
|
5840 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5841 <li>Then initialize it with a call <code>luaL_buffinit(L, &b)</code>.</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5842 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5843 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5844 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
|
5845 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
|
5846 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5847 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5848 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5849 Finish by calling <code>luaL_pushresult(&b)</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5850 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
|
5851 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5852 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5853 </ul> |
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5856 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
|
5857 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
|
5858 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5859 <ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5860 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5861 <li>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
|
5862 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5863 <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
|
5864 size <code>sz</code> with a call <code>luaL_buffinitsize(L, &b, sz)</code>.</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5865 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5866 <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
|
5867 |
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 Finish by calling <code>luaL_pushresultsize(&b, sz)</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5870 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
|
5871 copied into that space. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5872 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5873 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5874 </ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5875 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5876 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5877 During its normal operation, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5878 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
|
5879 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
|
5880 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
|
5881 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
|
5882 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
|
5883 that is, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5884 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
|
5885 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
|
5886 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
|
5887 (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
|
5888 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
|
5889 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
|
5890 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
|
5891 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5892 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5893 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5894 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5895 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5896 <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
|
5897 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5898 <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
|
5899 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5900 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5901 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
|
5902 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
|
5903 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
|
5904 (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
|
5905 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5906 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5907 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5908 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5909 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5910 <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
|
5911 <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
|
5912 <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
|
5913 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5914 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5915 Equivalent to the sequence |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5916 <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
|
5917 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5918 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5919 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5920 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5921 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5922 <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
|
5923 <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
|
5924 <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
|
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 Calls a metamethod. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5928 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5929 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5930 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5931 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
|
5932 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
|
5933 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
|
5934 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
|
5935 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
|
5936 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
|
5937 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
|
5938 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5939 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5940 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5941 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5942 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5943 <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
|
5944 <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
|
5945 <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
|
5946 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5947 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5948 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
|
5949 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
|
5950 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5951 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5952 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5953 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5954 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5955 <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
|
5956 <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
|
5957 <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
|
5958 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5959 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5960 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
|
5961 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
|
5962 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5963 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5964 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5965 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5966 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5967 <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
|
5968 <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
|
5969 <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
|
5970 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5971 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5972 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
|
5973 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
|
5974 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5975 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5976 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5977 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5978 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5979 <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
|
5980 <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
|
5981 <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
|
5982 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5983 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5984 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
|
5985 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
|
5986 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5987 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5988 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5989 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5990 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5991 <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
|
5992 <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
|
5993 <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
|
5994 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5995 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5996 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
|
5997 and returns this string; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5998 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
|
5999 with the string's length. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6000 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6001 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6002 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6003 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
|
6004 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
|
6005 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6006 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6007 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6008 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6009 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6010 <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
|
6011 <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
|
6012 <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
|
6013 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6014 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6015 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
|
6016 and returns this number. |
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6019 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6020 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6021 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6022 <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
|
6023 <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
|
6024 <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
|
6025 int arg, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6026 const char *def, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6027 const char *const lst[]);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6028 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6029 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6030 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
|
6031 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
|
6032 (which must be NULL-terminated). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6033 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
|
6034 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
|
6035 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
|
6036 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6037 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6038 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6039 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
|
6040 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
|
6041 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
|
6042 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6043 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6044 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6045 This is a useful function for mapping strings to C enums. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6046 (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
|
6047 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
|
6048 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6049 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6050 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6051 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6052 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6053 <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
|
6054 <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
|
6055 <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
|
6056 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6057 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6058 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
|
6059 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
|
6060 <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
|
6061 (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
|
6062 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6063 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6064 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6065 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6066 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6067 <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
|
6068 <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
|
6069 <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
|
6070 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6071 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6072 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
|
6073 and returns this string. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6074 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6075 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6076 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6077 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
|
6078 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
|
6079 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6080 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6081 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6082 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6083 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6084 <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
|
6085 <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
|
6086 <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
|
6087 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6088 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6089 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
|
6090 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
|
6091 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6092 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6093 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6094 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6095 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6096 <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
|
6097 <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
|
6098 <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
|
6099 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6100 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6101 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
|
6102 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
|
6103 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
|
6104 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6105 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6106 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6107 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6108 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6109 <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
|
6110 <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
|
6111 <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
|
6112 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6113 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6114 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
|
6115 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
|
6116 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6117 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6118 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6119 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6120 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6121 <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
|
6122 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6123 <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
|
6124 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6125 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6126 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
|
6127 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
|
6128 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
|
6129 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
|
6130 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
|
6131 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
|
6132 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6133 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6134 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6135 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6136 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6137 <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
|
6138 <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
|
6139 <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
|
6140 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6141 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6142 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
|
6143 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
|
6144 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6145 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6146 (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
|
6147 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6148 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
|
6149 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
|
6150 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6151 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6152 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6153 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6154 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6155 <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
|
6156 <span class="apii">[-0, +?, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6157 <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
|
6158 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6159 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6160 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
|
6161 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
|
6162 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6163 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6164 (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
|
6165 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6166 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
|
6167 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
|
6168 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6169 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6170 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6171 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6172 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6173 <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
|
6174 <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
|
6175 <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
|
6176 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6177 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6178 Raises an error. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6179 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
|
6180 plus any extra arguments, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6181 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
|
6182 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
|
6183 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
|
6184 if this information is available. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6185 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6186 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6187 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6188 This function never returns, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6189 but it is an idiom to use it in C functions |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6190 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
|
6191 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6192 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6193 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6194 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6195 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6196 <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
|
6197 <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
|
6198 <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
|
6199 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6200 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6201 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
|
6202 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
|
6203 (<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
|
6204 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6205 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6206 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6207 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6208 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6209 <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
|
6210 <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
|
6211 <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
|
6212 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6213 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6214 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
|
6215 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
|
6216 (<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
|
6217 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6218 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6219 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6220 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6221 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6222 <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
|
6223 <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
|
6224 <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
|
6225 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6226 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6227 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
|
6228 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
|
6229 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
|
6230 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
|
6231 returns false and pushes nothing. |
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6234 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6235 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6236 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6237 <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
|
6238 <span class="apii">[-0, +1, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6239 <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
|
6240 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6241 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6242 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
|
6243 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
|
6244 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6245 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6246 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6247 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6248 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6249 <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
|
6250 <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
|
6251 <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
|
6252 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6253 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6254 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
|
6255 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
|
6256 is a table, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6257 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
|
6258 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
|
6259 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
|
6260 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6261 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6262 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6263 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6264 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6265 <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
|
6266 <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
|
6267 <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
|
6268 const char *s, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6269 const char *p, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6270 const char *r);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6271 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6272 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6273 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
|
6274 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
|
6275 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
|
6276 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
|
6277 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6278 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6279 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6280 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6281 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6282 <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
|
6283 <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
|
6284 <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
|
6285 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6286 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6287 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
|
6288 as a number; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6289 it is equivalent to the '<code>#</code>' operator in Lua (see <a href="#3.4.6">§3.4.6</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6290 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
|
6291 (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
|
6292 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6293 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6294 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6295 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6296 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6297 <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
|
6298 <span class="apii">[-0, +1, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6299 <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
|
6300 const char *buff, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6301 size_t sz, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6302 const char *name);</pre> |
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6305 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
|
6306 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6307 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6308 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6309 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6310 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6311 <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
|
6312 <span class="apii">[-0, +1, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6313 <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
|
6314 const char *buff, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6315 size_t sz, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6316 const char *name, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6317 const char *mode);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6318 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6319 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6320 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
|
6321 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
|
6322 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
|
6323 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6324 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6325 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6326 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
|
6327 <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
|
6328 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
|
6329 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
|
6330 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6331 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6332 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6333 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6334 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6335 <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
|
6336 <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
|
6337 <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
|
6338 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6339 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6340 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
|
6341 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6342 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6343 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6344 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6345 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6346 <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
|
6347 <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
|
6348 <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
|
6349 const char *mode);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6350 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6351 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6352 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
|
6353 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
|
6354 named <code>filename</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6355 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
|
6356 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
|
6357 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
|
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 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
|
6362 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6363 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6364 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6365 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
|
6366 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
|
6367 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
|
6368 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6369 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6370 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6371 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
|
6372 it does not run it. |
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6375 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6376 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6377 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6378 <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
|
6379 <span class="apii">[-0, +1, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6380 <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
|
6381 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6382 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6383 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
|
6384 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
|
6385 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
|
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 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
|
6390 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6391 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6392 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6393 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
|
6394 it does not run it. |
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6397 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6398 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6399 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6400 <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
|
6401 <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
|
6402 <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
|
6403 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6404 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6405 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
|
6406 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
|
6407 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
|
6408 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6409 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6410 (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
|
6411 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6412 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6413 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6414 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6415 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6416 <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
|
6417 <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
|
6418 <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
|
6419 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6420 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6421 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
|
6422 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
|
6423 (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
|
6424 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
|
6425 (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
|
6426 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6427 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6428 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6429 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
|
6430 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
|
6431 not a pointer to it. |
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6434 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6435 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6436 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6437 <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
|
6438 <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
|
6439 <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
|
6440 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6441 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6442 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
|
6443 returns 0. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6444 Otherwise, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6445 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
|
6446 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
|
6447 and returns 1. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6448 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6449 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6450 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6451 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
|
6452 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
|
6453 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6454 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6455 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6456 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6457 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6458 <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
|
6459 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6460 <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
|
6461 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6462 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6463 Creates a new Lua state. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6464 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
|
6465 allocator based on the standard C <code>realloc</code> function |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6466 and then sets a panic function (see <a href="#4.6">§4.6</a>) that prints |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6467 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
|
6468 errors. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6469 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6470 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6471 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6472 Returns the new state, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6473 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
|
6474 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6475 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6476 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6477 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6478 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6479 <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
|
6480 <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
|
6481 <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
|
6482 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6483 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6484 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
|
6485 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6486 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6487 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6488 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6489 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6490 <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
|
6491 <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
|
6492 <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
|
6493 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6494 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6495 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
|
6496 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
|
6497 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
|
6498 returns <code>d</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6499 Otherwise, raises an error. |
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6502 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6503 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6504 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6505 <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
|
6506 <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
|
6507 <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
|
6508 int arg, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6509 lua_Integer d);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6510 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6511 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6512 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
|
6513 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
|
6514 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
|
6515 returns <code>d</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6516 Otherwise, raises an error. |
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6519 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6520 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6521 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6522 <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
|
6523 <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
|
6524 <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
|
6525 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6526 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6527 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
|
6528 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
|
6529 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
|
6530 returns <code>d</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6531 Otherwise, raises an error. |
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6534 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6535 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6536 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6537 <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
|
6538 <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
|
6539 <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
|
6540 int arg, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6541 const char *d, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6542 size_t *l);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6543 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6544 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6545 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
|
6546 returns this string. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6547 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
|
6548 returns <code>d</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6549 Otherwise, raises an error. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6550 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6551 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6552 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6553 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
|
6554 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
|
6555 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6556 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6557 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6558 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6559 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6560 <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
|
6561 <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
|
6562 <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
|
6563 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6564 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6565 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
|
6566 returns this number. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6567 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
|
6568 returns <code>d</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6569 Otherwise, raises an error. |
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6572 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6573 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6574 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6575 <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
|
6576 <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
|
6577 <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
|
6578 int arg, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6579 const char *d);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6580 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6581 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6582 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
|
6583 returns this string. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6584 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
|
6585 returns <code>d</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6586 Otherwise, raises an error. |
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6589 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6590 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6591 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6592 <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
|
6593 <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
|
6594 <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
|
6595 int arg, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6596 lua_Unsigned u);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6597 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6598 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6599 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
|
6600 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
|
6601 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
|
6602 returns <code>u</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6603 Otherwise, raises an error. |
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6606 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6607 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6608 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6609 <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
|
6610 <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
|
6611 <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
|
6612 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6613 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6614 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
|
6615 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
|
6616 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6617 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6618 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6619 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6620 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6621 <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
|
6622 <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
|
6623 <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
|
6624 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6625 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6626 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
|
6627 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
|
6628 (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
|
6629 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
|
6630 <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
|
6631 it to the buffer. |
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6634 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6635 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6636 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6637 <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
|
6638 <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
|
6639 <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
|
6640 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6641 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6642 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
|
6643 the top of the stack. |
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6646 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6647 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6648 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6649 <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
|
6650 <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
|
6651 <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
|
6652 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6653 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6654 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
|
6655 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6656 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6657 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6658 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6659 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6660 <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
|
6661 <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
|
6662 <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
|
6663 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6664 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6665 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
|
6666 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
|
6667 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
|
6668 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6669 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6670 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6671 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
|
6672 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
|
6673 <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
|
6674 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
|
6675 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
|
6676 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
|
6677 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6678 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6679 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6680 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
|
6681 <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
|
6682 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
|
6683 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
|
6684 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6685 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6686 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6687 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6688 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6689 <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
|
6690 <pre>typedef struct luaL_Reg { |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6691 const char *name; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6692 lua_CFunction func; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6693 } luaL_Reg;</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6694 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6695 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6696 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
|
6697 <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
|
6698 <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
|
6699 the function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6700 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
|
6701 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
|
6702 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6703 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6704 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6705 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6706 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6707 <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
|
6708 <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
|
6709 <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
|
6710 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
|
6711 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6712 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6713 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
|
6714 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
|
6715 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
|
6716 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6717 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6718 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6719 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
|
6720 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
|
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6724 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
|
6725 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6726 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6727 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6728 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6729 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6730 <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
|
6731 <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
|
6732 <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
|
6733 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6734 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6735 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
|
6736 (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
|
6737 (below optional upvalues, see next). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6738 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6739 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6740 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6741 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
|
6742 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
|
6743 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
|
6744 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
|
6745 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
|
6746 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6747 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6748 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6749 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6750 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6751 <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
|
6752 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6753 <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
|
6754 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6755 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6756 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
|
6757 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
|
6758 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
|
6759 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6760 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6761 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6762 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6763 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6764 <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
|
6765 <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
|
6766 <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
|
6767 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6768 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6769 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
|
6770 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
|
6771 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
|
6772 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6773 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6774 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6775 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6776 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6777 <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
|
6778 <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
|
6779 <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
|
6780 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6781 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6782 Converts any Lua value at the given index to a C string |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6783 in a reasonable format. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6784 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
|
6785 returned by the function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6786 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
|
6787 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
|
6788 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6789 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6790 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6791 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
|
6792 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
|
6793 with the value as argument, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6794 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
|
6795 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6796 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6797 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6798 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6799 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6800 <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
|
6801 <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
|
6802 <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
|
6803 int level);</pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6804 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6805 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6806 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
|
6807 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
|
6808 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
|
6809 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
|
6810 to start the traceback. |
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6813 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6814 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6815 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6816 <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
|
6817 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6818 <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
|
6819 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6820 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6821 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
|
6822 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6823 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6824 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6825 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6826 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6827 <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
|
6828 <span class="apii">[-0, +0, –]</span> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6829 <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
|
6830 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6831 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6832 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
|
6833 (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
|
6834 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
|
6835 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
|
6836 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
|
6837 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6838 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6839 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6840 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
|
6841 <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
|
6842 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6843 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6844 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6845 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6846 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6847 <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
|
6848 <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
|
6849 <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
|
6850 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6851 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6852 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
|
6853 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
|
6854 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
|
6855 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6856 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6857 <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
|
6858 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6859 Level 0 is the running function, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6860 level 1 is the function that called the running function, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6861 etc. |
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6865 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
|
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 |
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6872 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6873 <h1>6 – <a name="6">Standard Libraries</a></h1> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6874 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6875 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6876 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
|
6877 that are implemented directly through the C API. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6878 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
|
6879 (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
|
6880 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
|
6881 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
|
6882 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
|
6883 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
|
6884 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6885 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6886 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6887 All libraries are implemented through the official C API |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6888 and are provided as separate C modules. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6889 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
|
6890 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6891 <ul> |
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>basic library (<a href="#6.1">§6.1</a>);</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6894 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6895 <li>coroutine library (<a href="#6.2">§6.2</a>);</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6896 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6897 <li>package library (<a href="#6.3">§6.3</a>);</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6898 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6899 <li>string manipulation (<a href="#6.4">§6.4</a>);</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6900 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6901 <li>table manipulation (<a href="#6.5">§6.5</a>);</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6902 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6903 <li>mathematical functions (<a href="#6.6">§6.6</a>) (sin, log, etc.);</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6904 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6905 <li>bitwise operations (<a href="#6.7">§6.7</a>);</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6906 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6907 <li>input and output (<a href="#6.8">§6.8</a>);</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6908 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6909 <li>operating system facilities (<a href="#6.9">§6.9</a>);</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6910 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6911 <li>debug facilities (<a href="#6.10">§6.10</a>).</li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6912 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6913 </ul><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6914 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
|
6915 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
|
6916 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
|
6917 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6918 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6919 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6920 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
|
6921 the C host program should call the <a href="#luaL_openlibs"><code>luaL_openlibs</code></a> function, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6922 which opens all standard libraries. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6923 Alternatively, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6924 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
|
6925 <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
|
6926 <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
|
6927 <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
|
6928 <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
|
6929 <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
|
6930 <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
|
6931 <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
|
6932 <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
|
6933 <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
|
6934 <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
|
6935 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
|
6936 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
|
6937 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6938 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6939 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6940 <h2>6.1 – <a name="6.1">Basic Functions</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6941 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6942 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6943 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
|
6944 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
|
6945 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
|
6946 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
|
6947 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6948 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6949 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6950 <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
|
6951 Issues an error when |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6952 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
|
6953 otherwise, returns all its arguments. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6954 <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
|
6955 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
|
6956 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6957 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6958 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6959 |
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 <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
|
6962 |
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6965 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
|
6966 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
|
6967 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6968 <ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6969 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6970 <li><b>"<code>collect</code>": </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6971 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
|
6972 This is the default option. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6973 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6974 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6975 <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
|
6976 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
|
6977 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
|
6978 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
|
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>restart</code>": </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6982 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
|
6983 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6984 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6985 <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
|
6986 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
|
6987 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
|
6988 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
|
6989 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
|
6990 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6991 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6992 k, b = collectgarbage("count") |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6993 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
|
6994 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6995 (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
|
6996 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
|
6997 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6998 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6999 <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
|
7000 performs a garbage-collection step. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7001 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
|
7002 (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
|
7003 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
|
7004 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
|
7005 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
|
7006 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7007 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7008 <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
|
7009 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
|
7010 the collector (see <a href="#2.5">§2.5</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7011 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
|
7012 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7013 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7014 <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
|
7015 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
|
7016 the collector (see <a href="#2.5">§2.5</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7017 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
|
7018 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7019 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7020 <li><b>"<code>isrunning</code>": </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7021 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
|
7022 (i.e., not stopped). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7023 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7024 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7025 <li><b>"<code>generational</code>": </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7026 changes the collector to generational mode. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7027 This is an experimental feature (see <a href="#2.5">§2.5</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7028 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7029 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7030 <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
|
7031 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
|
7032 This is the default mode. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7033 </li> |
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 </ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7036 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7037 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7038 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7039 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7040 <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
|
7041 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
|
7042 When called without arguments, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7043 <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
|
7044 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
|
7045 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
|
7046 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
|
7047 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7048 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7049 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7050 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7051 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7052 <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
|
7053 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
|
7054 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
|
7055 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
|
7056 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7057 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7058 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7059 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
|
7060 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
|
7061 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
|
7062 With level 1 (the default), the error position is where the |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7063 <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
|
7064 Level 2 points the error to where the function |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7065 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
|
7066 Passing a level 0 avoids the addition of error position information |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7067 to the message. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7068 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7069 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7070 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7071 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7072 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7073 <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
|
7074 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
|
7075 holds the global environment (see <a href="#2.2">§2.2</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7076 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
|
7077 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
|
7078 nor vice-versa. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7079 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7080 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7081 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7082 |
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 <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
|
7085 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7086 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7087 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7088 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
|
7089 Otherwise, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7090 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
|
7091 returns the associated value. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7092 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
|
7093 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7094 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7095 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7096 |
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 <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
|
7099 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7100 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7101 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7102 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
|
7103 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
|
7104 results from the call. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7105 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7106 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7107 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7108 Otherwise, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7109 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
|
7110 so that the construction |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7111 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7112 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7113 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
|
7114 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7115 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
|
7116 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
|
7117 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7118 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7119 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7120 |
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 <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
|
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 Loads a chunk. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7127 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7128 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7129 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7130 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
|
7131 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
|
7132 <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
|
7133 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
|
7134 with previous results. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7135 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
|
7136 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7137 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7138 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7139 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
|
7140 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
|
7141 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
|
7142 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7143 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7144 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7145 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
|
7146 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
|
7147 if that parameter is given, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7148 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
|
7149 (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
|
7150 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
|
7151 the <code>_ENV</code> variable (see <a href="#2.2">§2.2</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7152 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
|
7153 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
|
7154 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7155 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7156 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7157 <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
|
7158 and debug information (see <a href="#4.9">§4.9</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7159 When absent, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7160 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
|
7161 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
|
7162 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7163 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7164 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7165 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
|
7166 (that is, a precompiled chunk). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7167 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
|
7168 "<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
|
7169 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
|
7170 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
|
7171 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7172 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7173 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7174 |
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 <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
|
7177 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7178 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7179 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7180 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
|
7181 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
|
7182 or from the standard input, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7183 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
|
7184 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7185 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7186 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7187 |
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 <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
|
7190 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7191 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7192 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7193 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
|
7194 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
|
7195 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
|
7196 <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
|
7197 and its associated value. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7198 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
|
7199 <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
|
7200 and its associated value. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7201 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
|
7202 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
|
7203 <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
|
7204 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
|
7205 In particular, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7206 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
|
7207 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7208 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7209 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7210 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
|
7211 <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
|
7212 (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
|
7213 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
|
7214 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7215 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7216 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7217 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
|
7218 during the traversal, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7219 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
|
7220 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
|
7221 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
|
7222 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7223 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7224 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7225 |
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 <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
|
7228 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7229 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7230 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7231 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
|
7232 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
|
7233 results from the call. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7234 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7235 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7236 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7237 Otherwise, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7238 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
|
7239 so that the construction |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7240 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7241 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7242 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
|
7243 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7244 will iterate over all key–value pairs of table <code>t</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7245 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7246 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7247 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7248 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
|
7249 the table during its traversal. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7250 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7251 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7252 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7253 |
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 <hr><h3><a name="pdf-pcall"><code>pcall (f [, arg1, ···])</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7256 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7257 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7258 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7259 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
|
7260 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
|
7261 This means that any error inside <code>f</code> is not propagated; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7262 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
|
7263 and returns a status code. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7264 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
|
7265 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
|
7266 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
|
7267 after this first result. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7268 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
|
7269 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7270 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7271 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7272 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7273 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7274 <hr><h3><a name="pdf-print"><code>print (···)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7275 Receives any number of arguments |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7276 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
|
7277 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
|
7278 <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
|
7279 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
|
7280 for instance for debugging. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7281 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
|
7282 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
|
7283 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7284 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7285 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7286 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7287 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7288 <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
|
7289 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
|
7290 without invoking any metamethod. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7291 Returns a boolean. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7292 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7293 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7294 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7295 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7296 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7297 <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
|
7298 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
|
7299 without invoking any metamethod. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7300 <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
|
7301 <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
|
7302 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7303 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7304 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7305 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7306 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7307 <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
|
7308 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
|
7309 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
|
7310 without invoking any metamethod. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7311 Returns an integer number. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7312 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7313 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7314 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7315 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7316 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7317 <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
|
7318 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
|
7319 without invoking any metamethod. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7320 <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
|
7321 <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
|
7322 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
|
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7326 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
|
7327 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7328 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7329 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7330 |
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 <hr><h3><a name="pdf-select"><code>select (index, ···)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7333 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7334 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7335 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7336 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
|
7337 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
|
7338 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
|
7339 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
|
7340 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
|
7341 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7342 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7343 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7344 |
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 <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
|
7347 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7348 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7349 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7350 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
|
7351 (You cannot change the metatable of other types from Lua, only from C.) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7352 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
|
7353 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
|
7354 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
|
7355 raises an error. |
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7359 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
|
7360 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7361 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7362 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7363 |
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 <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
|
7366 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7367 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7368 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7369 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
|
7370 <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
|
7371 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
|
7372 a string convertible to a number (see <a href="#3.4.2">§3.4.2</a>), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7373 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
|
7374 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
|
7375 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7376 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7377 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7378 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
|
7379 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
|
7380 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
|
7381 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
|
7382 In bases above 10, the letter '<code>A</code>' (in either upper or lower case) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7383 represents 10, '<code>B</code>' represents 11, and so forth, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7384 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
|
7385 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
|
7386 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
|
7387 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7388 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7389 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7390 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7391 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7392 <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
|
7393 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
|
7394 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
|
7395 (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
|
7396 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
|
7397 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7398 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7399 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7400 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
|
7401 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
|
7402 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
|
7403 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
|
7404 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7405 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7406 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7407 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7408 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7409 <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
|
7410 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
|
7411 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
|
7412 "<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
|
7413 "<code>number</code>", |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7414 "<code>string</code>", |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7415 "<code>boolean</code>", |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7416 "<code>table</code>", |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7417 "<code>function</code>", |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7418 "<code>thread</code>", |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7419 and "<code>userdata</code>". |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7420 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7421 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7422 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7423 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7424 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7425 <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
|
7426 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
|
7427 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
|
7428 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
|
7429 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7430 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7431 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7432 |
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 <hr><h3><a name="pdf-xpcall"><code>xpcall (f, msgh [, arg1, ···])</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7435 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7436 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7437 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7438 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
|
7439 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
|
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 |
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7446 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7447 <h2>6.2 – <a name="6.2">Coroutine Manipulation</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7448 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7449 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7450 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
|
7451 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
|
7452 See <a href="#2.6">§2.6</a> for a general description of coroutines. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
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 <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
|
7457 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7458 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7459 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7460 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
|
7461 <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
|
7462 Returns this new coroutine, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7463 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
|
7464 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7465 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7466 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7467 |
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 <hr><h3><a name="pdf-coroutine.resume"><code>coroutine.resume (co [, val1, ···])</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7470 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7471 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7472 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7473 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
|
7474 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
|
7475 it starts running its body. |
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 arguments to the body function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7478 If the coroutine has yielded, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7479 <code>resume</code> restarts it; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7480 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
|
7481 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
|
7482 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7483 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7484 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7485 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
|
7486 <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
|
7487 (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
|
7488 (if the coroutine terminates). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7489 If there is any error, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7490 <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
|
7491 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7492 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7493 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7494 |
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 <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
|
7497 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7498 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7499 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7500 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
|
7501 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
|
7502 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7503 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7504 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7505 |
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 <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
|
7508 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7509 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7510 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7511 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
|
7512 <code>"running"</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7513 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
|
7514 <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
|
7515 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
|
7516 <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
|
7517 (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
|
7518 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
|
7519 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
|
7520 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7521 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7522 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7523 |
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 <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
|
7526 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7527 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7528 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7529 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
|
7530 <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
|
7531 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
|
7532 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
|
7533 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
|
7534 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
|
7535 except the first boolean. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7536 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
|
7537 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7538 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7539 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7540 |
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 <hr><h3><a name="pdf-coroutine.yield"><code>coroutine.yield (···)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7543 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7544 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7545 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7546 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
|
7547 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
|
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 |
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7554 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7555 <h2>6.3 – <a name="6.3">Modules</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7556 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7557 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7558 The package library provides basic |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7559 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
|
7560 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
|
7561 <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
|
7562 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
|
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 <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
|
7567 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7568 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7569 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7570 Loads the given module. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7571 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
|
7572 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
|
7573 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
|
7574 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
|
7575 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
|
7576 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7577 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7578 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7579 To find a loader, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7580 <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
|
7581 By changing this sequence, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7582 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
|
7583 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
|
7584 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
|
7585 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7586 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7587 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7588 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
|
7589 If it has a value, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7590 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
|
7591 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
|
7592 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
|
7593 If that also fails, it searches for a C loader using the |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7594 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
|
7595 If that also fails, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7596 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
|
7597 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7598 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7599 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7600 Once a loader is found, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7601 <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
|
7602 <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
|
7603 (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
|
7604 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
|
7605 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
|
7606 <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
|
7607 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
|
7608 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
|
7609 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
|
7610 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
|
7611 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
|
7612 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7613 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7614 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7615 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
|
7616 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
|
7617 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
|
7618 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7619 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7620 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7621 |
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 <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
|
7624 |
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7627 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
|
7628 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
|
7629 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7630 <ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7631 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7632 <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
|
7633 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
|
7634 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7635 <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
|
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 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
|
7639 substitution points in a template. |
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 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
|
7643 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
|
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 <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
|
7647 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
|
7648 Default is '<code>-</code>'.</li> |
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 </ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7651 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7652 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7653 |
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 <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
|
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 The path used by <a href="#pdf-require"><code>require</code></a> to search for a C loader. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7660 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7661 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7662 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7663 Lua initializes the C path <a href="#pdf-package.cpath"><code>package.cpath</code></a> in the same way |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7664 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
|
7665 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
|
7666 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
|
7667 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
|
7668 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7669 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7670 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7671 |
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 <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
|
7674 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7675 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7676 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7677 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
|
7678 modules are already loaded. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7679 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
|
7680 <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
|
7681 <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
|
7682 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7683 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7684 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7685 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
|
7686 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
|
7687 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
|
7688 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7689 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7690 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7691 |
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 <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
|
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 Dynamically links the host program with the C library <code>libname</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7698 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7699 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7700 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7701 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
|
7702 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
|
7703 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
|
7704 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
|
7705 Otherwise, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7706 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
|
7707 and returns this function as a C function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7708 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
|
7709 (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
|
7710 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7711 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7712 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7713 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
|
7714 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
|
7715 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
|
7716 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
|
7717 does not automatically adds extensions. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7718 <code>libname</code> must be the complete file name of the C library, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7719 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
|
7720 <code>funcname</code> must be the exact name exported by the C library |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7721 (which may depend on the C compiler and linker used). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7722 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7723 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7724 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7725 This function is not supported by Standard C. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7726 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
|
7727 (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
|
7728 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
|
7729 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7730 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7731 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7732 |
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 <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
|
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 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
|
7739 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7740 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7741 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7742 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
|
7743 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
|
7744 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
|
7745 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
|
7746 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
|
7747 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
|
7748 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
|
7749 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7750 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7751 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7752 |
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 <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
|
7755 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7756 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7757 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7758 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
|
7759 (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
|
7760 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7761 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7762 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7763 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
|
7764 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
|
7765 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
|
7766 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7767 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7768 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7769 |
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 <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
|
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 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
|
7776 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7777 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7778 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7779 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
|
7780 When looking for a module, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7781 <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
|
7782 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
|
7783 sole parameter. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7784 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
|
7785 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
|
7786 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
|
7787 (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
|
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 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
|
7792 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7793 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7794 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7795 The 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
|
7796 <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
|
7797 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7798 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7799 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7800 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
|
7801 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
|
7802 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
|
7803 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7804 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7805 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7806 The third searcher looks for a loader as a C library, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7807 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
|
7808 Again, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7809 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
|
7810 For instance, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7811 if the C path is the string |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7812 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7813 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7814 "./?.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
|
7815 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7816 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
|
7817 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
|
7818 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
|
7819 Once it finds a C library, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7820 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
|
7821 application with the library. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7822 Then it tries to find a C function inside the library to |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7823 be used as the loader. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7824 The name of this C function is the string "<code>luaopen_</code>" |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7825 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
|
7826 is replaced by an underscore. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7827 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
|
7828 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
|
7829 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
|
7830 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
|
7831 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7832 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7833 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7834 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
|
7835 It searches the C path for a library for |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7836 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
|
7837 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
|
7838 it will search for a C library for <code>a</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7839 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
|
7840 the submodule; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7841 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
|
7842 With this facility, a package can pack several C submodules |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7843 into one single library, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7844 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
|
7845 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7846 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7847 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7848 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
|
7849 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
|
7850 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
|
7851 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
|
7852 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7853 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7854 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7855 |
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 <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
|
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 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
|
7862 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7863 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7864 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7865 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
|
7866 <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
|
7867 For each template, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7868 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
|
7869 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
|
7870 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
|
7871 (a dot, by default) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7872 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
|
7873 (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
|
7874 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
|
7875 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7876 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7877 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7878 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
|
7879 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7880 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7881 "./?.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
|
7882 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7883 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
|
7884 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
|
7885 <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
|
7886 <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
|
7887 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7888 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7889 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7890 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
|
7891 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
|
7892 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
|
7893 (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
|
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 |
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7900 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7901 <h2>6.4 – <a name="6.4">String Manipulation</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7902 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7903 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7904 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
|
7905 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
|
7906 When indexing a string in Lua, the first character is at position 1 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7907 (not at 0, as in C). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7908 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
|
7909 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
|
7910 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
|
7911 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7912 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7913 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7914 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
|
7915 <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
|
7916 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
|
7917 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
|
7918 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
|
7919 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
|
7920 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
|
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 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
|
7925 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7926 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7927 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7928 <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
|
7929 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
|
7930 <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
|
7931 The default value for <code>i</code> is 1; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7932 the default value for <code>j</code> is <code>i</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7933 These indices are corrected |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7934 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
|
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7938 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
|
7939 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7940 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7941 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7942 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7943 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7944 <hr><h3><a name="pdf-string.char"><code>string.char (···)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7945 Receives zero or more integers. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7946 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
|
7947 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
|
7948 to its corresponding argument. |
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7952 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
|
7953 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7954 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7955 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7956 |
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 <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
|
7959 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7960 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7961 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7962 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
|
7963 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
|
7964 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
|
7965 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7966 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7967 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7968 |
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 <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
|
7971 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7972 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7973 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7974 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
|
7975 <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
|
7976 If it finds a match, then <code>find</code> returns the indices of <code>s</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7977 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
|
7978 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
|
7979 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
|
7980 where to start the search; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7981 its default value is 1 and can be negative. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7982 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
|
7983 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
|
7984 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
|
7985 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
|
7986 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
|
7987 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7988 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7989 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7990 If the pattern has captures, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7991 then in a successful match |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7992 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
|
7993 after the two indices. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7994 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7995 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7996 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7997 |
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 <hr><h3><a name="pdf-string.format"><code>string.format (formatstring, ···)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8000 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8001 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8002 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8003 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
|
8004 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
|
8005 The format string follows the same rules as the ANSI C function <code>sprintf</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8006 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
|
8007 <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
|
8008 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
|
8009 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
|
8010 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
|
8011 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
|
8012 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
|
8013 For instance, the call |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8014 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8015 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8016 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
|
8017 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8018 may produce the string: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8019 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8020 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8021 "a string with \"quotes\" and \ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8022 new line" |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8023 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8024 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8025 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8026 Options |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8027 <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
|
8028 <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
|
8029 <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
|
8030 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
|
8031 <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
|
8032 also expect a number, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8033 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
|
8034 the underlying C implementation. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8035 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
|
8036 the number cannot be negative. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8037 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
|
8038 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
|
8039 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
|
8040 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
|
8041 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8042 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8043 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8044 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8045 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8046 <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
|
8047 Returns an iterator function that, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8048 each time it is called, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8049 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
|
8050 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
|
8051 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
|
8052 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8053 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8054 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8055 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
|
8056 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
|
8057 printing one per line: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8058 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8059 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8060 s = "hello world from Lua" |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8061 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
|
8062 print(w) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8063 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8064 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8065 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
|
8066 given string into a table: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8067 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8068 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8069 t = {} |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8070 s = "from=world, to=Lua" |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8071 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
|
8072 t[k] = v |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8073 end |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8074 </pre> |
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8077 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
|
8078 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
|
8079 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8080 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8081 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8082 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8083 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8084 <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
|
8085 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
|
8086 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
|
8087 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
|
8088 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
|
8089 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
|
8090 <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
|
8091 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
|
8092 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
|
8093 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8094 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8095 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8096 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
|
8097 The character <code>%</code> works as an escape character: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8098 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
|
8099 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
|
8100 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
|
8101 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
|
8102 The sequence <code>%%</code> stands for a single <code>%</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8103 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8104 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8105 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8106 If <code>repl</code> is a 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
|
8107 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
|
8108 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8109 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8110 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8111 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
|
8112 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
|
8113 in order. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8114 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8115 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8116 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8117 In any case, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8118 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
|
8119 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
|
8120 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8121 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8122 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8123 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
|
8124 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
|
8125 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
|
8126 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
|
8127 then there is no replacement |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8128 (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
|
8129 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8130 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8131 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8132 Here are some examples: |
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 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8135 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
|
8136 --> x="hello hello world world" |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8137 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8138 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
|
8139 --> x="hello hello world" |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8140 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8141 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
|
8142 --> x="world hello Lua from" |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8143 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8144 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
|
8145 --> 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
|
8146 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8147 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
|
8148 return load(s)() |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8149 end) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8150 --> x="4+5 = 9" |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8151 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8152 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
|
8153 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
|
8154 --> 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
|
8155 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8156 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8157 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8158 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8159 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8160 <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
|
8161 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
|
8162 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
|
8163 Embedded zeros are counted, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8164 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
|
8165 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8166 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8167 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8168 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8169 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8170 <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
|
8171 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
|
8172 uppercase letters changed to lowercase. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8173 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
|
8174 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
|
8175 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8176 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8177 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8178 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8179 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8180 <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
|
8181 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
|
8182 <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
|
8183 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
|
8184 the captures from the pattern; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8185 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
|
8186 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
|
8187 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
|
8188 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
|
8189 where to start the search; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8190 its default value is 1 and can be negative. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8191 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8192 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8193 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8194 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8195 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8196 <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
|
8197 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
|
8198 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
|
8199 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
|
8200 (that is, no separator). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8201 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8202 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8203 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8204 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8205 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8206 <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
|
8207 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
|
8208 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8209 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8210 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8211 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8212 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8213 <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
|
8214 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
|
8215 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
|
8216 <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
|
8217 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
|
8218 (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
|
8219 In particular, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8220 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
|
8221 with length <code>j</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8222 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
|
8223 with length <code>i</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8224 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8225 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8226 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8227 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
|
8228 <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
|
8229 it is corrected to 1. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8230 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
|
8231 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
|
8232 If, after these corrections, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8233 <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
|
8234 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
|
8235 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8236 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8237 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8238 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8239 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8240 <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
|
8241 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
|
8242 lowercase letters changed to uppercase. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8243 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
|
8244 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
|
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8248 <h3>6.4.1 – <a name="6.4.1">Patterns</a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8249 |
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 <h4>Character Class:</h4><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8252 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
|
8253 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
|
8254 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8255 <ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8256 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8257 <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
|
8258 (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
|
8259 <code>^$()%.[]*+-?</code>) |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8260 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
|
8261 </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>.</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
|
8264 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8265 <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
|
8266 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8267 <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
|
8268 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8269 <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
|
8270 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8271 <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
|
8272 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8273 <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
|
8274 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8275 <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
|
8276 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8277 <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
|
8278 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8279 <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
|
8280 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8281 <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
|
8282 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8283 <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
|
8284 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8285 <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
|
8286 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
|
8287 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
|
8288 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
|
8289 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
|
8290 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
|
8291 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8292 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8293 <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
|
8294 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
|
8295 characters in <em>set</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8296 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
|
8297 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
|
8298 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
|
8299 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
|
8300 components in <em>set</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8301 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
|
8302 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
|
8303 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
|
8304 <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
|
8305 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
|
8306 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
|
8307 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8308 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8309 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8310 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
|
8311 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
|
8312 have no meaning. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8313 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8314 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8315 <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
|
8316 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
|
8317 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
|
8318 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8319 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8320 </ul><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8321 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
|
8322 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
|
8323 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
|
8324 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8325 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8326 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8327 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
|
8328 depend on the current locale. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8329 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
|
8330 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8331 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8332 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8333 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8334 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8335 <h4>Pattern Item:</h4><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8336 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
|
8337 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8338 <ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8339 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8340 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8341 a single character class, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8342 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
|
8343 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8344 |
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 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
|
8347 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
|
8348 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
|
8349 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8350 |
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 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
|
8353 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
|
8354 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
|
8355 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8356 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8357 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8358 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
|
8359 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
|
8360 Unlike '<code>*</code>', |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8361 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
|
8362 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8363 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8364 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8365 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
|
8366 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
|
8367 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8368 |
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 <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
|
8371 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
|
8372 (see below); |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8373 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8374 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8375 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8376 <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
|
8377 such item matches strings that start with <em>x</em>, end with <em>y</em>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8378 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
|
8379 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
|
8380 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
|
8381 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
|
8382 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
|
8383 balanced parentheses. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8384 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8385 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8386 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8387 <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
|
8388 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
|
8389 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
|
8390 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
|
8391 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
|
8392 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
|
8393 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
|
8394 </li> |
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 </ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8397 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8398 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8399 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8400 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8401 <h4>Pattern:</h4><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8402 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
|
8403 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
|
8404 beginning of the subject string. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8405 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
|
8406 end of the subject string. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8407 At other positions, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8408 '<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
|
8409 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8410 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8411 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8412 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8413 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8414 <h4>Captures:</h4><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8415 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
|
8416 they describe <em>captures</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8417 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
|
8418 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
|
8419 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
|
8420 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
|
8421 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
|
8422 stored as the first capture (and therefore has number 1); |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8423 the character matching "<code>.</code>" is captured with number 2, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8424 and the part matching "<code>%s*</code>" has number 3. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8425 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8426 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8427 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8428 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
|
8429 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
|
8430 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
|
8431 string <code>"flaaap"</code>, there will be two captures: 3 and 5. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
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 |
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8442 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8443 <h2>6.5 – <a name="6.5">Table Manipulation</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8444 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8445 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8446 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
|
8447 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
|
8448 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8449 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8450 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8451 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
|
8452 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
|
8453 or have a <code>__len</code> metamethod (see <a href="#3.4.6">§3.4.6</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8454 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
|
8455 in tables given as arguments. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8456 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8457 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8458 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8459 For performance reasons, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8460 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
|
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 <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
|
8465 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8466 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8467 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8468 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
|
8469 returns the string <code>list[i]..sep..list[i+1] ··· sep..list[j]</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8470 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
|
8471 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
|
8472 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
|
8473 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
|
8474 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8475 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8476 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8477 |
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 <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
|
8480 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8481 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8482 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8483 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
|
8484 shifting up the elements |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8485 <code>list[pos], list[pos+1], ···, list[#list]</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8486 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
|
8487 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
|
8488 of list <code>t</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8489 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8490 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8491 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8492 |
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 <hr><h3><a name="pdf-table.pack"><code>table.pack (···)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8495 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8496 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8497 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8498 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
|
8499 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
|
8500 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
|
8501 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8502 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8503 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8504 |
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 <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
|
8507 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8508 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8509 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8510 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
|
8511 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
|
8512 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
|
8513 it shifts down the elements |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8514 <code>list[pos+1], list[pos+2], ···, list[#list]</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8515 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
|
8516 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
|
8517 or <code>#list + 1</code>; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8518 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
|
8519 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8520 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8521 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8522 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
|
8523 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
|
8524 of list <code>t</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8525 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8526 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8527 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8528 |
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 <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
|
8531 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8532 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8533 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8534 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
|
8535 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
|
8536 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
|
8537 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
|
8538 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
|
8539 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
|
8540 (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
|
8541 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
|
8542 then the standard Lua operator <code><</code> is used instead. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8543 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8544 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8545 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8546 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
|
8547 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
|
8548 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
|
8549 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8550 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8551 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8552 |
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 <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
|
8555 |
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8558 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
|
8559 This function is equivalent to |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8560 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8561 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8562 return list[i], list[i+1], ···, list[j] |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8563 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8564 By default, <code>i</code> is 1 and <code>j</code> is <code>#list</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
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 |
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8571 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8572 <h2>6.6 – <a name="6.6">Mathematical Functions</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8573 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8574 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8575 This library is an interface to the standard C math library. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8576 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
|
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 <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
|
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8584 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
|
8585 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8586 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8587 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8588 |
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 <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
|
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8594 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
|
8595 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8596 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8597 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8598 |
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 <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
|
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8604 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
|
8605 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8606 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8607 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8608 |
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 <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
|
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8614 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
|
8615 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8616 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8617 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8618 |
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 <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
|
8621 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8622 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8623 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8624 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
|
8625 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
|
8626 quadrant of the result. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8627 (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
|
8628 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8629 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8630 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8631 |
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 <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
|
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8637 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
|
8638 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8639 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8640 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8641 |
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 <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
|
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8647 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
|
8648 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8649 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8650 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8651 |
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 <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
|
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8657 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
|
8658 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8659 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8660 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8661 |
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 <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
|
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8667 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
|
8668 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8669 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8670 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8671 |
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 <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
|
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8677 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
|
8678 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8679 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8680 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8681 |
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 <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
|
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8687 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
|
8688 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8689 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8690 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8691 |
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 <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
|
8694 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8695 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8696 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8697 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
|
8698 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
|
8699 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8700 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8701 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8702 |
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 <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
|
8705 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8706 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8707 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8708 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
|
8709 <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
|
8710 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
|
8711 (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
|
8712 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8713 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8714 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8715 |
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 <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
|
8718 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8719 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8720 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8721 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
|
8722 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
|
8723 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8724 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8725 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8726 |
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 <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
|
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8732 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
|
8733 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8734 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8735 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8736 |
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 <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
|
8739 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8740 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8741 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8742 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
|
8743 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
|
8744 (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
|
8745 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8746 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8747 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8748 |
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 <hr><h3><a name="pdf-math.max"><code>math.max (x, ···)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8754 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
|
8755 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8756 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8757 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8758 |
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 <hr><h3><a name="pdf-math.min"><code>math.min (x, ···)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8764 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
|
8765 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8766 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8767 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8768 |
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 <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
|
8771 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8772 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8773 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8774 Returns two numbers, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8775 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
|
8776 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8777 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8778 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8779 |
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 <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
|
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8785 The value of <em>π</em>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8786 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8787 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8788 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8789 |
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 <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
|
8792 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8793 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8794 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8795 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
|
8796 (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
|
8797 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8798 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8799 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8800 |
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 <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
|
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8806 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
|
8807 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8808 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8809 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8810 |
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 <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
|
8813 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8814 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8815 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8816 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
|
8817 pseudo-random generator function <code>rand</code> provided by Standard C. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8818 (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
|
8819 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8820 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8821 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8822 When called without arguments, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8823 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
|
8824 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
|
8825 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
|
8826 <code>math.random</code> returns |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8827 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
|
8828 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
|
8829 <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
|
8830 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
|
8831 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8832 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8833 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8834 |
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 <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
|
8837 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8838 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8839 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8840 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
|
8841 for the pseudo-random generator: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8842 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
|
8843 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8844 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8845 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8846 |
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 <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
|
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8852 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
|
8853 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8854 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8855 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8856 |
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 <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
|
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8862 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
|
8863 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8864 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8865 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8866 |
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 <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
|
8869 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8870 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8871 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8872 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
|
8873 (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
|
8874 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8875 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8876 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8877 |
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 <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
|
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8883 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
|
8884 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8885 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8886 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8887 |
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 <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
|
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8893 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
|
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 |
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8900 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8901 <h2>6.7 – <a name="6.7">Bitwise Operations</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8902 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8903 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8904 This library provides bitwise operations. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8905 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
|
8906 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8907 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8908 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8909 Unless otherwise stated, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8910 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
|
8911 <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
|
8912 each argument is normalized to |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8913 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
|
8914 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
|
8915 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
|
8916 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
|
8917 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
|
8918 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
|
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 <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
|
8923 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8924 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8925 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8926 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
|
8927 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
|
8928 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
|
8929 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8930 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8931 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8932 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
|
8933 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
|
8934 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
|
8935 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
|
8936 In particular, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8937 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
|
8938 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
|
8939 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8940 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8941 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8942 |
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 <hr><h3><a name="pdf-bit32.band"><code>bit32.band (···)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8948 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
|
8949 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8950 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8951 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8952 |
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 <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
|
8955 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8956 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8957 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8958 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
|
8959 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
|
8960 the following identity holds: |
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 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8963 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
|
8964 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8965 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8966 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8967 |
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 <hr><h3><a name="pdf-bit32.bor"><code>bit32.bor (···)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8973 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
|
8974 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8975 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8976 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8977 |
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 <hr><h3><a name="pdf-bit32.btest"><code>bit32.btest (···)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8980 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8981 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8982 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8983 Returns a boolean signaling |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8984 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
|
8985 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8986 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8987 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8988 |
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 <hr><h3><a name="pdf-bit32.bxor"><code>bit32.bxor (···)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8994 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
|
8995 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8996 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8997 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8998 |
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 <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
|
9001 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9002 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9003 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9004 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
|
9005 <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
|
9006 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
|
9007 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
|
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9011 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
|
9012 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9013 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9014 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9015 |
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 <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
|
9018 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9019 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9020 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9021 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
|
9022 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
|
9023 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
|
9024 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
|
9025 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9026 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9027 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9028 |
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 <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
|
9031 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9032 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9033 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9034 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
|
9035 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
|
9036 |
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9039 For any valid displacement, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9040 the following identity holds: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9041 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9042 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9043 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
|
9044 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9045 In particular, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9046 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
|
9047 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9048 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9049 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9050 |
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 <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
|
9053 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9054 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9055 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9056 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
|
9057 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
|
9058 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
|
9059 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
|
9060 In particular, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9061 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
|
9062 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
|
9063 |
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9066 For positive displacements, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9067 the following equality holds: |
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 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9070 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
|
9071 </pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9072 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9073 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9074 |
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 <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
|
9077 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9078 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9079 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9080 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
|
9081 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
|
9082 |
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9085 For any valid displacement, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9086 the following identity holds: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9087 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9088 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9089 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
|
9090 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9091 In particular, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9092 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
|
9093 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9094 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9095 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9096 |
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 <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
|
9099 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9100 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9101 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9102 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
|
9103 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
|
9104 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
|
9105 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
|
9106 In particular, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9107 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
|
9108 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
|
9109 |
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9112 For positive displacements, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9113 the following equality holds: |
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 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9116 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
|
9117 </pre> |
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9120 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
|
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 |
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9127 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9128 <h2>6.8 – <a name="6.8">Input and Output Facilities</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9129 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9130 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9131 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
|
9132 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
|
9133 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
|
9134 default output file, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9135 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
|
9136 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
|
9137 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9138 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9139 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9140 When using implicit file descriptors, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9141 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
|
9142 When using explicit file descriptors, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9143 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
|
9144 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
|
9145 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9146 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9147 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9148 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
|
9149 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
|
9150 <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
|
9151 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
|
9152 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9153 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9154 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9155 Unless otherwise stated, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9156 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
|
9157 (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
|
9158 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
|
9159 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
|
9160 On non-Posix systems, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9161 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
|
9162 in case of errors |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9163 may be not thread safe, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9164 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
|
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 <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
|
9169 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9170 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9171 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9172 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
|
9173 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
|
9174 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9175 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9176 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9177 |
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 <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
|
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9183 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
|
9184 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9185 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9186 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9187 |
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 <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
|
9190 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9191 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9192 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9193 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
|
9194 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
|
9195 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
|
9196 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
|
9197 When called without parameters, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9198 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
|
9199 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9200 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9201 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9202 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
|
9203 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
|
9204 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9205 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9206 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9207 |
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 <hr><h3><a name="pdf-io.lines"><code>io.lines ([filename ···])</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9210 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9211 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9212 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9213 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
|
9214 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
|
9215 works like <code>file:lines(···)</code> over the opened file. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9216 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
|
9217 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
|
9218 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9219 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9220 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9221 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
|
9222 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
|
9223 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
|
9224 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
|
9225 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9226 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9227 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9228 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
|
9229 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
|
9230 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9231 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9232 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9233 |
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 <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
|
9236 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9237 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9238 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9239 This function opens a file, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9240 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
|
9241 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
|
9242 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
|
9243 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9244 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9245 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9246 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
|
9247 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9248 <ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9249 <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
|
9250 <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
|
9251 <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
|
9252 <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
|
9253 <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
|
9254 <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
|
9255 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
|
9256 </ul><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9257 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
|
9258 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
|
9259 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9260 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9261 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9262 |
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 <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
|
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9268 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
|
9269 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9270 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9271 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9272 |
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 <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
|
9275 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9276 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9277 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9278 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
|
9279 on all platforms. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9280 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9281 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9282 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9283 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
|
9284 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
|
9285 (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
|
9286 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
|
9287 (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
|
9288 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9289 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9290 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9291 |
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 <hr><h3><a name="pdf-io.read"><code>io.read (···)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9297 Equivalent to <code>io.input():read(···)</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9298 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9299 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9300 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9301 |
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 <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
|
9304 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9305 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9306 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9307 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
|
9308 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
|
9309 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
|
9310 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9311 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9312 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9313 |
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 <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
|
9316 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9317 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9318 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9319 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
|
9320 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
|
9321 <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
|
9322 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
|
9323 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9324 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9325 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9326 |
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 <hr><h3><a name="pdf-io.write"><code>io.write (···)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9332 Equivalent to <code>io.output():write(···)</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9333 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9334 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9335 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9336 |
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 <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
|
9339 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9340 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9341 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9342 Closes <code>file</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9343 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
|
9344 their handles are garbage collected, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9345 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
|
9346 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9347 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9348 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9349 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
|
9350 <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
|
9351 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
|
9352 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9353 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9354 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9355 |
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 <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
|
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9361 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
|
9362 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9363 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9364 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9365 |
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 <hr><h3><a name="pdf-file:lines"><code>file:lines (···)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9368 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9369 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9370 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9371 Returns an iterator function that, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9372 each time it is called, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9373 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
|
9374 When no format is given, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9375 uses "*l" as a default. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9376 As an example, the construction |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9377 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9378 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9379 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
|
9380 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9381 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
|
9382 starting at the current position. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9383 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
|
9384 when the loop ends. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9385 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9386 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9387 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9388 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
|
9389 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
|
9390 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9391 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9392 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9393 |
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 <hr><h3><a name="pdf-file:read"><code>file:read (···)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9396 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9397 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9398 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9399 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
|
9400 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
|
9401 For each format, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9402 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
|
9403 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
|
9404 When called without formats, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9405 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
|
9406 (see below). |
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9409 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9410 The available formats are |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9411 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9412 <ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9413 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9414 <li><b>"<code>*n</code>": </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9415 reads a number; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9416 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
|
9417 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9418 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9419 <li><b>"<code>*a</code>": </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9420 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
|
9421 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
|
9422 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9423 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9424 <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
|
9425 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
|
9426 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
|
9427 This is the default format. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9428 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9429 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9430 <li><b>"<code>*L</code>": </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9431 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
|
9432 returning <b>nil</b> on end of file. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9433 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9434 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9435 <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
|
9436 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
|
9437 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
|
9438 If number is zero, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9439 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
|
9440 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
|
9441 </li> |
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 </ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9444 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9445 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9446 |
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 <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
|
9449 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9450 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9451 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9452 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
|
9453 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
|
9454 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
|
9455 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
|
9456 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9457 <ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9458 <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
|
9459 <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
|
9460 <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
|
9461 </ul><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9462 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
|
9463 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
|
9464 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
|
9465 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
|
9466 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9467 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9468 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9469 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
|
9470 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
|
9471 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
|
9472 file position, without changing it; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9473 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
|
9474 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
|
9475 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
|
9476 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
|
9477 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9478 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9479 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9480 |
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 <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
|
9483 |
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9486 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
|
9487 There are three available modes: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9488 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9489 <ul> |
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>no</code>": </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9492 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
|
9493 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9494 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9495 <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
|
9496 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
|
9497 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
|
9498 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
|
9499 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9500 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9501 <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
|
9502 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
|
9503 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
|
9504 (such as a terminal device). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9505 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9506 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9507 </ul><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9508 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
|
9509 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
|
9510 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
|
9511 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9512 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9513 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9514 |
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 <hr><h3><a name="pdf-file:write"><code>file:write (···)</code></a></h3> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9517 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9518 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9519 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9520 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
|
9521 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
|
9522 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9523 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9524 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9525 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
|
9526 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
|
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 |
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9533 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9534 <h2>6.9 – <a name="6.9">Operating System Facilities</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
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 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
|
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 <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
|
9542 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9543 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9544 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9545 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
|
9546 used by the program. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9547 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9548 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9549 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9550 |
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 <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
|
9553 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9554 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9555 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9556 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
|
9557 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
|
9558 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9559 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9560 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9561 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
|
9562 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
|
9563 (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
|
9564 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
|
9565 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9566 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9567 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9568 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
|
9569 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
|
9570 After this optional character, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9571 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
|
9572 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
|
9573 <code>year</code> (four digits), <code>month</code> (1–12), <code>day</code> (1–31), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9574 <code>hour</code> (0–23), <code>min</code> (0–59), <code>sec</code> (0–61), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9575 <code>wday</code> (weekday, Sunday is 1), |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9576 <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
|
9577 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
|
9578 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
|
9579 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
|
9580 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9581 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9582 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9583 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
|
9584 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
|
9585 formatted according to the same rules as the ANSI C function <code>strftime</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9586 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9587 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9588 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9589 When called without arguments, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9590 <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
|
9591 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
|
9592 (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
|
9593 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9594 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9595 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9596 On non-Posix systems, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9597 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
|
9598 because of its reliance on C function <code>gmtime</code> and C function <code>localtime</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9599 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9600 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9601 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9602 |
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 <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
|
9605 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9606 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9607 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9608 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
|
9609 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
|
9610 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
|
9611 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9612 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9613 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9614 |
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 <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
|
9617 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9618 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9619 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9620 This function is equivalent to the ANSI C function <code>system</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9621 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
|
9622 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
|
9623 if the command terminated successfully, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9624 or <b>nil</b> otherwise. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9625 After this first result |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9626 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
|
9627 as follows: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9628 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9629 <ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9630 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9631 <li><b>"<code>exit</code>": </b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9632 the command terminated normally; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9633 the following number is the exit status of the command. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9634 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9635 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9636 <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
|
9637 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
|
9638 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
|
9639 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9640 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9641 </ul> |
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9644 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
|
9645 <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
|
9646 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9647 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9648 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9649 |
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 <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
|
9652 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9653 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9654 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9655 Calls the ANSI C function <code>exit</code> to terminate the host program. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9656 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
|
9657 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
|
9658 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
|
9659 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
|
9660 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
|
9661 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
|
9662 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
|
9663 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9664 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9665 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9666 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
|
9667 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
|
9668 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9669 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9670 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9671 |
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 <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
|
9674 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9675 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9676 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9677 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
|
9678 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
|
9679 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9680 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9681 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9682 |
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 <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
|
9685 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9686 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9687 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9688 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
|
9689 with the given name. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9690 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
|
9691 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
|
9692 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9693 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9694 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9695 |
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 <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
|
9698 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9699 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9700 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9701 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
|
9702 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
|
9703 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
|
9704 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9705 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9706 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9707 |
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 <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
|
9710 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9711 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9712 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9713 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
|
9714 <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
|
9715 <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
|
9716 <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
|
9717 <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
|
9718 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
|
9719 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
|
9720 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
|
9721 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9722 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9723 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9724 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
|
9725 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
|
9726 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
|
9727 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
|
9728 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9729 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9730 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9731 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
|
9732 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
|
9733 for the given category. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9734 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9735 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9736 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9737 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
|
9738 because of its reliance on C function <code>setlocale</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9739 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9740 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9741 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9742 |
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 <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
|
9745 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9746 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9747 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9748 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
|
9749 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
|
9750 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
|
9751 and may have fields |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9752 <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
|
9753 <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
|
9754 <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
|
9755 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
|
9756 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
|
9757 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9758 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9759 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9760 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
|
9761 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
|
9762 this number counts the number |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9763 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
|
9764 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
|
9765 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
|
9766 <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
|
9767 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9768 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9769 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9770 |
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 <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
|
9773 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9774 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9775 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9776 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
|
9777 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
|
9778 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
|
9779 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
|
9780 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9781 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9782 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9783 On POSIX systems, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9784 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
|
9785 to avoid security risks. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9786 (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
|
9787 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
|
9788 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
|
9789 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
|
9790 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9791 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9792 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9793 When possible, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9794 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
|
9795 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
|
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 |
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9802 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9803 <h2>6.10 – <a name="6.10">The Debug Library</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9804 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9805 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9806 This library provides |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9807 the functionality of the debug interface (<a href="#4.9">§4.9</a>) to Lua programs. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9808 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
|
9809 Several of its functions |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9810 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
|
9811 (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
|
9812 cannot be accessed from outside; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9813 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
|
9814 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
|
9815 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
|
9816 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
|
9817 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9818 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9819 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9820 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
|
9821 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
|
9822 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
|
9823 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
|
9824 thread to operate over. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9825 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
|
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 <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
|
9830 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9831 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9832 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9833 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
|
9834 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
|
9835 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
|
9836 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
|
9837 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
|
9838 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
|
9839 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
|
9840 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9841 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9842 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9843 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
|
9844 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
|
9845 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9846 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9847 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9848 |
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 <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
|
9851 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9852 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9853 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9854 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
|
9855 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
|
9856 and the current hook count |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9857 (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
|
9858 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9859 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9860 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9861 |
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 <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
|
9864 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9865 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9866 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9867 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
|
9868 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
|
9869 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
|
9870 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
|
9871 of the given thread: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9872 level 0 is the current function (<code>getinfo</code> itself); |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9873 level 1 is the function that called <code>getinfo</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9874 (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
|
9875 and so on. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9876 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
|
9877 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
|
9878 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9879 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9880 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9881 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
|
9882 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
|
9883 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
|
9884 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
|
9885 If present, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9886 the option '<code>f</code>' |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9887 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
|
9888 If present, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9889 the option '<code>L</code>' |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9890 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
|
9891 valid lines. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9892 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9893 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9894 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9895 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
|
9896 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
|
9897 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
|
9898 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
|
9899 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
|
9900 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
|
9901 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9902 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9903 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9904 |
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 <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
|
9907 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9908 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9909 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9910 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
|
9911 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
|
9912 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
|
9913 but also parameters, temporaries, etc. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9914 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9915 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9916 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9917 The first parameter or local variable has index 1, and so on, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9918 until the last active variable. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9919 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
|
9920 -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
|
9921 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
|
9922 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
|
9923 (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
|
9924 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9925 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9926 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9927 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
|
9928 represent internal variables |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9929 (loop control variables, temporaries, varargs, and C function locals). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9930 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9931 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9932 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9933 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
|
9934 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
|
9935 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9936 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9937 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9938 |
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 <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
|
9941 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9942 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9943 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9944 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
|
9945 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
|
9946 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9947 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9948 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9949 |
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 <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
|
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9955 Returns the registry table (see <a href="#4.5">§4.5</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9956 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9957 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9958 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9959 |
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 <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
|
9962 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9963 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9964 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9965 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
|
9966 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
|
9967 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
|
9968 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9969 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9970 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9971 |
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 <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
|
9974 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9975 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9976 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9977 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
|
9978 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
|
9979 returns <b>nil</b>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9980 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9981 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9982 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9983 |
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 <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
|
9986 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9987 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9988 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9989 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
|
9990 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
|
9991 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
|
9992 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
|
9993 with the given meaning: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9994 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9995 <ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9996 <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
|
9997 <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
|
9998 <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
|
9999 </ul><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10000 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
|
10001 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
|
10002 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10003 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10004 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10005 When called without arguments, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10006 <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
|
10007 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10008 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10009 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10010 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
|
10011 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
|
10012 <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
|
10013 <code>"return"</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10014 <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
|
10015 For line events, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10016 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
|
10017 Inside a hook, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10018 you can call <code>getinfo</code> with level 2 to get more information about |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10019 the running function |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10020 (level 0 is the <code>getinfo</code> function, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10021 and level 1 is the hook function). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10022 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10023 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10024 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10025 |
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 <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
|
10028 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10029 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10030 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10031 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
|
10032 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
|
10033 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
|
10034 variable with the given index, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10035 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
|
10036 (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
|
10037 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
|
10038 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10039 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10040 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10041 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
|
10042 variable indices and names. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10043 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10044 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10045 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10046 |
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 <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
|
10049 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10050 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10051 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10052 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
|
10053 (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
|
10054 Returns <code>value</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10055 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10056 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10057 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10058 |
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 <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
|
10061 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10062 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10063 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10064 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
|
10065 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
|
10066 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
|
10067 with the given index. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10068 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
|
10069 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10070 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10071 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10072 |
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 <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
|
10075 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10076 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10077 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10078 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
|
10079 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
|
10080 <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
|
10081 <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
|
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10085 Returns <code>udata</code>. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10086 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10087 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10088 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10089 |
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 <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
|
10092 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10093 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10094 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10095 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
|
10096 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
|
10097 Otherwise, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10098 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
|
10099 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
|
10100 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
|
10101 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
|
10102 to start the traceback |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10103 (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
|
10104 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10105 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10106 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10107 |
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 <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
|
10110 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10111 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10112 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10113 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
|
10114 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
|
10115 from the given function. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10116 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10117 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10118 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10119 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
|
10120 closures share upvalues. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10121 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
|
10122 (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
|
10123 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
|
10124 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10125 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10126 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10127 |
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 <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
|
10130 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10131 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10132 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10133 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
|
10134 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
|
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 |
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10141 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10142 <h1>7 – <a name="7">Lua Standalone</a></h1> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10143 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10144 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10145 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
|
10146 to be embedded in a host C program, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10147 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
|
10148 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
|
10149 called simply <code>lua</code>, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10150 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
|
10151 The standalone interpreter includes |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10152 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
|
10153 Its usage is: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10154 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10155 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10156 lua [options] [script [args]] |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10157 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10158 The options are: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10159 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10160 <ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10161 <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
|
10162 <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
|
10163 <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
|
10164 <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
|
10165 <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
|
10166 <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
|
10167 <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
|
10168 </ul><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10169 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
|
10170 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
|
10171 When called without arguments, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10172 <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
|
10173 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
|
10174 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
|
10175 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10176 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10177 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10178 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
|
10179 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
|
10180 (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
|
10181 before running any argument. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10182 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
|
10183 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
|
10184 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
|
10185 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10186 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10187 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10188 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
|
10189 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
|
10190 Lua also ignores |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10191 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
|
10192 setting the values of |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10193 <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
|
10194 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
|
10195 |
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 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10198 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
|
10199 For instance, an invocation like |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10200 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10201 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10202 $ 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
|
10203 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10204 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
|
10205 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
|
10206 (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
|
10207 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10208 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10209 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10210 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
|
10211 <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
|
10212 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
|
10213 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
|
10214 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
|
10215 and so on. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10216 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
|
10217 (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
|
10218 go to negative indices. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10219 For instance, in the call |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10220 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10221 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10222 $ 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
|
10223 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10224 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
|
10225 then creates a table |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10226 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10227 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10228 arg = { [-2] = "lua", [-1] = "-la", |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10229 [0] = "b.lua", |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10230 [1] = "t1", [2] = "t2" } |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10231 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10232 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
|
10233 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
|
10234 as arguments; |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10235 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
|
10236 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10237 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10238 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10239 In interactive mode, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10240 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
|
10241 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
|
10242 by issuing a different prompt. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10243 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10244 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10245 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10246 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
|
10247 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
|
10248 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
|
10249 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
|
10250 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
|
10251 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
|
10252 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
|
10253 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
|
10254 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10255 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10256 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10257 When finishing normally, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10258 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
|
10259 (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
|
10260 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
|
10261 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
|
10262 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10263 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10264 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10265 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
|
10266 script interpreter in Unix systems, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10267 the standalone interpreter skips |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10268 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
|
10269 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
|
10270 by using <code>chmod +x</code> and the <code>#!</code> form, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10271 as in |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10272 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10273 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10274 #!/usr/local/bin/lua |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10275 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10276 (Of course, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10277 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
|
10278 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
|
10279 then |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10280 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10281 <pre> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10282 #!/usr/bin/env lua |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10283 </pre><p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10284 is a more portable solution.) |
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10287 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10288 <h1>8 – <a name="8">Incompatibilities with the Previous Version</a></h1> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10289 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10290 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10291 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
|
10292 from Lua 5.1 to Lua 5.2. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10293 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
|
10294 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
|
10295 However, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10296 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
|
10297 Similarly, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10298 all features marked as deprecated in Lua 5.1 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10299 have been removed in Lua 5.2. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10300 |
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10303 <h2>8.1 – <a name="8.1">Changes in the Language</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10304 <ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10305 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10306 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10307 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
|
10308 Only Lua functions have environments. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10309 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
|
10310 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
|
10311 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10312 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10313 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10314 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
|
10315 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
|
10316 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
|
10317 (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
|
10318 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
|
10319 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10320 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10321 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10322 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
|
10323 (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
|
10324 use the new functions |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10325 <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
|
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 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
|
10330 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10331 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10332 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10333 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
|
10334 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
|
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 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
|
10339 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10340 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10341 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10342 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
|
10343 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
|
10344 <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
|
10345 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
|
10346 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10347 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10348 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10349 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
|
10350 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
|
10351 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
|
10352 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
|
10353 </li> |
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 </ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10356 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10357 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10358 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10359 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10360 <h2>8.2 – <a name="8.2">Changes in the Libraries</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10361 <ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10362 |
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 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
|
10365 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
|
10366 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
|
10367 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10368 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10369 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10370 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
|
10371 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
|
10372 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10373 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10374 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10375 Function <code>math.log10</code> is deprecated. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10376 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
|
10377 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10378 |
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 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
|
10381 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
|
10382 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
|
10383 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10384 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10385 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10386 Function <code>table.maxn</code> is deprecated. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10387 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
|
10388 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10389 |
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 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
|
10392 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
|
10393 otherwise. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10394 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10395 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10396 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10397 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
|
10398 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
|
10399 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10400 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10401 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10402 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
|
10403 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
|
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 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
|
10408 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10409 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10410 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10411 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
|
10412 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
|
10413 (<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
|
10414 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
|
10415 (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
|
10416 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
|
10417 When in doubt, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10418 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
|
10419 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
|
10420 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10421 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10422 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10423 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
|
10424 change between versions. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10425 </li> |
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 </ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10428 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10429 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10430 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10431 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10432 <h2>8.3 – <a name="8.3">Changes in the API</a></h2> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10433 <ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10434 |
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 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
|
10437 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
|
10438 (see <a href="#4.5">§4.5</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10439 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10440 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10441 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10442 Pseudoindex <code>LUA_ENVIRONINDEX</code> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10443 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
|
10444 were removed, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10445 as C functions no longer have environments. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10446 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10447 |
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 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
|
10450 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
|
10451 (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
|
10452 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10453 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10454 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10455 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
|
10456 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
|
10457 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
|
10458 (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
|
10459 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
|
10460 the block is new. |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10461 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10462 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10463 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10464 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
|
10465 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
|
10466 not that they were created (see <a href="#2.5.1">§2.5.1</a>). |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10467 (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
|
10468 Moreover, |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10469 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
|
10470 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
|
10471 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
|
10472 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10473 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10474 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10475 <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
|
10476 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
|
10477 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10478 |
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 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
|
10481 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
|
10482 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
|
10483 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10484 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10485 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10486 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
|
10487 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
|
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 <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
|
10492 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10493 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10494 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10495 Function <a href="#lua_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
|
10496 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
|
10497 </li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10498 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10499 <li> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10500 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
|
10501 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
|
10502 </li> |
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 </ul> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10505 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10506 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10507 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10508 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10509 <h1>9 – <a name="9">The Complete Syntax of Lua</a></h1> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10510 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10511 <p> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10512 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
|
10513 (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
|
10514 |
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 |
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 <pre> |
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 chunk ::= block |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10521 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10522 block ::= {stat} [retstat] |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10523 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10524 stat ::= ‘<b>;</b>’ | |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10525 varlist ‘<b>=</b>’ explist | |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10526 functioncall | |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10527 label | |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10528 <b>break</b> | |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10529 <b>goto</b> Name | |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10530 <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>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
|
10532 <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
|
10533 <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
|
10534 <b>for</b> Name ‘<b>=</b>’ exp ‘<b>,</b>’ exp [‘<b>,</b>’ exp] <b>do</b> block <b>end</b> | |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10535 <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
|
10536 <b>function</b> funcname funcbody | |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10537 <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
|
10538 <b>local</b> namelist [‘<b>=</b>’ explist] |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10539 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10540 retstat ::= <b>return</b> [explist] [‘<b>;</b>’] |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10541 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10542 label ::= ‘<b>::</b>’ Name ‘<b>::</b>’ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10543 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10544 funcname ::= Name {‘<b>.</b>’ Name} [‘<b>:</b>’ Name] |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10545 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10546 varlist ::= var {‘<b>,</b>’ var} |
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 var ::= Name | prefixexp ‘<b>[</b>’ exp ‘<b>]</b>’ | prefixexp ‘<b>.</b>’ Name |
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 namelist ::= Name {‘<b>,</b>’ Name} |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10551 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10552 explist ::= exp {‘<b>,</b>’ exp} |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10553 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10554 exp ::= <b>nil</b> | <b>false</b> | <b>true</b> | Number | String | ‘<b>...</b>’ | functiondef | |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10555 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
|
10556 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10557 prefixexp ::= var | functioncall | ‘<b>(</b>’ exp ‘<b>)</b>’ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10558 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10559 functioncall ::= prefixexp args | prefixexp ‘<b>:</b>’ Name args |
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 args ::= ‘<b>(</b>’ [explist] ‘<b>)</b>’ | tableconstructor | String |
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 functiondef ::= <b>function</b> funcbody |
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 funcbody ::= ‘<b>(</b>’ [parlist] ‘<b>)</b>’ block <b>end</b> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10566 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10567 parlist ::= namelist [‘<b>,</b>’ ‘<b>...</b>’] | ‘<b>...</b>’ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10568 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10569 tableconstructor ::= ‘<b>{</b>’ [fieldlist] ‘<b>}</b>’ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10570 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10571 fieldlist ::= field {fieldsep field} [fieldsep] |
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 field ::= ‘<b>[</b>’ exp ‘<b>]</b>’ ‘<b>=</b>’ exp | Name ‘<b>=</b>’ exp | exp |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10574 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10575 fieldsep ::= ‘<b>,</b>’ | ‘<b>;</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 binop ::= ‘<b>+</b>’ | ‘<b>-</b>’ | ‘<b>*</b>’ | ‘<b>/</b>’ | ‘<b>^</b>’ | ‘<b>%</b>’ | ‘<b>..</b>’ | |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10578 ‘<b><</b>’ | ‘<b><=</b>’ | ‘<b>></b>’ | ‘<b>>=</b>’ | ‘<b>==</b>’ | ‘<b>~=</b>’ | |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10579 <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
|
10580 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10581 unop ::= ‘<b>-</b>’ | <b>not</b> | ‘<b>#</b>’ |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10582 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10583 </pre> |
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 <p> |
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 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10590 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10591 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10592 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10593 <HR> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10594 <SMALL CLASS="footer"> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10595 Last update: |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10596 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
|
10597 </SMALL> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10598 <!-- |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10599 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
|
10600 --> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10601 |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10602 </body></html> |
aa7bc9c1df22
add unedited Lua manual
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10603 |