lua-users home
lua-l archive

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

Leo Razoumov wrote:
> Isn't  require supposed to set  package.loaded[modname]  to some true
> value *before* it executes the module chunk to prevent a possibility
> of an infinite recursion? If it is not the case and require can cause
> an infinite recursion then it is a bug in Lua module system.
> Requiring modules can produce cycles  (directly or indirectly) and a
> package loader should be prepared to handle this possibility.

The old "module" function did that, it created a module table and set
package.loaded[modname] right at the start of the module.

Without the "module" function you would have to do it yourself:

    local M = {}
    package.loaded[...] = M

    -- implement the module, cyclic requirements are now valid.

    return M

Best regards,

David Kolf