I’m trying a file require/linkage structure to simulate globals while still keeping everything local.
Basically, I’m storing references to information from many modules inside a settings module.
For example, module A requires the settings module and then inserts information inside a table in that module - sort of a reverse require method?
[lua]
local moduleA = {}
local function test () print(“test”) end ; moduleA.test = test
local settings = require(‘settings.lua’)
settings.table.moduleA = moduleA – add the module
settings.table.test = moduleA.test – add a function
[/lua]
I could then have module B require the settings module and then access the settings.table to retrieve items stored there by module A.
Module A could also retrieve it’s own information from settings.table
I’m treating settings.table as repository for all the other modules to get information (values, methods, tables ) from each other without direct requires to one another.
So far, it seems almost fine. When I do a globals check, nothing is triggered as global and I’ve avoided circular require reference errors. However, I have some memory leaks that I’m starting to think this structure is responsible for.
Maybe one of you Lua gurus can point out the pitfalls or flaws of trying this method. I’ve attached an image to try to illustrate what I’m doing.