[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: RE: require()
- From: "Bilyk, Alex" <ABilyk@...>
- Date: Thu, 23 Jan 2003 14:26:37 -0800
That's what I did in our project. The dofile was overloaded in order to load a file once. That was in Lua 4. Stack overflow is pretty silly IMHO and I would assume is a result of scarce human resources dedicated to official Lua implementation. I would allow loops and either complain about them to stderr or just let people work out run-time issues (if any) produced by such loops on their own rather than producing stack overflows. On the other hand, it is really easy to implement this in Lua itself and so it doesn't seem to be a big deal to me, just not pretty.
From: Wim Couwenberg [mailto:firstname.lastname@example.org]
Sent: Thursday, January 23, 2003 1:37 PM
To: Multiple recipients of list
Subject: Re: require()
> 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.