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-13

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
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 T. Publications

Steve T. Publications is a specialized book publishing company dedicated to delivering high-quality technical resources for IT professionals, students, educators, and technology enthusiasts. Our mission is to make complex technology concepts accessible through well-structured, practical, and industry-relevant publications.

We focus on publishing books across a wide range of information technology disciplines, including software development, cloud computing, cybersecurity, artificial intelligence, data science, networking, DevOps, databases, and enterprise technologies. Every publication is designed to bridge the gap between theory and real-world application, helping readers build the skills needed to succeed in today's rapidly evolving digital landscape.

At Steve T. Publications, we collaborate with experienced industry experts, educators, and technology professionals to produce accurate, up-to-date, and engaging content. We are committed to maintaining the highest editorial standards while empowering learners and professionals with trusted technical knowledge.

Whether you're beginning your IT journey, preparing for professional certifications, or advancing your expertise in emerging technologies, Steve T. Publications is your trusted source for authoritative and practical technical books.

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
  5. First-Class Functions
  6. Closures and Upvalues
  7. Variadic Functions and … Arguments
  8. Tail Calls and Proper Tail Call Optimization
  9. Table Operations and the Table Library
  10. Tables as Data Structures
  11. Table Traversal and Manipulation
  12. 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
  4. Performance Optimization Techniques
  5. Profiling and Benchmarking
  6. Garbage Collection Phases: A Visual Guide
  7. 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

Mini-Project 3: C-Embedded Lua Scripting Host

  1. Design Overview
  2. Implementation
  3. 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