Another method suggested by Owen Shepherd to the lua-l mailing list :
If we set package.loaded[current-module-name] at the beginning of each module, then any other require d module can later refer to the current (possibly incomplete) module.
A.lua:
local A = {} package.loaded[...] = A local B = require 'B' function A.foo() return B.bar() end function A.baz() return 42 end return A
B.lua:
local B = {} package.loaded[...] = B local A = require 'A' function B.bar() return A.baz() end return B
This will not work everywhere. For example, if the initialization of B depends on A.baz , then it will not work if A is loaded first, because B will see an incomplete version of A in which baz has not yet been defined.
finnw
source share