Localise external module

Hi, the setup I have is a main.lua scene that requires a bunch of modules, one such like so:

mNav = require(“mNav”)

This is not local to main because we want to access functions within mNav in other scene modules, like this in the page_1.lua module:

page_1.lua

mNav.new()  – calls function mNav.new in mNav.lua.

Question, how do we make mNav local to other modules given it has already been required in main.lua.

Does local mNav = mNav within other modules such as page_1.lua do it?

Using Director.

Use local mNav=require(“mNav”)
At top of each module needed in

To add to what @jstrahan said, when you include the same module multiple times (in different modules), it’s still only loaded once, the first time.  It’s just now locally referenced where you need it.

So avoid only calling mNav once in main.lua and instead require it 30 times?

30 is the number of scenes that would each be calling require(“mNav”). Certain we encountered unexpected performance in the past when calling require on the same file multiple times…

Can someone give a definitive here - require globally once in main.lua OR require locally the same file x 30 times.

Just got your reply there thanks Rob. Miraculously, in the minutes I was taking to write my last post, you had replied already.
Cool.
So - we are going to local require across the pages…

Use local mNav=require(“mNav”)
At top of each module needed in

To add to what @jstrahan said, when you include the same module multiple times (in different modules), it’s still only loaded once, the first time.  It’s just now locally referenced where you need it.

So avoid only calling mNav once in main.lua and instead require it 30 times?

30 is the number of scenes that would each be calling require(“mNav”). Certain we encountered unexpected performance in the past when calling require on the same file multiple times…

Can someone give a definitive here - require globally once in main.lua OR require locally the same file x 30 times.

Just got your reply there thanks Rob. Miraculously, in the minutes I was taking to write my last post, you had replied already.
Cool.
So - we are going to local require across the pages…