lua-users home
lua-l archive

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

Luiz Henrique de Figueiredo wrote:
> >I don't know what the plan for Lua and library loading might be, but my
> >libraries stash their name and version number in the _LIBS_LOADED
> >global, if it exists.
> Use the registry instead. The registry is an ordinary Lua table that is
> always available. It was introduced in 4.0 just for this kind of application.
> --lhf

Well, that makes sense, except that there is no obvious way of a Lua
program getting that information. Of course, it would be easy enough to
write some glue to export a _LIBS_LOADED key from the registry back into
the Lua environment but I'm not sure what's gained by that, exactly.

I just use this so that I know what's kicking about in my Lua runtimes;
I haven't really formalised into anything special. I wanted something
simple to get at in either Lua or C, so that a Lua library could use it
equally well. The start.lua that runs by default (in my normal
environment, anyway) prints the keys and values of this table, which I
find a handy clue sometimes as to where I'm at.

I did try using the Lua registry at one point. It seemed like a useful
idea, but I usually find that closures work better, as well as avoiding
the awkwardness of trying to impose a naming structure on the world for
registry keys, as long as the information is private to a single
library. For C libraries that need an interfacing structure, the
registry would be fine, I think, but I haven't yet come across that
need; I suppose it would apply if one depended on another one, which is
probably where you're coming from now that I think of it....

Anyway, thanks for the suggestion.