Looping require

Basic question:

I have 2 files: a.lua and b.lua

If a.lua does a require(“b”) and b.lua does a require(“a”) I get this error:

loop or previous error loading module

But I legitimately need a.lua to call some functions in b, and vice-versa. Am I missing something? [import]uid: 92621 topic_id: 25837 reply_id: 325837[/import]

Try assigning it to a variable to use it like

objA = reqiure"a"

call the function

objA.SomeFunction()

See if that works.

Larry
DoubleSlashDesign.com [import]uid: 11860 topic_id: 25837 reply_id: 104480[/import]

Hi Larry, I usually do assign it to a variable but still get the same error. [import]uid: 92621 topic_id: 25837 reply_id: 104533[/import]

Try to rethink your code structure.
If A relies on B, and B relies on A, in a way that one can`t load independently first, then it should throw up a red flag.

http://en.wikipedia.org/wiki/Circular_dependency

It`s hard to provide useful solutions to help that structure, but possibly creating a third Utilities class that contains some of the required functions, or possibly allowing A to entirely contain B. These are wild guesses, as I don’t know what A and B are supposed to do.

You cannot in Lua have A.lua load B.lua and B.lua load A.lua due to how files are parsed and interpreted (it would create an infinite loop and crash, because it would be never be able to finish loading A or B)

If you give a bit more context maybe me or someone else could provide a different stucture/design that would remove the issue. [import]uid: 134101 topic_id: 25837 reply_id: 104535[/import]

Yeah creating a third Utilities class would be the way to go.

Otherwise your creating a recursive loop in your app, and that’s why LUA is bombing more than likely.

Good Luck

Larry
[import]uid: 11860 topic_id: 25837 reply_id: 104543[/import]