Page 1 of 1

Dum Question: Using the Data folder

Posted: Wed Mar 06, 2019 1:29 am
by Charidan
The development wiki suggests using a /data folder in the addon root to store new classes and/or raw data files. How do I then access those files from another?

I've got a helper class in /data/myclass.lua I'm trying to require into my /hooks/load.lua, but no matter what I put it tells me that this file is not found.

Is "require" the wrong keyword? Is there some sort of unix-like ../ equivalent I'm missing?

Re: Dum Question: Using the Data folder

Posted: Wed Mar 06, 2019 4:24 am
by Zizzo
Charidan wrote:The development wiki suggests using a /data folder in the addon root to store new classes and/or raw data files. How do I then access those files from another?

I've got a helper class in /data/myclass.lua I'm trying to require into my /hooks/load.lua, but no matter what I put it tells me that this file is not found.

Is "require" the wrong keyword? Is there some sort of unix-like ../ equivalent I'm missing?
Files in an addon's data/ folder are visible to the engine by the name "/data-<short_name>/path/to/filename", where <short_name> is as defined in your init.lua. data/ is just for data, though (hence the name); for new classes, you probably want overload/. So for instance, you might have overload/mod/class/MyClass.lua, and you would access that from other code via e.g.:

Code: Select all

local MyClass = require 'mod.class.MyClass'

Re: Dum Question: Using the Data folder

Posted: Wed Mar 06, 2019 8:38 pm
by Charidan
Ah, I knew I needed to put the addon-name in there somewhere, but I didn't try hyphenating it.

That said, good call on using an overload instead. I wasn't sure you could overload a file that didn't exist, but I should have just tried it.