Is there a way to have
- Two Lua modules (let's call them
AandB) - Each module uses functions from the other, so they must
requireeach other - A third module (let's call it
C) can useAbut notBe.g.
C.lua:
local A = require 'A'
-- ...
A.foo()
- There may be another module
Dthat requiresBbut notAand/orErequiring bothAandB - Neither
AnorBnor their members should be added to the global namespace. - Avoid using the
moduleandsetfenvfunctions (deprecated in Lua 5.2)
Related: Lua - how do I use one lib from another? (note: this solution does not handle circular dependencies.)