feat(ltk_lua): add lua manifest parser and scaffold new crate - #160
feat(ltk_lua): add lua manifest parser and scaffold new crate#160Crauzer wants to merge 1 commit into
Conversation
| #[repr(transparent)] | ||
| #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] | ||
| #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] | ||
| pub struct ScriptEntry(pub u64); |
There was a problem hiding this comment.
inner u64 shouldn't be public, should have a from_raw instead
| /// Lowercasing is ASCII-only, matching the game's `tolower`. Every name in a | ||
| /// shipped manifest is ASCII, so the distinction has never mattered in practice. | ||
| #[must_use] | ||
| pub fn hash_script_name(name: &str) -> u64 { |
There was a problem hiding this comment.
this being a free function feels kinda cringe, i think newtype would be nicer (or even just making this not public)
| Ok(()) | ||
| } | ||
|
|
||
| /// Writes a string with a `u32` length prefix (writes 4 + str.len() bytes). |
There was a problem hiding this comment.
can we leave a TODO here to destroy this in future
| #[must_use] | ||
| #[allow(clippy::cast_possible_truncation)] | ||
| pub const fn dir_index(self) -> u8 { | ||
| (self.0 & DIR_INDEX_MASK) as u8 |
There was a problem hiding this comment.
could we add a test to make this cast never break? (e.g enforce DIR_INDEX_BYTES <= 8)
| /// Nothing checks that `entries` and `shared` line up; that join is by hash | ||
| /// and is the caller's to maintain (see [`ScriptEntry::new`]). | ||
| #[must_use] | ||
| pub fn from_parts( |
There was a problem hiding this comment.
this should take impl IntoIterator's, and should have an unsafe _unchecked variant without the sort (downstream could be upholding the sort themselves w/ priority queue/insertion sort/etc)
| /// them. The shared list is observed sorted but is only iterated, and the | ||
| /// per-character script lists are **not** sorted in shipped files, so | ||
| /// neither is touched beyond the top level. | ||
| pub fn sort(&mut self) { |
There was a problem hiding this comment.
this shouldn't be public if the struct is supposed to uphold the sortedness as an invariant :3
What and why
Adds a new
ltk_luacrate for anything script related in the game. The first thing to be in there is the new LUA Manifest format.How it was tested
Parses and writes the current manifest one-to-one
The API might need more manual review, this PR was mostly vibe coded as a fun background side project.