Table of Contents
About the Book
I. The Basics
1. Getting Started
Chunks
Some Lexical Conventions
Global Variables
Types and Values
The Stand-Alone Interpreter
2. Interlude: The Eight-Queen Puzzle
3. Numbers
Numerals
Arithmetic Operators
Relational Operators
The Mathematical Library
Representation Limits
Conversions
Precedence
Lua Before Integers
4. Strings
Literal strings
Long strings
Coercions
The String Library
Unicode
5. Tables
Table Indices
Table Constructors
Arrays, Lists, and Sequences
Table Traversal
Safe Navigation
The Table Library
6. Functions
Multiple Results
Variadic Functions
The function table.unpack
Proper Tail Calls
7. The External World
The Simple I/O Model
The Complete I/O Model
Other Operations on Files
Other System Calls
8. Filling some Gaps
Local Variables and Blocks
Control Structures
break, return, and goto
II. Real Programming
9. Closures
Functions as First-Class Values
Non-Global Functions
Lexical Scoping
A Taste of Functional Programming
10. Pattern Matching
The Pattern-Matching Functions
Patterns
Captures
Replacements
Tricks of the Trade
11. Interlude: Most Frequent Words
12. Date and Time
The Function os.time
The Function os.date
Date–Time Manipulation
13. Bits and Bytes
Bitwise Operators
Unsigned Integers
Packing and Unpacking Binary Data
Binary files
14. Data Structures
Arrays
Matrices and Multi-Dimensional Arrays
Linked Lists
Queues and Double-Ended Queues
Reverse Tables
Sets and Bags
String Buffers
Graphs
15. Data Files and Serialization
Data Files
Serialization
16. Compilation, Execution, and Errors
Compilation
Precompiled Code
Errors
Error Handling and Exceptions
Error Messages and Tracebacks
17. Modules and Packages
The Function require
The Basic Approach for Writing Modules in Lua
Submodules and Packages
III. Lua-isms
18. Iterators and the Generic for
Iterators and Closures
The Semantics of the Generic for
Stateless Iterators
Traversing Tables in Order
True Iterators
19. Interlude: Markov Chain Algorithm
20. Metatables and Metamethods
Arithmetic Metamethods
Relational Metamethods
Library-Defined Metamethods
Table-Access Metamethods
21. Object-Oriented Programming
Classes
Inheritance
Multiple Inheritance
Privacy
The Single-Method Approach
Dual Representation
22. The Environment
Global Variables with Dynamic Names
Global-Variable Declarations
Non-Global Environments
Using _ENV
Environments and Modules
_ENV and load
23. Garbage
Weak Tables
Memorize Functions
Object Attributes
Revisiting Tables with Default Values
Ephemeron Tables
Finalizers
The Garbage Collector
Controlling the Pace of Collection
24. Coroutines
Coroutine Basics
Who Is the Boss?
Coroutines as Iterators
Event-Driven Programming
25. Reflection
Introspective Facilities
Hooks
Profiles
Sandboxing
26. Interlude: Multithreading with Coroutines
IV. The C API
27. An Overview of the C API
A First Example
The Stack
Error Handling with the C API
Memory Allocation
28. Extending Your Application
The Basics
Table Manipulation
Calling Lua Functions
A Generic Call Function
29. Calling C from Lua
C Functions
Continuations
C Modules
30. Techniques for Writing C Functions
Array Manipulation
String Manipulation
Storing State in C Functions
31. User-Defined Types in C
Userdata
Metatables
Object-Oriented Access
Array Access
Light Userdata
32. Managing Resources
A Directory Iterator
An XML Parser
33. Threads and States
Multiple Threads
Lua States