lua-users home
lua-l archive

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


> > How about you set the __index metamethod of the package.preload table and
> > use it to trap package load attempts and dispatch them any way you might
> > want?
> 
> I didn't think of that, but the idea of changing internal structures
> doesn't attract me either.
> [snip]
> Anyway, i don't think this would bloat the core. I know Lua was
> designed to be kept small, but since the package system was added i
> don't think the module loading modification will hurt.

Surely you couldn't really have a better answer than Diego's: 
adapt and extend the language in and with the language.

You were asking, IIRC, for per-package callbacks to allow 
the package loading to be overridden on a packge-by-package 
basis. And since the package loader works through a Lua table
by design...you already have exactly the functionality you need,
by design. The hooks are already there, so why add more?

(Don't think of changing __index as "changing internal structures",
as you you were dereferencing a FILE * yourself in a C program.
Think of it in terms of of "ask not what you can do for Lua, but
what Lua can do for you" :-), and see Chapters 13 to 16 in PIL.)