[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: require()
- From: "Wim Couwenberg" <w.couwenberg@...>
- Date: Thu, 23 Jan 2003 22:36:43 +0100
> I know I can arrange an own
> solution to suppress both behaviours (patch require or check if a
> file is already slowly dofiled) but I feel that require() should do this
> alone. Now require isn't so much usefull as it could be. And I don't see
> arguments to let require() as it is.
Well circular module dependencies _may_ cause trouble and can therefore not
easily be supported in general. In some cases, the following might work.
Mark the module as loaded (in the global _LOADED table) just before
"luaB_require" runs the module (in lbaselib.c, ln 480 for lua5.0b) instead
of afterwards. This prevents cyclic loading of packages. If the modules
involved do not actually use any other module's variables in their _global_
scope then this will do the trick. In other cases the behavior may be
Btw, generically speaking, it will be possible to factor out the "common"
stuff in cyclic dependencies, thereby breaking the cycles. I think this
should be the preferred method, though it may take some (tricky) redesign.