lua-users home
lua-l archive

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


> "Peter Hill" <corwin@i...> wrote:

> Hmm, I hadn't thought about circular require() but you have a point.

> To help detect such errors perhaps _LOADED should have three states
> for a library:
> - unloaded
> - partially loaded (set when require() starts).
> - loaded (set when require() ends).

Now you get the point. In more detail both ways are usefull:

- mark as loaded on start of the required file
  it must be already loaded to start
  and inside the table is named _LOADED
- mark as finished initialised
  but this second form is *useless* in conjunction with require()
  require() never now if init of the required file was successfull
  so for that point you have to implement an own check system

> An attempt to require() a partially-loaded library will report an
> error about circular library references (and will abort the load, even
> if the error function choses to 'continue' processing).

I don't think that this is an error. Its an big mistake is to protect
the user against programming "errors". Especially Lua is so well
designed to give a enormous freedom.

> That way we get circular-reference errors if we stuff up, and if
> someone actually wants a certain circular reference then they can
> explicitly override the error function around the require() call.

Using loops is the base of programming! Do you allow recursive
progamming? Then why? Its a good place for infinity errors. So disallow
it. You won't do that right? Then: I can't see any good argument to
disallow a loop usage with require().

And has to override it each time he needs require(). I don't accept this
overhead. The question is why is there a require() loop? Do you write
programms and surprisingly there is a require() loop you don't like? I
don't think so.

I have already patched require to set the correct behaviour.



Markus