dfhack
dfhack copied to clipboard
Add script-data.lua - A method for lua scripts to save data directly as json
This module is a resource for persistently saving lua tables directly with the json implementation. It handles either saving data globally (available anywhere) or as world data (specific to the save). World data is saved automatically whenever the world is unloaded, as well as whenever the game is saved via autosave or quicksave.
Ideally it needs somebody to go over and review a few things:
- Does the documentation make sense? Can you understand how to use the module from it? (I'm not great at articulating things >.>)
- Will the files save fine on every operating system (I've only checked for the OS I have - Windows 10)? I've not dabbled much in file system stuff before, and I can half-remember from somewhere that OSes can sometimes get picky about which slashes you use in file paths(?).
- Is this an okay way of handling this?
I guess I missed the boat to do this huh. I just converted my code for this into a class, I was gonna see about making it internal and a bit more generalized next. https://github.com/cppcooper/dfhack-scripts/blob/d07ce6688ecea340d4724646dbe319eca75006ea/dwarf-op2.lua#L543
I'm going through older PRs, and this looks interesting, but I'm a little confused. What benefits does this offer over the current feature set of persist-table and json? For example, would gui/launcher or emigration benefit from using script-data instead of the existing APIs?
This looks cool, but I think it has been superseded by the dfhack.persistent API