Thought about Lua and using tables as file format


Just [reading throught this book][1] about Lua and found an interesting chapter (#12.1). Actually there is an [older version available online][2], which includes more or less the same text in chapter 12.

The chapter talks about the idea to save data as usable (Lua-) code in a file. I have tried it out and really like the idea and way how it works. More or less if you read the file, you can “execute” the code which is included and it will be available to you without too much further processing.

This might not only be an option to save data in a mod (depending on what kind of support Stonehearth offers here), but also to exchange information between mods. Modders could write only one function which handles input and could get this input either from a file or from another mod (like an “event”?).

If you are interested in ways to save informationi in a file… might be worth a look.
[2]: Programming in Lua : 12


indeed… this is a very helpful (and powerful) feature… and obviously similar in nature to what @Tom was describing in yesterday’s stream (with the embedded code within HTML blocks calling relative URLs, and executing the results)…


Exactly, that’s why it came back into my mind. Though I have understood that in the stream this was JSON-data, not Lua-code.


yes sir, i believe you are correct… same general idea, different means of execution…

and speaking of the stream, i think i need to finish listening this morning…


A key difference as far as I can tell between JSON and this though is sanitization. This would allow for code to be inserted into the mod to potentially allow for hacks which could seriously matter for mp mod checking, JSON is a subset if JS instead to overcome that issue. Although I’m probably not the best when it comes to this as I tend to overdo compression to a massive degree, binary saves that should really be readable and spending stupid amounts of time deciding whether a single bit could be removed.

Supposedly the save/load stuff isn’t lua so it’s likely we just get an api to save settings/data, we’ll likely get little to no fs powers as well. Official support would be good though as official support tends to cause less quibbles than community support.