Config not working as expected

Hello FP,

I wanted to do a config, I tried it in different ways…

First one was, I put the config ontop of my shared file which includes all(the config table itself is local), but then the files couldn’t load it,
then I tried making a config file which is shared, and gets included & sent as first file, and the other files couldn’t access the vars either,
then I tried including the config manually on each file, and they couldn’t get the vars either,

now my problem is, I don’t want any other addon to be able to access the config, therefore I made it local, but how can I make other files access it?

I thought ‘include’ is more or less, getting the code of a file, and putting it ‘technically’ in the one file, so as example my local config would be first, then it loads the rest, any help?

-- config file
local config = {

  option1 = ...,
  option2 = ...,


return config   <--- this is the key to this succeeding

-- some other file
local config = include( "path/to/config.lua" )    <-- now save the return value locally in your files so they can access it

Have you tried this? include() now passes its return value back to the caller since an update or 2 ago.

The reason it didn’t work when you (assumingly) weren’t returning the local config table is that it is declared file-local – its scope only extends to the end of the file.
Doing include() doesn’t actually include the script into another, it just executes it. So the file-local variable goes out of scope and can’t be used unless you return it manually

one global table which holds all the vars? I mean other addons could access it, so you just give it a long name that includes your alias?

I’ll try it, thanks.

Alright, it works now, thanks for that!

But now I’m asking, is it possible that I like, can ‘insert’ functions inside a table like config.functions, from a different file?

Like I got a config file, and a sql file, now I want to do(after getting the returned config) something like

config.functions.blah = function()

Would it inject this into the whole config table, making it accessable from other files(which get loaded after sql.lua), or would it only work in sql.lua? If it only would work in the file, how could I ‘insert’ a function into the table so other files from my addon ONLY can call it?

Unfortunately, the way it’s currently being handled means every time you run include( “path/to/config.lua” ), it is creating another table.

So every file that includes it gets a reference to a different table. Modifying one won’t affect the other. The only way (that I know of) to do what you’d like is to make the config global or stored within a global table somewhere (e.g., a namespace table for your addon). That way every file has the same reference to the table and modifications to it affect it in any file.

But you don’t want to use a global table, so I’m not really sure what else to do.

Sigh… I guess I’ll make a global config then… thanks for your help anyways!