lua-users home
lua-l archive

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


On 20/12/2012 09:47, Geoff Leyland wrote:
Hi,

I'm tidying up some code and moving towards compatibility with 5.2.  In particular, I'm getting rid of "module".  I have some code where file A requires file B, and file B in turn requires file A.  I used to get around this with a bit of require ordering and the fact that "module" filled in package.loaded early.  Without module that doesn't work.

At the moment, I'm considering requiring one of the modules inside the function that actually uses it, so it gets initialised on first use, which, really, all seems a bit of overkill.

Can anyone point me to the obvious and simple solution?

Below is a sort of test case of the code - a little system for evaluating expressions.  As one file, it works (with a forward declaration of add) but if I cut it into modules at the "-----" markers and start using require, there's a require loop.  Surely I'm missing something?

Cheers,
Geoff

I asked this on StackOverflow about a year ago, and eventually came up with the same solution that Steve suggested:

http://stackoverflow.com/q/8248698/12048