Nuke, I think you missed what was meant by "using cfile". cfile in the context of FSO is not the C file api (ie. the ISO standard functions for File IO; fopen, fwrite, etc.) but but the name of a code file "cfile.cpp" that contains
all (with very few exceptions, lua being one) methods of accessing the filesystem in the engine. cfile.cpp it what the argument of the -mod flag is passed to, and is what allows the engine its ability to be modded to the extent that it can. It is also because of cfile that FSO does
not know or even care what mods are actually passed via the -mod flag.
FSO's cfile api allows code anywhere in the engine to load a file by just passing the files name and cfile will search the folder that corresponds to its extension in the first listed mod folder, then every .vp in the first listed mod folder that has the folder that corresponds to the extension, this is repeated for every mod folder listed, then for the root folder. For example, say -mod mod1,mod2,mod3 is passed to FSO and that you requested atmospheric.lua, cfile will search inorder:
- mod1/scripts/atmospheric.lua
- mod1/vp1.vp:data/scripts/atmospheric.lua
- ...
- mod1/vpn.vp:data/scripts/atmospheric.lua
- mod2/data/scripts/atmospheric.lua
- mod2/vp1.vp:data/scripts/atmospheric.lua
- ...
- vp1.vp:data/scripts/atmospheric.lua
- ...
- vpn.vp:data/scripts/atmospheric.lua
- data/scripts/atmospheric.lua
until it finds a file that exists. This behaviour is also what allows for the mixing of game assets, like blue planet and their layering of the ships to have new designs but still have the stock FS2 and FSU assets. Even
used this principle of cfile to allow for normal effects and advanced effects to be activated by adding a .vp (the name of which escapes me) that is earlier in lexical sorting, so that cfile will search and find the high end version of a graphic in the new .vp rather than using the low end one in the Root.vp.
just because it shouldnt care where it is, doesnt mean it that it does not need to know where it is. scripting kinda also needs to know where it is, then scripters and modders dont need to make any guesswork as to where lua files are locted, just call a function for the correct path. ideally every lua function should work relative to the mod dir, but there are some built in functions, like dofile, that like to run relative to the program root. so this kinda helps meet that goal.
No, this is where the problem lies, the script should not care nor should it know where it is located on the filesystem. As I described above, lua is circumventing how the
entire engine finds
all of its resources. The built-ins that do not use cfile should either be modified to use cfile or removed and replacements implemented which will use cfile. Using cfile does make the scripts more modifiable and flexible.
Using cfile allows anyone to do mods based on your scripting work by just putting your mod in the -mod list and having their work before yours, that way they could change the interface or the ship models, etc.
Nuke.. Why wont just use cfile and let it do the file locating for you?
dofile is equivalent to an include call in c, it has a completely different usage from cfile. dofile helps make script more modular and for large scripts, much more organized.
From your description, Nuke, it seems you are trying to use dofile as a replacement for function calls. Is there something wrong with the function calls in lua? FSO's lua?
In short, I do not mean to call you out Nuke, but why should lua be exempted from the resource location system that the rest of the engine has?