lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Mon, Apr 25, 2011 at 07:13:25PM +0400, Alexander Gladysh wrote:
> 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!

It's bittorrent related. Sharing is caring ;)

I didn't want to wait until someone has to reinvent the wheel, making my
attempt obsolete.

> >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.)

Oh, I didn't think about that. Thanks!

> 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

I thought of this as well, but deferred it... I don't remember why, but the
first version of the file said that the implementation was probably suboptimal
in the header. Since this applies to most code anyway, I decided to remove it.

> 3. In library code it is much better to return nil, error_message than
> to throw error().

Yep, it's a bit too much error(). People will presumably always have to use
pcall the way it is right now.

> 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.

Ah, yes, I'm lazy. It does mostly what it's supposed to do, and so far, it's a
start.

Thanks for the feedback, I will fix it up sooner or later.

Best regards,

Moritz