[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [ANN] bencode-1
- From: Alexander Gladysh <agladysh@...>
- Date: Mon, 25 Apr 2011 19:13:25 +0400
On Mon, Apr 25, 2011 at 13:15, Moritz Wilhelmy <ml+lua@wzff.de> wrote:
> After finally finishing my rockspec for it after three years of dusting (it was
> finished in April 2009, but has never been announced anywhere), I have been
> suggested to announce my bencode module to this list as well.
Thank you for sharing!
>From reading the code[1] I see several potential minor problems:
1. You do not check for self-referencing tables. (t = { }, t[t]= { t } etc.)
2. You concatenate strings in place. This is really slow as it creates
a lot of garbage. Instead keep a buffer table and table.concat() it
when you're done.
See here for one of the approaches on how to solve first two problems:
https://github.com/lua-nucleo/lua-nucleo/blob/master/lua-nucleo/tstr.lua
3. In library code it is much better to return nil, error_message than
to throw error().
4. You do not alias Lua API globals to local variables at the top of
the file, making your module harder to use in sandboxed environments.
My 2c.
HTH,
Alexander.
[1] — https://bitbucket.org/wilhelmy/lua-bencode/src/74d63caac458/bencode.lua#cl-29