-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
88157f3
commit e87b07e
Showing
5 changed files
with
475 additions
and
288 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
resolver = "2" | ||
members = [ | ||
"morphing", | ||
"morphing-macros", | ||
"examples", | ||
"winit-egui-wgpu-template", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[package] | ||
name = "morphing-macros" | ||
version = "0.1.0" | ||
authors = ["YishiMichael"] | ||
edition = "2021" | ||
|
||
[lib] | ||
proc-macro = true | ||
|
||
[dependencies] | ||
darling = "0.20.10" | ||
quote = "1.0.38" | ||
syn = "2.0.96" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use darling::FromMeta; | ||
use proc_macro::TokenStream; | ||
|
||
#[derive(FromMeta)] | ||
struct SceneArgs { | ||
override_settings: Option<syn::Path>, | ||
} | ||
|
||
#[proc_macro_attribute] | ||
pub fn scene(input: TokenStream, tokens: TokenStream) -> TokenStream { | ||
let args = match darling::ast::NestedMeta::parse_meta_list(input.into()) { | ||
Ok(args) => match SceneArgs::from_list(&args) { | ||
Ok(args) => args, | ||
Err(error) => return TokenStream::from(error.write_errors()), | ||
}, | ||
Err(error) => return TokenStream::from(darling::Error::from(error).write_errors()), | ||
}; | ||
let scene_fn = syn::parse_macro_input!(tokens as syn::ItemFn); | ||
|
||
let scene_name = scene_fn.sig.ident.clone(); | ||
let scene_settings = quote::format_ident!("__scene_settings"); | ||
|
||
let override_settings_stmt = if let Some(override_settings_path) = args.override_settings { | ||
quote::quote! { | ||
let #scene_settings = #override_settings_path(#scene_settings); | ||
} | ||
} else { | ||
quote::quote! {} | ||
}; | ||
let block = quote::quote! { | ||
pub fn #scene_name( | ||
#scene_settings: ::morphing::toplevel::settings::SceneSettings, | ||
) -> ::morphing::toplevel::app::scene::SceneTimelines { | ||
#scene_fn | ||
#override_settings_stmt | ||
::morphing::toplevel::app::scene::SceneTimelines::new(stringify!(#scene_name), #scene_settings, #scene_name) | ||
} | ||
}; | ||
block.into() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.