lua-users home
lua-l archive

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


On Thu, 11 Sep 2008, Mike Pall wrote:

Apparently stdlib has not been updated to use Lua 5.1 semantics
regarding varargs.

This is true in just the one instance given (that of stdlib's string.format extension). Thanks to David Kantowitz for bringing this to my attention; I'll make a release in a few minutes with a fix.

Anyway, stdlib has some strange code like:
  if #arg == 0 then ...
Which is mixing Lua 5.1 syntax (# operator) and Lua 5.0 syntax
(arg table).

Indeed, stdlib still has code like this. But it's not incorrect: there are two cases where it's used:

1. It is desired to operate on the table of varargs. The code will be preceded with a line like this:

local arg = {...}

2. Where the code is referring to the top-level arg table of the standalone interpreter. From the manual:

"Before starting to run the script, lua collects all arguments in the command line in a global table called arg."

I don't see any hint that this is deprecated.

There's more ugliness inside like an __index function for the string metatable, overriding lots of standard functions and in general adding lots of bloat.

This is very much the point of stdlib. It adds __index to the string metatable as a convenience, and similarly overrides the standard functions to add conveniences that the Lua team have not seen fit to add. Almost all the extensions to standard types and functions in stdlib only extend the existing semantics, rather than altering them. For example, string.format is extended so that if only one argument is given, it is printed as a string, i.e. "string.format (s)" becomes "string.format ("%s", s)".

Of course, there are also a lot of general-purpose functions not found in the built-in library.

So I suggest to stay away from it.

I suggest rather that you criticize and improve it. stdlib was started as a project to build general-purpose pure-Lua libraries. Sadly, it has not exactly prospered, though I still maintain it. Almost all the code in it I wrote or gathered for particular uses. As I don't program much in Lua any more, I don't add to it.

One other thing of note is that I'm actually quite anti-bloat. I have only added things that seem to me to be widely useful (with one or two odd exceptions like the mbox parser, which I simply wanted to preserve), and that I've used in my own code. In particular, I have occasionally removed functions that I ended up deciding were too special-purpose, and I have removed several functions that were obsoleted by new features or functions in Lua releases.

I think stdlib is not without value: much of the code in it is reasonably well tested, and all of it is reasonably well documented. The design of the library has had quite a bit of thought put into it. There's a lot left to be desired: in particular, there are no systematic tests, and much of the code could be written more efficiently. The coding style is largely but not entirely consistent. The dependencies between modules are expressed, but few modules can be loaded without pulling in most of the library. There's no automatic dependency detection, which there could and should be.

If an active Lua programmer would like to take over the project, I'd be delighted. I think stdlib still fills an otherwise unfilled hole in the space of Lua libraries.

--
http://rrt.sc3d.org/ | RSA, n.  safety in numbers