Show HN: Ldump – serialize any Lua data
96 points| girvel | 1 year ago |github.com
It is a polished version, thoroughly annotated, tested and documented. It is made to be as functional and customizable as possible (or at least I did everything I could think of). I would be happy to hear suggestions/corrections for both code and documentation -- even nitpicky ones.
lifthrasiir|1 year ago
girvel|1 year ago
Overall, it would be nice to make it safer. I don't think switching to non-Lua format would make it safer, because it is intended to serialize functions too, which can have arbitrary code even if everything else would be stored as data. Maybe it is possible to make a function like `ldump.safe_load` restricting `load`'s environment, so it wouldn't have access to debug/os/io modules.
ithkuil|1 year ago
girvel|1 year ago
JourneyJourney|1 year ago
nicoloren|1 year ago
I'm thinking of starting to dev a game with LOVE2D just to have an excuse to use Lua.
je42|1 year ago
aldanor|1 year ago
koeng|1 year ago
I have a long-running script. At several steps, the execution of the script has to pause for a long time for operations to be done in-real-life (biological experiments, so think wait time being like 2 days between running), before getting some data and continuing to run. From what I can see in this, I'd add yielding coroutines at data pause points, right? How would you handle that?
appleorchard46|1 year ago
Semi-unrelated - you say you're using tables as keys in your project. I didn't know you could do that! What are you using it for?
girvel|1 year ago
GranPC|1 year ago
sebstefan|1 year ago
Does the function still need to be in memory to be loaded again ("does it just dump the pointer") or can I save it to disk, shut off the interpreter, boot it again and it imports it fine (in which case it somehow dumps them as code...?)?
Even in the linked test case on the readme you don't show the output/expectation of the serialization
myrmidon|1 year ago
Yes, it dumps them as bytecode (probably not compatible between completely different interpreters).
It even preserves debug metadata, so stack traces involving serialized/deserialized functions look right, and still show the original source file.
This is really neat.
lifthrasiir|1 year ago
girvel|1 year ago
I didn't include asserts in the linked case, because I thought it would be too verbose. You can see asserts in the test, that is linked below the example. Maybe it was the wrong call, I will think about including asserts into the example itself.
bflesch|1 year ago
nicoloren|1 year ago
[1] https://github.com/kikito/inspect.lua
sebstefan|1 year ago
jhatemyjob|1 year ago
myrmidon|1 year ago
There is not even significant overlap in what they do; all that %q does is sufficiently escape Lua strings so the interpreter can read them back. It does not serialize functions nor even tables in any shape or form.
edit: Sorry for being unreasonably harsh after misunderstanding your message.
girvel|1 year ago
gvx|1 year ago
girvel|1 year ago
brunocroh|1 year ago
synergy20|1 year ago
girvel|1 year ago
098527222722|1 year ago