Can I get the path to the current file?
Posted: Sat Feb 20, 2021 12:24 pm
Is there a way to get the name of and path to the file that is currently processed, so I can log it?
Use case: I'm cleaning up the data*lua files of BI, moving out compatibility code for other mods to external files. There are a lot of files with similar names (e.g. "updates/mod_name.lua" and "final-fixes/mod_name.lua"), and I've moved files between folders several times. In order to check that I didn't forget to require a file, I want to output the file path and name whenever a file is entered. Using fixed strings for that is not an option because I may forget to change the message text after moving or renaming a file.
I know that something like this would work:
log() automatically adds path, filename, and even the line number to the output. However, I've made a wrapper that will only write to the log in my mod's debugging mode, as I don't want to spam the log unnecessarily. The problem is that all output will be preceded by path + name of the file containing the wrapper function, so that information is basically useless. Therefore, I'd like to find a way to do something like this:
Is that possible somehow?
Use case: I'm cleaning up the data*lua files of BI, moving out compatibility code for other mods to external files. There are a lot of files with similar names (e.g. "updates/mod_name.lua" and "final-fixes/mod_name.lua"), and I've moved files between folders several times. In order to check that I didn't forget to require a file, I want to output the file path and name whenever a file is entered. Using fixed strings for that is not an option because I may forget to change the message text after moving or renaming a file.
I know that something like this would work:
Code: Select all
if not BI.check_mods("alien-biomes") then
log("Nothing to do!")
return
end
Code: Select all
if not BI.check_mods("alien-biomes") then
log_wrapper(get_current_file_name() .. ": Nothing to do!")
return
end