Programming in Lua

by Roberto Ierusalimschy

Errata for the First Edition

Errors in Code Examples


  1. page 49, in function list_iter:

    return (i <= n) and t[i]
    should be
    if i <= n then return t[i] end
    (Thanks to Anders Topper).
  2. page 74, third chunk of code: printResult(v) should be printResult(p).


  3. page 76, in function download: return count should be print(file, count). (On the next page, in function receive, settimeout may be timeout, depending on the version of LuaSocket that you use.)


  4. page 92, last chunk of code: for j=i,M do should be for j=1,i do (thanks to Enrico Colombini).


  5. page 122, second chunk of code:

    if rawget(var) == nil then
    should be
    if rawget(_G, var) == nil then

  6. page 126, function complex.inv:

    return complex.new(c.r/n, c.i/n)
    should be
    return complex.new(c.r/n, -c.i/n)
    (Thanks to John Hauser).
  7. page 129, first chunk of code:

    if rawget(_REQUIREDNAME) == nil then
    should be
    if _REQUIREDNAME == nil then

  8. page 130, second chunk of code: Similar to previous correction.


  9. page 139, last chunk of code:

    if self.balance - v <= self:getLimit() then
    should be
    if v - self.balance >= self:getLimit() then
    (thanks to Yu Ping Hu).
  10. page 144, first chunk of code, function getBalance:

    return self.balance + self.extra()
    should be
    return self.balance + extra()
    (thanks to Byron Mattingly).
  11. page 162, last chunk of code: PI should be math.pi (thanks to Florian Berger).


  12. page 167, third and fourth chunks of code: strfind should be string.find (thanks to Florian Berger).


  13. page 190, second chunk of code:

    print(setlocale("ISO-8859-1", "collate"))    --> ISO-8859-1
    should be
    print(os.setlocale("ISO-8859-1", "collate"))   --> ISO-8859-1
    (thanks to Florian Berger).
  14. page 190, last chunk of code: That example only works in interactive mode (thanks to Luiz Henrique de Figueiredo).


  15. page 204, first chunk of code:

    vfprintf(stderr, argp);
    should be
    vfprintf(stderr, fmt, argp);
    (thanks to Alan Ritter).
  16. page 213, last chunk of code:

    #include <lua.h>
    should be
    #include <lua.h>
    #include <lauxlib.h>
    
    (thanks to Florian Berger).
  17. page 219, first chunk of code:

      return (x^2 * sin(y))/(1 - x)
    should be
      return (x^2 * math.sin(y))/(1 - x)
    (thanks to Tomas Gorham).
  18. page 223, only chunk of code; and page 224, second chunk of code:

    static int l_sin (lua_State L) {
    should be
    static int l_sin (lua_State *L) {
    (thanks to Helcio Mello).

Typographical errors


  1. page xvi, first and second paragraphs: htpp should be http. (Thanks to Florian Berger).


  2. page 13, Section 2.5, second paragraph: IndexPascal should be Pascal.


  3. page 34, fourth chunk: a = {foo() should be a = {foo0() (thanks to Tomas Gorham).


  4. page 39, second from last line: oder should be other (thanks to Kurt Jung).


  5. page 73: call permget with should be call permgen with (thanks to Tomas Gorham).


  6. page 82, second line: "can becomes" should be "becomes" (thanks to Enrico Colombini).


  7. page 139, end of the first (long) paragraph: "and there if finds" should be "and there it finds" (thanks to Tomas Gorham).


  8. page 184, fourth line: "of any like" should be "of any line" (thanks to Steve Elkins).


  9. page 201, fourth line: "You may be wandering" should be "You may be wondering" (thanks to Steve Elkins).


  10. page 204, first line after second chunk of code: "and is using" should be "and are using" (thanks to Enrico Colombini).


  11. page 214, second-to-last paragraph: "the user is already able do" should be "the user is already able to do" (thanks to Tomas Gorham).


  12. page 233, last paragraph of Section 27.2: "it is an error to call this function is the" should be "it is an error to call this function if the" (thanks to Tomas Gorham).


  13. page 256, third comment in first chunk of code: "prepare environment for hanlders" should be "prepare environment for handlers" (thanks to Tomas Gorham).