Programming In Lua Comments

lua-users home
wiki

This page is for comments, errata, and discussions on the book [Programming in Lua] by Roberto Ierusalimschy.

Second Edition Comments

2.4 - Why is concatenation (..) right associative? See AssociativityOfConcatenation.

2.5 - Concerning "An associative array is an array that can be indexed not only with numbers, but also with strings or any other value in the language, except Nil" and also 27.3 - p.252 - "The registry is a regular Lua table. As such, you can index it with any Lua value but nil." NaN can fail too--see LuaList:2008-03/msg00603.html .

This is probably because, by definition, Nan != Nan, which violates the hash table requirement that keys be comparable for equality. --ChrisRebert?

2.5 - What is the computational complexity of # and table.maxn? --DavidManura

Again, that's more a language question than a book question. In most cases, the computational complexity of # is O(log Na), where Na is the size of the array part of the table. table.maxn is O(N) where N is the total allocated size of the table, because every key has to be examined. --RiciLake

27.3 - p.254 - spelling: register -> registry (in "favor the environment over the register")

28.2 - The luaL_newmetatable/luaL_getmetatable/luaL_checkudata functions use a C string as a key into the registry. I'd prefer simply using a lightuserdata for this or storing the metatable as an upvalue (more efficient and less error prone). I also avoid passing a name to luaL_register because there's an unnecessary risk of name conflicts, and this sets a global variable much like the module function criticized in LuaModuleFunctionCritiqued. --DavidManura

First Edition Comments

(none currently)

Other Comments

(none currently)


RecentChanges · preferences
edit · history
Last edited April 9, 2008 3:56 am GMT (diff)