Leanpub Header

Skip to main content

Lua Programming: From First Script to Full Mastery

A Complete Guide to the Language Powering Games, Engines, and Embedded Systems

This book is 100% completeLast updated on 2026-07-17

Learn Lua from your first script to advanced programming techniques with a practical, hands-on guide. Whether you are building games, scripting applications, or exploring embedded systems, this book gives you the knowledge to write clean, efficient Lua code with confidence.

Minimum price

$19.00

$29.00

You pay

Author earns

$

Also available for 1 book credit with a Reader Membership

PDF
EPUB
WEB
APP
170
Pages
About

About

About the Book

Lua is one of the most widely used scripting languages in the world, yet it remains one of the least understood. This book takes you from writing your very first line of Lua code to mastering advanced topics like metaprogramming with metatables, embedding Lua in C applications, and building production-grade systems. Whether you are a game developer scripting behavior in Roblox or LÖVE2D, a web engineer configuring OpenResty, an editor power user customizing Neovim, or simply a programmer curious about the language that powers so much of modern software, this book gives you the deep, practical knowledge you need. Every concept is explained with annotated code examples, version-aware notes covering Lua 5.1 through the latest 5.5 release, and real-world context drawn from the projects and communities that make Lua matter.

Author

About the Author

Steve Publications

Steve is a technology professional with more than 20 years of experience in software development, server infrastructure, cybersecurity, vulnerability research and reverse engineering. Throughout his career, he has designed, secured, analyzed and tested complex software and infrastructure, with a particular focus on understanding how systems fail and how they can be made more secure.

Outside of work, Steve enjoys sharing knowledge with the technology community. He collaborates with researchers, industry experts and technology professionals to write practical books covering software development, cybersecurity, cloud computing, networking, DevOps, artificial intelligence and enterprise technologies. His books focus on practical learning through clear explanations, real-world examples and hands-on exercises. With more than two decades of industry experience, his goal is to help IT professionals, students and technology enthusiasts build useful skills and stay current in a rapidly changing industry.

We believe readers deserve to know how our books are created. Most of our authors are not native English speakers, so we use AI to help translate, proofread manuscripts, fix grammar, improve sentence structure and make technical explanations easier to read. AI is used as an editing tool only. It does not replace the research, technical knowledge or hands-on experience behind our books. Some of our authors also prefer to remain anonymous for privacy or professional reasons. In those cases, we publish their work under a different name. The author's name may be different, but the quality of the content and our review process remain the same.

Every book is written, reviewed and maintained by experienced technology professionals, with contributions from our private technical community of more than 420 engineers and researchers from Ukraine, Belarus and Russia. We spend far more time validating technical accuracy and keeping our content up to date than generating text. We are always interested in working with experienced professionals who have deep expertise in a particular technology or domain. If you would like to publish a book with us or help review an existing manuscript, we'd love to hear from you. Send us a message describing your area of expertise. We are especially interested in niche technologies, specialized skills and emerging topics that are underrepresented in existing technical literature.

If you look through the contents of our books, you'll see practical examples, detailed explanations and material that is regularly updated. Our goal is to publish books that professionals can actually rely on, not low-effort AI-generated content. If you ever feel that one of our books does not meet that standard, Leanpub offers a 60-day money-back guarantee. Feel free to request a refund if you are not satisfied with your purchase.

Contents

Table of Contents

A Complete Guide to the Language Powering Games, Engines, and Embedded Systems

Introduction

  1. What This Book Is
  2. What This Book Is Not
  3. The Version Landscape
  4. How to Use the Code Examples
  5. A Note on Style
  6. What to Expect Next

Chapter 1: The Story of Lua

  1. From SOL to Lua: A Brazilian Origin Story
  2. Design Philosophy: Minimalism by Choice
  3. Version Evolution: From 1.0 to 5.5
  4. Where Lua Lives Today
  5. Chapter 1 Summary

Chapter 2: Getting Started with Lua

  1. Installing Lua: From Source to Package Manager
  2. Your First Lua Program
  3. Development Environments and Editors
  4. Understanding the Lua Distribution
  5. Chapter 2 Summary

Chapter 3: Lua Fundamentals: Types, Variables, and Expressions

  1. Lua’s Type System
  2. Variables and Assignment
  3. Operators and Precedence
  4. Strings and String Operations
  5. Chapter 3 Summary

Chapter 4: Control Flow

  1. Conditional Statements
  2. While and Repeat-Until Loops
  3. The For Loop: Numeric and Generic
  4. Blocks and the do-end Construct

Chapter 5: Functions in Lua

  1. Defining and Calling Functions
  2. First-Class Functions
  3. Closures and Upvalues
  4. Variadic Functions and … Arguments
  5. Tail Calls and Proper Tail Call Optimization

Chapter 6: Tables – The Heart of Lua

  1. Table Fundamentals
  2. Table Operations and the Table Library
  3. Tables as Data Structures
  4. Table Traversal and Manipulation
  5. Chapter 6 Summary

Chapter 7: Metatables and Metamethods

  1. What Are Metatables?
  2. Arithmetic and Bitwise Metamethods
  3. Table Access Metamethods
  4. Advanced Metatable Patterns
  5. Metatable Lookup Chain: A Visual Guide
  6. Chapter 7 Summary

Chapter 8: Object-Oriented Programming in Lua

  1. Objects Without Classes
  2. Class Metapatterns
  3. Inheritance in Lua
  4. Encapsulation and Access Control
  5. Polymorphism and Duck Typing
  6. Why This Matters

Chapter 9: Modules, Packages, and Code Organization

  1. Creating Modules
  2. Package Paths and Searchers
  3. LuaRocks: The Package Ecosystem
  4. Chapter 9 Summary

Chapter 10: Coroutines and Cooperative Concurrency

  1. What Are Coroutines?
  2. Yielding and Resuming
  3. Producer-Consumer Patterns
  4. Practical Concurrency Patterns
  5. Why This Matters

Chapter 11: Error Handling, Debugging, and File I/O

  1. The Debug Library
  2. File I/O: Simple and Complete Models
  3. Pattern Matching with the String Library

Chapter 12: Performance, Memory Management, and Optimization

  1. Understanding Lua’s Virtual Machine
  2. Garbage Collection Deep Dive
  3. Performance Optimization Techniques
  4. Profiling and Benchmarking
  5. Garbage Collection Phases: A Visual Guide
  6. Chapter 12 Summary

Chapter 13: The C API, Embedding, and Extending Lua

  1. The C API Architecture
  2. Embedding Lua in C Applications
  3. Writing C Libraries for Lua
  4. Userdata and Metaprogramming in C
  5. Security and Sandboxing
  6. C API Stack: A Visual Guide
  7. Chapter 13 Summary
  8. Mini-Project 3: C-Embedded Lua Scripting Host
  9. Design Overview
  10. Implementation
  11. Why This Matters

Chapter 14: Real-World Applications and Best Practices

  1. Game Development with Lua
  2. Web Development and Infrastructure
  3. Automation and Tooling
  4. Best Practices and Common Pitfalls
  5. Chapter 14 Summary

Conclusion

References

  1. Official Lua Documentation
  2. Language Design and Performance
  3. C API and Embedding
  4. Ecosystem and Tools
  5. Game Development
  6. Web Infrastructure
  7. Text Editors and Automation
  8. News and Analysis
  9. General References

Get the free sample chapters

Click the buttons to get the free sample in PDF or EPUB, or read the sample online here

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $15 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub