Programming in Lua (4th Edition) cover

Programming in Lua (4th Edition)

Rating 4.5
Word count
560 words
Chapters
37
ISBN
9787121338045

Tags

Summary

This book is the Chinese translation of the 4th edition of Programming in Lua, written by Roberto Ierusalimschy, the chief architect of the Lua language, and is the official authoritative tutorial on Lua. The 4th edition targets Lua 5.3 (the latest version of the language at the time of writing) and reorganizes the book into four parts. Part 1, "The Language," begins with chunks, lexical conventions, global variables, types and values, then introduces numbers, strings, tables, functions, input/output and control structures. Part 2, "Real Programming," covers closures, pattern matching, dates and times, bitwise operations, data structures, data files and serialization, compilation, execution and errors, and modules and packages, using interlude case studies to apply language elements to real problems. Part 3, "The Language Itself," delves into iterators and the generic for, metatables and metamethods, object-oriented programming, environments, garbage collection, coroutines and reflection. Part 4, "The C API," systematically explains how Lua interacts with C, including extending applications, calling C from Lua, techniques for writing C functions, user-defined types, resource management, and threads and states. The book also details new features introduced in Lua 5.3, such as integers and bitwise operations, and includes exercises in each chapter so that readers, beyond mastering usage, can appreciate the trade-offs in the design and implementation of a scripting language.

Editor's review

市面上讲Lua的书不少,但由语言作者本人执笔、且真正讲透“为什么这样设计”的,只有这一本。第4版不是对上一版的修修补补,而是配合Lua 5.3做了整篇重排:语言基础、编程实操、语言特性、C语言API四部分层层递进,读完第一部分能写脚本,读到第三部分能理解元表、协程与垃圾回收这些Lua的“性格”,第四部分则把手伸进引擎内部,教你如何让C程序与Lua互相调用。书中穿插的八皇后问题、词频统计、马尔可夫链、用协程实现多线程等小插曲,篇幅不大,却是把零散语法串成完整思路的关键;每章末尾的练习题也很值得动手做一遍。由梅隆魁翻译,术语与官方手册保持了一致,译文总体准确可读。对于被Unity、Redis、nginx、OpenResty、Wireshark等大量项目用作嵌入脚本的Lua来说,这本书既是入门教程,也是查漏补缺的参考手册。

Who it's for

A good fit for

  • 已有其他语言基础、想快速上手Lua的程序员
  • 从事游戏开发、嵌入式、OpenResty等Lua实战场景的开发者
  • 需要把Lua嵌入自有C/C++程序、扩展脚本能力者
  • 想借一门小而完整的语言理解编程语言设计与实现的读者

Not a good fit for

  • 完全没有编程经验的零基础读者
  • 只想找Lua插件速查表、不打算系统学习的人
  • 希望本书直接讲解某个具体游戏引擎Lua API的读者

Reading tips

  1. 先按顺序读完第1部分并完成每章练习,打牢表、函数、字符串的基础。
  2. 第2、3部分的案例建议在本地敲一遍代码,配合独立解释器观察输出。
  3. 第4部分C API需要边读边写小型C宿主程序,可对照官方参考手册验证。
  4. 遇到Lua版本差异时,留意书中关于5.3整型与位运算的兼容性说明。

About the publisher

Publishing House of Electronics Industry China · Founded in 1982

The Publishing House of Electronics Industry is a comprehensive publisher distinguished by its focus on electronic information and related fields. Judging from the more than 3,000 titles in its catalogue, its publishing covers programming and design, artificial intelligence, computer science, finance and economics, photography, and social sciences, attending both to cutting-edge technology and to general readers. Representative titles include Factor Investing: Methods and Practice, x86 Assembly Language: From Real Mode to Protected Mode, The RISC-V Reader, Artificial Intelligence: Speech Recognition, Understanding and Practice, Phased Array Radar Technology, Radar Target Characteristics, and 100 Go Mistakes and How to Avoid Them, most of which centre on technical methods and engineering practice. Its authors include Shi Chuan, Li Zhong, Wang Xiaobo, David Patterson, Andrew Waterman, and Yu Zihao, among others from China and abroad. Owing to limited public information, no further publishing features are elaborated here.

Contents

  1. Part 1 The Language
  2. 1 Getting Started
  3. 2 Interlude: The Eight-Queens Puzzle
  4. 3 Numbers
  5. 4 Strings
  6. 5 Tables
  7. 6 Functions
  8. 7 Input and Output
  9. 8 The Bits and Pieces
  10. Part 2 Real Programming
  11. 9 Closures
  12. 10 Pattern Matching
  13. 11 Interlude: Most Frequent Words
  14. 12 Dates and Times
  15. 13 Bits and Bytes
  16. 14 Data Structures
  17. 15 Data Files and Serialization
  18. 16 Compilation, Execution, and Errors
  19. 17 Modules and Packages
  20. Part 3 The Language Itself
  21. 18 Iterators and the Generic for
  22. 19 Interlude: Markov Chains
  23. 20 Metatables and Metamethods
  24. 21 Object-Oriented Programming
  25. 22 Environments
  26. 23 Garbage Collection
  27. 24 Coroutines
  28. 25 Reflection
  29. 26 Interlude: Multithreading with Coroutines
  30. Part 4 The C API
  31. 27 An Overview of the C API
  32. 28 Extending Your Application
  33. 29 Calling C from Lua
  34. 30 Techniques for Writing C Functions
  35. 31 User-Defined Types in C
  36. 32 Managing Resources
  37. 33 Threads and States

FAQ

这本书对应Lua的哪个版本?
第4版主要面向Lua 5.3,这是作者撰写时的最新版本,书中详细介绍了5.3引入的整型、位运算等新特性。若使用5.4或更早版本,部分细节会有差异,建议对照对应版本官方手册。
没有其他编程语言基础能读懂吗?
不太合适。本书虽从基础语法讲起,但节奏较快,默认读者了解变量、循环、函数等通用概念。零基础读者建议先学一门入门语言,再回来看本书会更顺畅。
这本书和官方参考手册有什么区别?
本书是教程性质的系统讲解,重在讲清用法与设计思路,并配有大量示例和练习;官方参考手册则是逐条定义语言与标准库的规范文本,更适合作为查阅工具。两者搭配使用效果最好。
书里的C语言API部分需要什么基础?
需要能读懂C语言代码,了解指针、结构体与模块编译方式。如果只是用Lua写脚本,可以先略过第4部分,等需要做扩展或嵌入时再回头精读。
中文译本质量如何?
由梅隆魁翻译,术语基本沿用Lua官方中文文档的习惯用法,语句通顺。个别技术名词可能与其他资料译法不同,可结合英文原文或官方手册对照理解。

Comments

Find this book

This site is an index: you start “Search all sources” in your browser, and the entries it lists all point to third-party sites; please judge their availability yourself.

More by the same author

Top rated in the same category