Replies: 1 comment
-
In general, you need an intermediate representation. Many crates include it ( I'm not sure that bincode would work as it cannot serialize dynamically sized objects (eg Lua hash tables). // Encode
let value = lua.from_value_with::<ciborium::Value>(
Value::Table(lua.globals()),
DeserializeOptions::default()
.deny_unsupported_types(false)
.deny_recursive_tables(false),
)?;
let mut data = Vec::new();
ciborium::into_writer(&value, &mut data).unwrap();
// Decode back
let value = ciborium::from_reader::<ciborium::Value, _>(&data[..]).unwrap();
let lua_value = lua.to_value(&value)?;
println!("{lua_value:#?}"); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I want to serialize a table, and all its subdata, to a file. Then do the opposite operation (load the file, and deserialize it into a table).
Basically I'm looking to store the complete game state of a game engine in a Lua table, and I'm wondering if I can make the game's load/save feature a mere bincode serialization/deserialization (+ file I/O).
Is this possible with mlua? I'm able to serialize (using global just as an illustration; in practice it's a subtable):
But I'm unsure if it's possible to deserialize in a similar manner. The specific issue is that I load the bincode blob from a file into a
Vec<u8>
.. but then what?Beta Was this translation helpful? Give feedback.
All reactions