Skip to content

Commit

Permalink
#1322 Make it possible to skip fields marked with #[default = "bla"] …
Browse files Browse the repository at this point in the history
…in Luau
  • Loading branch information
helgoboss committed Nov 12, 2024
1 parent 3ff8b8c commit 8aeb7ce
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
14 changes: 13 additions & 1 deletion api/src/bindings/luau/luau_converter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,11 +394,23 @@ pub struct SerdeArgs {
#[darling(default)]
untagged: bool,
#[darling(default)]
default: Option<()>,
default: Option<FlagOrStringAttribute>,
#[darling(default)]
flatten: bool,
}

#[derive(Debug)]
struct FlagOrStringAttribute;

impl FromMeta for FlagOrStringAttribute {
fn from_meta(item: &Meta) -> Result<Self, darling::Error> {
match item {
Meta::Path(_) | Meta::NameValue(_) => Ok(Self),
_ => Err(darling::Error::unsupported_format("no default")),
}
}
}

impl<'a, H: Hook> Display for LuauEnum<'a, H> {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
let args = serde_args(&self.value.attrs).next();
Expand Down
1 change: 1 addition & 0 deletions playtime-api/src/persistence/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1255,6 +1255,7 @@ pub struct Clip {
/// It then sets this section to the portion that actually matters. Once set, this section
/// rarely changes.
#[serde(alias = "section")]
#[serde(default)]
pub fixed_section: Section,
#[serde(default)]
pub pitch_shift: Semitones,
Expand Down
12 changes: 6 additions & 6 deletions resources/api/luau/playtime.luau
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ export type MatrixClipRecordSettings = {
play_start_timing: ClipPlayStartTimingOverrideAfterRecording?,
play_stop_timing: ClipPlayStopTimingOverrideAfterRecording?,
time_base: ClipRecordTimeBase?,
looped: boolean,
looped: boolean?,
midi_settings: MatrixClipRecordMidiSettings?,
audio_settings: MatrixClipRecordAudioSettings?,
}
Expand Down Expand Up @@ -747,8 +747,8 @@ function module.ColumnSettings(value: ColumnSettings): ColumnSettings
end

export type ColumnClipPlaySettings = {
follows_scene: boolean,
exclusive: boolean,
follows_scene: boolean?,
exclusive: boolean?,
track: TrackId?,
start_timing: ClipPlayStartTiming?,
stop_timing: ClipPlayStopTiming?,
Expand Down Expand Up @@ -1018,11 +1018,11 @@ export type Clip = {
start_timing: ClipPlayStartTiming?,
stop_timing: ClipPlayStopTiming?,
velocity_sensitivity: number?,
looped: boolean,
looped: boolean?,
volume: number?,
color: ClipColor?,
dynamic_section: Section?,
fixed_section: Section,
fixed_section: Section?,
pitch_shift: Semitones?,
audio_settings: ClipAudioSettings?,
midi_settings: ClipMidiSettings?,
Expand All @@ -1033,7 +1033,7 @@ function module.Clip(value: Clip): Clip
end

export type ClipAudioSettings = {
apply_source_fades: boolean,
apply_source_fades: boolean?,
time_stretch_mode: AudioTimeStretchMode?,
resample_mode: VirtualResampleMode?,
cache_behavior: AudioCacheBehavior?,
Expand Down

0 comments on commit 8aeb7ce

Please sign in to comment.