Lua Programming The Ultimate Beginner's Guide to
Learn Lua Step by Step Fourth edition 2021 By Kathleen Peterson TABLE OF CONTENTS Introduction The audience About the third edition Other resources Certain Typographical Conventions Running examples Acknowledgments PART I Language Chapter 1. Getting Started 1.1. Blocks 1.2. Some lexical conventions 1.3. Global variables 1.4. Separate interpreter Exercises Chapter 2.
Types and values 2.1. Nil 2.2. Boolean 2.3. Numbers 2.4. Strings Literals Long lines Type conversions 2.5. Tables 2.6.
Functions 2.7. userdata and threads Exercises Chapter 3. Expressions 3.1. Arithmetic Operators 3.2. Comparison operators 3.3. Logical operators 3.4.
Concatenation 3.5. Length operator 3.6. Operator Priorities 3.7. Table constructors Exercises Chapter 4. Operators 4.1. Assignment operators 4.2.
Local variables and blocks 4.3. Control structures if then else while repeat Numeric for statement General for statement 4.4. break, return and goto Exercises Chapter 5. Functions 5.1. Multiple Results 5.2. Functions with a variable number of arguments 5.3.
Named arguments Exercises Chapter 6. More about functions 6.1. Closures 6.2. Non-global functions 6.3. Optimization of tail calls Exercises Chapter 7. Iterators and the generic for 7.1.
Iterators and Closures 7.2. Generic for semantics 7.3. Stateless iterators 7.4. Complex State Iterators 7.5. True iterators Exercises Chapter 8. Compilation, Execution, and Errors 8.1.
Compilation 8.2. Precompiled Code 8.3. C code 8.4. Errors 8.5. Error and Exception Handling 8.6. Error messages and call stack Exercises Chapter 9.
Coroutines 9.1. Basics of coroutines 9.2. Channels and Filters 9.3. Coroutines as iterators 9.4. Non-displacing multi-threading Exercises Chapter 10. Completed Examples 10.1.
The problem of eight queens 10.2. The most common words 10.3. Markov chain Exercises PART II Tables and Objects Chapter 11. Data Structures 11.1. Arrays 11.2. Matrices and multidimensional arrays 11.3.
Linked Lists 11.4. Queues and double queues 11.5. Sets and Sets 11.6. Line buffers 11.7. Counts Exercises Chapter 12. Data Files and Persistence 12.1.
Data files 12.2. Serialization Saving tables without loops Saving tables with loops Exercises Chapter 13. Metatables and Metamethods 13.1. Arithmetic metamethods 13.2. Comparison Methods 13.3. Library Metamethods 13.4.
Methods for accessing the table __Index metamethod __Newindex metamethod Default tables Tracking access to a table Read-only tables Exercises Chapter 14. Environment 14.1. Global variables with dynamic names 14.2. Descriptions of global variables 14.3. Non-global environments 14.4. _ENV and load Exercises Chapter 15. _ENV and load Exercises Chapter 15.
Modules and Packages 15.1. Require function Renaming a module Search along the path File crawlers 15.2. The Standard Approach for Writing Lua Modules 15.3. Using environments 15.4. Submodules and Packages Exercises Chapter 16. Object Oriented programming 16.1.
Classes 16.2. Inheritance 16.3. Multiple inheritance 16.4. Hiding 16.5. Single Method Approach Exercises Chapter 17. Weak Tables and Finalizers 17.1.
Weak tables 17.2. Functions with caching 17.3. Object Attributes 17.4. Again tables with default values 17.5. Ephemeral tables 17.6. Finalizers Exercises PART III Standard Libraries Chapter 18.
Math Library Exercises Chapter 19. Library for Bitwise Operations Exercises Chapter 20. Library for Working with Tables 20.1. Insert and remove functions 20.2. Sorting 20.3. Concatenation Exercises Chapter 21.
Library for working with strings 21.1. Basic functions for working with strings 21.2. Functions for working with templates String.find function String.match function String.gsub function String.gmatch function 21.3. Templates 21.4. Grips 21.5. Substitutions URL encoding Replacing tabs 21.6.
Tricky tricks 21.7. Unicode Exercises Chapter 22. Library I / O 22.1. Simple I / O Model 22.2. Full I / O model A small trick to increase performance Binaries 22.3. Other operations with files Exercises Chapter 23.
Library of operating room functions systems 23.1. Date and time 23.2. Other system calls Exercises Chapter 24. Debug Library 24.1. Accessibility (introspection) Accessing Local Variables Access to non-local variables Access to other coroutines 24.2. Hooks 24.3.
Profiling Exercises PART IV WITH API Chapter 25. Overview of the C API 25.1. First example 25.2. Stack Putting items on the stack Referring to items Other stack operations 25.3. Error handling in the C API Handling errors in the application code Error handling in the library code Exercises Chapter 26. Extending Your Application 26.1.
Basics 26.2. Working with tables 26.3. Lua function calls 26.4. Generalized function call Exercises Chapter 27. Calling C from Lua 27.1. Functions on C 27.2.
Continuations 27.3. C modules Exercises Chapter 28. Techniques for writing functions in C 28.1. Working with arrays 28.2. Working with strings 28.3. Saving state in functions on C Register Function related values Function related values used several functions Exercises Chapter 29.
User-Defined Types in C 29.1. User data (userdata) 29.2. Metatables 29.3. Object Oriented Access 29.4. Access as an ordinary array 29.5. Light objects of type userdata (light userdata) Exercises Chapter 30.
Resource Management 30.1. Directory iterator 30.2. XML Parser Exercises Chapter 31. Threads and States 31.1. Numerous threads 31.2. Lua States Exercises INTRODUCTION When Waldemar, Louis, and I started developing Lua in 1993, we could hardly imagine that Lua would spread like that.
On- started as home language for two specific projects, now Lua is widely used in all areas one can get benefits from simple, extensible, portable and efficient scripting language such as embedded systems, mobile devices swarms and, of course, games. We designed Lua from the beginning to integrate with software software written in C / C ++ and other common strange languages. There are many benefits to this integration. Lua is a tiny and simple language, partly because it doesn't tries to do what C is already good at, such as speed, low-level operations and interaction with third-party programs parties. Lua relies on C for these tasks. Lua offers something for which C is not good enough: sufficient distance from the hardware go support, dynamic structures, no redundancy and ease of testing and debugging.
For these purposes, Lua has safe environment, automatic memory management and good possibilities for working with strings and other types resizable data. Some of Lua's strength comes from its libraries. And this is no coincidence. In the end Finally, one of the main strengths of Lua is extensibility. Many language features contribute to this. Dynamic typing tion provides a large degree of polymorphism.
Automatic memory management simplifies interfaces because there is no need to the ability to decide who is responsible for allocating and freeing memory or how to handle overflows. Higher-order functions and anonymous functions allow a high degree of parameterization, making functions more versatile. More than an extensible language, Lua is a glue vayushim (glue) language . Lua supports a component-based approach to software development when we create an application by gluing together existing high-level components. These components are written in a compiled language with a static typing such as C / C ++; Lua is the glue we use use to arrange and connect these components. Usually components (or objects) represent more specific low- tier entities (such as widgets and data structures), which which hardly change during the development of the program and which take up the bulk of the final program execution time.
Lua gives the final form to the application, which is most likely changes a lot during the life of a given software product. However, unlike other "glue" technologies, Lua is is a complete programming language. Therefore we can use Lua not only to "glue" components, but also to adaptation and customization of these components, as well as to create a floor new components. Of course, Lua isn't the only scripting language. Exists other languages you can use for roughly the same goals. Nevertheless, Lua provides a whole set of possibilities, which make him the best choice for many tasks and gives him your unique profile: Extensibility .
Next page