Programming in Lua, Fourth Edition - Roberto Ierusalimschy

Programming in Lua, Fourth Edition

Roberto Ierusalimschy

出版社

Lua.Org

出版时间

2016-08-01

ISBN

9788590379867

评分

★★★★★
书籍介绍
Lua is spreading more and more throughout different areas of software, from embedded systems and mobile devices to the Web and the Internet of Things. Besides, it has a major role in the game industry, where knowledge of Lua has become an indisputable asset. Lua is the language of choice for anyone who needs a scripting language that is simple, efficient, extensible, portable, and free. Programming in Lua is the official book about the language, providing a solid base to any programmer who wants to use Lua. Authored by Roberto Ierusalimschy, the chief architect of the language, it covers all aspects of Lua 5---from the basics to its API with C. The book is the main source of programming patterns for Lua, with numerous code examples that help the reader to make the most of Lua's flexibility and powerful mechanisms. Programming in Lua is targeted at people with some programming background, but does not assume any prior knowledge about Lua or other scripting languages. This Fourth Edition updates the book to Lua 5.3 and marks a complete reorganization of the text. Building on his many years of experience teaching Lua, Roberto has restructured the book to present the material in a growing order of complexity, allowing the reader to better absorb the character of the language.
AI导读
核心看点
  • Lua之父亲笔撰写,官方权威指南
  • 涵盖Lua 5全貌,从基础到C API
  • 深入解析元表与闭包等核心特性
适合谁读
  • 希望系统学习Lua编程的开发者
  • 从事游戏开发或嵌入式系统的工程师
  • 需将Lua嵌入C/C++项目的程序员
读前提醒
  • 建议先精读前几章掌握基础语法
  • C API部分较难,按需阅读即可
  • 配合Lua用户Wiki查阅快速用法
读者共识
  • 语言设计简洁优雅,阅读体验极佳
  • 解释设计原理,优于普通速查手册
  • 内容详实但部分章节略显啰嗦

本导读基于书籍简介、目录、原文摘录、短评和书评生成,不等同于全文精读。

精彩摘录
  • "lua_call 函数完成一次无保护的调用,它类似于 lua_pcall,不过在发生错误时,它会传播错误,而非返回错误代码。在一个应用程序中编写主函数时,不应使用lua_call,因为这样需要捕获所有的错误。而编写C函数时,通常可以用lua_call。若有错误发生,只需将错误留下。 当一个 C 函数从 Lua 收到一个字符串参数时,必须遵守两条规则:不要在访问字符串时从栈中弹出它,不要修改字符串。 当一个 C 函数需要创建一个字符串返回给 Lua 时,C 代码还必须处理字符串缓冲的分配的释放、缓冲溢出等问题。"
  • "这个函数有点类似于 C 函数 sprintf,但是无须提供这个新字符串的缓冲。Lua 会动态地创建一个足够大的缓冲来存放字符串,确保不会有缓冲溢出等问题。这个函数会将结果字符串压入栈中,并返回一个指向它的指针。当前,这个函数接受的指示符只有:%%(字符%)、%s(字符串)、%d(整数)、%f(Lua 中的数字,即双精度浮点数)以及%c(接受一个整数,并将其格式化为一个字符)。除此之外,它不接受任何例如宽度或精度选项"
  • "通过这些函数,就无须再关心缓冲的分配、溢出等细节了。此外,这种连接算法也非常高效。"
  • "在调用setDefault后,任何对tab中存在字段的访问都将调用它的__index元方法,而这个元方法会返回0(这个元方法中d的值)."
  • "After the call to setDefault, any access to an absent eld in tab calls its __index metamethod, which returns zero (the value of d for this metamethod)."
  • "local function iter(a, i) i = i + 1 local v = a[i] if v then return i, v end end function ipairs(a) return iter, a, 0 end </代码结束>"
  • "在Lua中,函数是一种“第一类值”,它们具有特定的词法域。 第一类值是什么意思呢?就是说在Lua中函数与其他传统类型的值有着相同的权利。函数可以存储到变量中,也可以作为实参传给其他函数,还可以作为函数的返回值。"
  • "一个函数定义就是一个语句(准确地说是一个赋值语句),这种语句创造了一种类型为函数的值"
作者简介
Roberto Ierusalimschy is the leading architect of the Lua programming language, driving its development since its inception in 1993. He is an Associate Professor of Computer Science at PUC-Rio (the Pontifical Catholic University of Rio de Janeiro), where he works with programming-language design and implementation. Roberto has a M.Sc. Degree and a D.Sc. Degree in Computer Science, both from PUC-Rio. He was a visiting researcher at the University of Waterloo, ICSI, GMD, and UIUC, and a Tinker Professor at Stanford. As a professor at PUC-Rio, Roberto was the advisor of several students that later became influential members of the Lua community. Roberto is also a Distinguished ACM Speaker and a member of the IFIP Working Group on Language Design.
用户评论
海淘500rmb 来的原版 本来想翻译一发 结果出版社说已经有人在从事这个工作了……
写的简洁,讲的都是要点
比起第一版内容要详细很多,已经300多页了。有些地方不免有些啰嗦,想要快速知道一个事情的做法不如 lua users wiki。但是此书经常告诉你 lua 为什么要这么设计,和 Fluent Python 一样,是一本不可多得的好书。
小巧,速度在脚本中No1.就是库少了点,C的补充~
其实最后一部分关于 C 的还没看(暂时用不到,先放一放QAQ),不过前面看下来确实感觉挺灵活的,而且体积较小,甚至解释了为什么不用 POSIX regex 或者 Perl 正则表达式,因为他们太长了,快要有一半 lua 的标准库的代码那么多,最终 lua 的正则匹配只有 600 多行。记录一下:lua user wiki
Z-Library
收藏