Atnaujinkite slapukų nuostatas

Beginning Lua Programming [Minkštas viršelis]

3.62/5 (58 ratings by Goodreads)
  • Formatas: Paperback / softback, 672 pages, aukštis x plotis x storis: 235x189x37 mm, weight: 1034 g
  • Išleidimo metai: 01-Jan-2007
  • Leidėjas: Wrox Press
  • ISBN-10: 0470069171
  • ISBN-13: 9780470069172
Kitos knygos pagal šią temą:
  • Formatas: Paperback / softback, 672 pages, aukštis x plotis x storis: 235x189x37 mm, weight: 1034 g
  • Išleidimo metai: 01-Jan-2007
  • Leidėjas: Wrox Press
  • ISBN-10: 0470069171
  • ISBN-13: 9780470069172
Kitos knygos pagal šią temą:
Lua has advantages: it is powerful, has a wide range of features, and is surrounded, enfolded and uplifted by free community resources. Master practitioners Jung and Brown assume readers want to start at the beginning and explain how to install Lua and how to find a systems shell. They cover using the interpreter, extending Lua with functions such as return values, working with tables, using strings and modules, handling events naturally with co-routines, developing bytecode, collecting garbage, implementing tables and strings, working with the debug library, and exploring libraries for such elements as the core, co-routines, packages, strings, tables, math, input/output and the community. They show how to interface Lua with other languages, manage information with databases, program for the web, connect with the outside world, program games, and carry Lua with you. They conclude with information on joining the Lua community. Annotation ©2007 Book News, Inc., Portland, OR (booknews.com) This book is for students and professionals who are intrigued by the prospect of learning and using a powerful language that provides a rich infrastructure for creating programs. No programming knowledge is necessary to benefit from this book except for the section on Lua bindings, which requires some familiarity with the C programming language. A certain comfort level with command-line operations, text editing, and directory structures is assumed.Software developers who have experience with functions, strings, and associative arrays can skim Chapters 2 through 5 with the caveat that certain Lua colloquialisms are introduced there along with programming concepts.Throughout the text, sections pertaining to a particular operating system are clearly marked and can be skipped by readers working on a different platform.This book is organized to guide you through the basics of using Lua. Its structure is as follows:Installing Lua on your system (Chapter 1)Learning the fundamentals of programming in Lua (Chapters 2 through 10)Reviewing standard Lua functions (Chapter 11)Exploring application development with Lua using packages contributed by the community (Chapters 12 through 18)Using Luas many community resources (Chapter 19)Chapters 2 through 10 each build on concepts that are presented in its predecessors, so a sequential reading of this part of the book is advised. The summary of Luas built-in libraries contains examples that assume you have a good grasp of the materials presented in the first 10 chapters.Some of the libraries and techniques presented in Chapters 12 and 13 are needed in the remaining chapters of the book. Chapters 14 through 19 are relatively independent of one another and can be read out of sequence.You need surprisingly little in the way of computer resources to learn and use Lua. This book focuses on Windows and Unix-like (including Linux) systems, but any operating system that supports a command shell should be suitable. Youll need a text editor to prepare and save Lua scripts.If you choose to extend Lua with libraries written in a programming language like C, youll need a suitable software development kit. Many of these kits are freely available on the Internet but, unlike Lua, they can consume prodigious amounts of disk space and memory.Chapter 18 discusses using Lua on a Palm Pilot. Even if you dont own or have access to one of these devices, this chapter shows how you can simulate one on the major desktop systems.
Acknowledgments ix
Introduction xxiii
Getting Situated
1(22)
Choosing How to Install Lua
1(2)
Building Lua Yourself
2(1)
Selecting Prebuilt Lua
3(1)
Finding Your System's Shell
3(3)
Windows Shells
3(1)
Shells on Unix and Unix-Like systems
3(1)
Shell Features
4(1)
The Environment
4(1)
Environment Variables on Unix-Like Systems
4(1)
Environment Variables on Windows
5(1)
Dealing with Tarballs and Zip Files
6(1)
Compiling Lua
7(11)
The Lua Source Tarball
7(1)
Compiling Lua on Linux and Other Unix-Like Systems
8(4)
Compiling Lua on Windows
12(1)
Building Lua with Microsoft Visual C++
13(1)
Building Lua with the Tiny C Compiler
14(2)
Building Lua with MinGW
16(2)
Binary Packages
18(3)
Selecting a Prebuilt Binary Package
18(1)
Installing a Prebuilt Binary Package on a Unix-Type System
19(1)
Installing a Prebuilt Binary Package on Windows
20(1)
Additional Tools
21(1)
Programmer's Editor
21(1)
Revision Control System
22(1)
Summary
22(1)
First Steps
23(46)
Numbers and Arithmetic Operations: Basic Interpreter Usage
23(3)
Addition, Subtraction, Multiplication, Division, and Exponentiation
24(1)
Interacting with the Interpreter
24(1)
Other Notations for Numbers
25(1)
Interpreter Know-How
26(1)
Quitting the Interpreter
26(1)
Interpreter Shortcuts
26(1)
Numerical Gotchas
27(1)
Division by Zero and Overflow
27(1)
Floating-Point Rounding
28(1)
Variables and Assignment
28(4)
Assignment Basics
29(2)
Multiple Assignment
31(1)
Variables on the Right Side of Assignments
32(1)
Strings
32(5)
Quoting Strings
32(1)
Quoting Strings with Double Quotes
32(1)
Quoting Strings with Single Quotes
33(1)
Quoting Strings with Square Brackets
33(2)
Backslash Escaping
35(2)
Relational Operators and Boolean Values
37(3)
Comparing Numbers
37(1)
Comparing Strings
38(2)
The nil Value
40(1)
Boolean Operators
41(4)
The and Operator
42(1)
The or Operator
43(1)
The not Unary Operator
44(1)
The Concatenation, Length, and Modulo Operators
45(3)
The String Concatenation Operator
45(1)
The Length Operator
46(1)
The Modulo Operator
47(1)
Automatic Conversion of Operands
48(1)
Precedence and Associativity
49(2)
Variables and Values
51(1)
Comments
52(1)
Expressions and Statements
53(1)
Compound Statements
54(12)
The if Statement
55(3)
The while Loop
58(2)
The for Loop
60(2)
The repeat Loop
62(1)
The break and do Statements
63(3)
Summary
66(1)
Exercises
66(3)
Extending Lua with Functions
69(48)
Return Values
72(9)
Using a Function that Returns a Value
72(1)
Defining a Function that Returns a Value
73(1)
Using return to Alter Control Flow
74(2)
Returning Nothing
76(1)
Returning Multiple Values
77(1)
Adjusting Value Lists
78(1)
Using Multiple-Valued Functions in Value Lists
78(1)
Using Valueless Functions in Value Lists
79(2)
Chunks as Functions
81(3)
Variable Scope
84(7)
Actual and Formal Arguments
84(1)
Local Variables
85(6)
Understanding Side Effects
91(4)
Ordering Side Effects
91(2)
Short-Circuit Evaluation
93(2)
Functions Calling Functions
95(7)
The Call Stack
95(2)
Recursion
97(1)
Stack Overflow
98(1)
Tail Calls
99(3)
Functions as Values
102(4)
Replacing Built-in Functions
102(1)
Comparing and Printing Functions
103(1)
Function Definitions as Assignments
103(2)
Local Functions
105(1)
Whitespace, Semicolons, and Function Calls
106(2)
Upvalues and Closures
108(5)
Defining Functions that Create Functions
108(2)
Defining Functions with Private State
110(1)
Figuring Out Tricky Scope Situations
111(2)
Summary
113(1)
Exercises
114(3)
Working with Tables
117(54)
Tables Introduced
117(2)
A Shorter Way to Write Some Keys
119(1)
Altering a Table's Contents
120(1)
Tables as Arrays
121(2)
Array Length
123(1)
Looping through Tables
124(4)
Tables of Functions
128(8)
The Table Library
128(1)
table.sort
128(3)
table.concat
131(1)
table.remove
132(1)
table.maxn
132(1)
Object-Oriented Programming with Tables
133(3)
Functions with Variable Numbers of Arguments
136(7)
Defining Vararg Functions
136(4)
Script as Vararg Functions
140(3)
Keyword Arguments
143(1)
Different but the Same
144(8)
Table Equality
144(1)
Avoiding Bugs by Understanding Mutability
145(1)
Variables and Mutable Values
145(2)
Tables and Functions
147(1)
Copying Tables
148(4)
Building Other Data Structures from Tables
152(6)
Custom-Made Loops
158(5)
Global Variable Environments
163(5)
Summary
168(1)
Exercises
169(2)
Using Strings
171(42)
Basic String Conversion Functions
171(2)
String Length
173(1)
Converting Between Characters and Character Codes
173(1)
Formatting Strings and Numbers with string.format
174(6)
Input/Output
180(5)
Writing to and Reading from a File
181(4)
Pattern-Matching
185(25)
Searching for a Specific String
186(1)
Matching Any of Several Characters
186(7)
Matches of Varying Lengths
193(5)
Captures
198(4)
Matching Balanced Delimiters
202(1)
More on string.find, string.match, and string.gsub
202(2)
Iterating Through All Matches
204(3)
Tricks for the Tricky
207(2)
Magic Characters Chart
209(1)
Summary
210(1)
Exercises
210(3)
Handling and Avoiding Errors
213(20)
Kinds of Errors
213(5)
Syntax Errors
213(4)
Runtime Errors
217(1)
Handling Errors
218(12)
Default Error Behavior
218(1)
Checking Assumptions
219(1)
Code Errors
220(1)
Data Errors
220(1)
The assert and error Functions
220(1)
Defining Your Own Error Condition
221(1)
Anticipating Error Conditions
222(1)
Working with Return Values
222(2)
Structuring Code
224(3)
Error-Containment Functions
227(1)
The pcall Function
227(2)
The xpcall Function
229(1)
User-Written Scripts
230(1)
Locating Errors
230(1)
Summary
230(1)
Exercises
231(2)
Using Modules
233(16)
Interfaces and Implementations
233(1)
The require Function
234(1)
Where to Put Modules
235(1)
Creating a Module Directory
235(1)
Setting Lua's Environment Variable
236(1)
Preserving a Module's Interface
236(4)
Module Bookkeeping
240(1)
Bytecode
241(1)
Namespaces
242(3)
Creating and Reusing Namespaces
242(2)
Avoiding Global Variables
244(1)
Using the strict Module
244(1)
Reporting All Global Assignments
244(1)
The module Function
245(2)
C Modules
247(1)
Summary
247(1)
Exercises
247(2)
Extending Lua's Behavior with Metamethods
249(22)
Using Concatenation and Arithmetical Operators on Tables
249(8)
Relational Metamethods
257(1)
Indexing and Call Metamethods
258(7)
Non-Tables with Metamethods
265(2)
Non-Syntactical Metamethods
267(1)
Metamethod Applicability
268(1)
Summary
268(1)
Exercises
269(2)
Handling Events Naturally with Coroutines
271(28)
Coroutines and Program Control
271(10)
Coroutines Are Not Functions
272(1)
How Coroutines Are Like Programs
272(1)
Coroutines Transfer Control
273(1)
Wrapping a Coroutine
273(1)
Coroutines Are Cooperative
273(2)
Outside Looking In
275(3)
Coroutines Have Status
278(1)
Rules of Conduct
279(1)
Work Shoulder-to-Shoulder
279(1)
Trust the Dispatcher
280(1)
Expect the Best, Prepare for the Worst
280(1)
Play on Your Side of the Fence
280(1)
Avoid the Deep End
281(1)
Managing Concurrent Tasks
281(1)
Retaining State
282(5)
Exercising a Coroutine's Memory
282(4)
Iterating with Coroutines
286(1)
Handling Events Simply
287(10)
The Event Loop
288(8)
Yielding to Another Coroutine
296(1)
Summary
297(1)
Exercises
297(2)
Looking Under the Hood
299(26)
Bytecode and luac
299(4)
Garbage Collection
303(4)
The Implementation of Tables and Strings
307(1)
The Debug Library
308(13)
Inspecting and Manipulating Running Code
308(7)
Hooks
315(6)
Other Functions in the Debug Library
321(1)
Summary
321(1)
Exercises
322(3)
Exploring Lua's Libraries
325(50)
Core Library
325(11)
Environment Functions
326(1)
Metatable Functions
326(2)
Chunk-Loading Functions
328(2)
Error-Containment Functions
330(1)
Module Functions
331(1)
The Garbage-Collection Function
332(1)
Type and Conversion Functions
333(1)
Basic Output
333(1)
Error-Condition Functions
333(1)
Table Traversal Functions
334(1)
Vararg-Related Functions
335(1)
Coroutine Library
336(2)
Package Library
338(2)
String Library
340(4)
Pattern-Based String Functions
340(2)
String-Conversion Functions
342(2)
Table Library
344(1)
Math Library
345(19)
Trigonometric Functions
345(3)
Inverse Trigonometric Functions
348(3)
Hyperbolic Functions
351(3)
Exponent Functions
354(2)
Logarithm Functions
356(2)
Adjustment Functions
358(2)
Floating Point Representation
360(1)
Angle Conversion Functions
361(1)
Pseudo-Random Number Functions
362(1)
Modulus Functions
362(1)
Minimum and Maximum Functions
363(1)
Constants
363(1)
Input/Output Library
364(4)
Operating System Library
368(2)
CPU Timing
368(1)
Time and Date Functions
368(1)
Filesystem Functions
369(1)
Other Operating System Functions
370(1)
Debugging Library
370(3)
Summary
373(2)
Using Community Libraries
375(38)
Library Overview
375(4)
Dynamically Linked Libraries
376(1)
Resolving External References
376(1)
Configuration Options
376(1)
Libraries Built from Source Code
377(1)
Building Libraries on Unix-Like Systems
378(1)
Building Libraries on Windows
378(1)
Limits to Portability
379(1)
How Lua Interacts with Libraries
379(4)
The Variable Registration Process
379(1)
Calling a C Function from Lua
380(3)
The pack Binary Structuring Library
383(6)
Building the pack Library on Unix-type Systems
383(1)
Building and Installing the pack Library on Windows
384(1)
Testing the pack Library
384(1)
Installing the pack Library
385(1)
Using the pack Library
385(4)
The cURL File Transfer Library
389(6)
Building libcurl
389(1)
Building libcurl on Unix-Like Systems
390(1)
Building libcurl on Windows
391(1)
Building luacurl
392(1)
Building luacurl on Unix-Like Systems
392(1)
Building luacurl on Windows
393(1)
Using luacurl
393(2)
The gd Graphics Library
395(10)
Building gd
395(1)
Building gd on Unix-Like Systems
396(1)
Installing gd on Windows
396(1)
Building lua-gd
397(1)
Building lua-gd on Unix-Like Systems
397(1)
Building lua-gd on Windows
398(1)
Using lua-gd
399(6)
The SQLite Database Library
405(6)
Building SQLite3
405(1)
Building SQLite3 on Unix-Like Systems
405(1)
Building SQLite3 on Windows
406(1)
Building Iua-sqlite3
407(1)
Building Iua-sqlite3 on Unix-Like Systems
407(1)
Building Iua-sqlite3 on Windows
408(1)
Using Iua-sqlite3
409(2)
Summary
411(1)
Exercises
412(1)
Interfacing Lua with Other Languages
413(36)
How C Programs Use Lua
413(2)
Embedding Lua
414(1)
Extending Lua
414(1)
Embedding or Extending: Which Is Best?
414(1)
Communicating Between Lua and C
415(6)
Calling Lua from C
421(2)
Obtaining a Lua Function
421(1)
Calling a Lua Function
421(1)
Protected Calls
422(1)
Working with Userdata
423(13)
Indexing Values in C
436(2)
Retrieving Indexed Values
436(1)
Setting Indexed Values
437(1)
Retaining Values in C
438(3)
The Registry
438(1)
C Function Environments
439(1)
Upvalues in C
439(1)
Referencing Values
440(1)
The Thread Environment
441(1)
Layering Your Extension Library
441(6)
Summary
447(1)
Exercises
448(1)
Managing Information with Databases
449(18)
Some Basic Relational Database Concepts
449(9)
SQL, LuaSQL, and MySQL
458(8)
Summary
466(1)
Exercises
466(1)
Programming for the Web
467(36)
A Web Server Primer
467(1)
Dynamic Web Content
468(1)
Embedded Web Server
468(1)
Extended Web Server
469(1)
Creating Content at Run Time with Lua
469(1)
Executing CGI Scripts
469(2)
CGI Scripts on Unix-Type Systems
470(1)
CGI Scripts on Windows
470(1)
Installing a Web Server
471(3)
Apache
471(1)
TinyWeb
472(2)
Testing Your Web Server with Static Content
474(1)
Serving Dynamic Web Content
474(15)
Problems with CGI Scripts
475(1)
Asynchronous Calls to the Server
476(2)
Producing a Calendar Dynamically
478(3)
Producing Charts Dynamically
481(8)
Interactive CGI Applications
489(9)
CGI Helper Routines
489(9)
Developing CGI Scripts
498(1)
Security Issues
498(1)
The Kepler Project
498(3)
CGI the Kepler Way
499(1)
Lua Pages
500(1)
Summary
501(1)
Exercises
501(2)
Connecting to a Larger World
503(40)
Installing LuaSocket
503(3)
Compiling LuaSocket
504(1)
Compiling on Linux and Other Unix-Like Systems
504(1)
Compiling on Windows
504(1)
Installing Windows Binaries
505(1)
Network Overview
506(6)
Routed Packets
506(1)
Addresses
507(1)
Domain Names
507(1)
Identifying Internet Resources
508(1)
Transport Protocols
509(1)
Sockets: Streams and Datagrams
510(1)
TCP Socket Sociology
511(1)
Using LuaSocket for Network Communication
512(6)
Handling Multiple Persistent Connections
518(6)
Using Lua Coroutines with the select Function
518(4)
Multiple Connections on the Server Side
522(1)
Setting Timeout Values for the Server Socket
523(1)
The Application Protocols
524(12)
Filtering the Flow of Data
524(3)
Accessing Web Pages
527(2)
Sending and Receiving E-mail Messages
529(7)
Networking with Lua and Streams
536(5)
On the Server Side: inetd and Friends
536(2)
On the Client Side: ssh and Friends
538(3)
Summary
541(1)
Exercises
542(1)
Programming Games with Lua
543(22)
Understanding Why and When to Use Lua
543(1)
Simple 2-D Action Game Using SDL
544(18)
Installing SDL and LuaCheia
544(2)
Using SDL
546(16)
Summary
562(1)
Exercise
562(3)
Carrying Lua with You
565(30)
Getting Started with Plua
565(2)
Obtaining Plua
566(1)
Examining the Distribution Contents
566(1)
Exploring Plua's Features
567(9)
Running the Plua Application
567(2)
Saving Plua Programs
569(1)
Reading the Online Documentation
570(1)
Using Palm OS Streams
571(1)
Compiling Applications
572(1)
Compiling Libraries
573(3)
Plua on the Mothership
576(5)
The Command-Line Compiler
576(1)
The Palm OS Emulator
577(1)
Obtaining the Emulator
577(1)
Installing on Windows
578(1)
Configuring POSE
578(1)
Running Plua in the Emulator
578(2)
Compiling a Program in the Emulator
580(1)
Exiting the Emulator
580(1)
The Palm OS Simulator
581(1)
Obtaining the Simulator
581(1)
Using the Simulator
581(1)
Programming with Plua
581(11)
Generating Graphics
582(1)
Programming the User Interface
583(7)
Accessing Databases
590(2)
Summary
592(1)
Exercises
593(2)
Fitting into the Lua Community
595(10)
The Lua Web Site
596(1)
The Lua Reference Manual
596(1)
Framing Questions
597(1)
The Lua Mailing List
597(4)
Viewing and Searching the Archives
597(1)
Downloading the Archives
598(1)
Using a Web Browser to Access the List
599(1)
Using a Newsreader to Access the List
599(1)
Subscribing to the List Server
599(1)
Posting Messages
600(1)
The Lua Chat Room
601(1)
Forums
601(1)
The Lua Wiki
601(1)
LuaForge
602(1)
Annual Workshops
603(1)
Summary
603(2)
Appendix A: Answers 605(24)
Index 629


Between his first programs submitted to a Burroughs 5500 on Hollerith punch cards and his latest programs tapped into a Palm Pilot, Kurt Jung has been the principal programmer on various projects ranging from airline yield management to state machine-driven workflow. Aaron Brown began programming in elementary school on a Commodore 64. He plays various musical instruments and speaks Esperanto.