1
0
Fork 0

Refactor(lua_macros): Remove dead code

This commit is contained in:
Benedikt Peetz 2023-07-17 07:23:36 +02:00
parent fc880d47d2
commit 91ea3f65ea
Signed by: bpeetz
GPG Key ID: A5E94010C3A642AD
3 changed files with 3 additions and 33 deletions

View File

@ -1,11 +0,0 @@
use proc_macro2::TokenStream as TokenStream2;
use quote::ToTokens;
// TODO: Do we need this noop?
pub fn generate_default_lua_function(input: &syn::Field) -> TokenStream2 {
let output: TokenStream2 = syn::parse(input.into_token_stream().into())
.expect("This is generated from valid rust code, it should stay that way.");
output
}

View File

@ -1,8 +1,6 @@
mod generate_noop_lua_function;
mod mark_as_ci_command; mod mark_as_ci_command;
mod struct_to_ci_enum; mod struct_to_ci_enum;
use generate_noop_lua_function::generate_default_lua_function;
use mark_as_ci_command::generate_final_function; use mark_as_ci_command::generate_final_function;
use proc_macro::TokenStream; use proc_macro::TokenStream;
use proc_macro2::TokenStream as TokenStream2; use proc_macro2::TokenStream as TokenStream2;
@ -30,21 +28,18 @@ pub fn turn_struct_to_ci_commands(_attrs: TokenStream, input: TokenStream) -> To
} }
/// Generate a default lua function implementation. /// Generate a default lua function implementation.
// TODO: Is this needed?
#[proc_macro_attribute] #[proc_macro_attribute]
pub fn gen_lua_function(_attrs: TokenStream, input: TokenStream) -> TokenStream { pub fn gen_lua_function(_attrs: TokenStream, input: TokenStream) -> TokenStream {
// Construct a representation of Rust code as a syntax tree // Construct a representation of Rust code as a syntax tree
// that we can manipulate // that we can manipulate
//
let parser = Field::parse_named; let parser = Field::parse_named;
let input = parser.parse(input) let input = parser.parse(input)
.expect("This is only defined for named fileds."); .expect("This is only defined for named fileds.");
// Build the trait implementation
let default_lua_function: TokenStream2 = generate_default_lua_function(&input);
quote! { quote! {
#default_lua_function #input
} }
.into() .into()
} }

View File

@ -26,21 +26,7 @@ fn append_tx_send_code(input: &mut syn::ItemFn) -> &mut syn::ItemFn {
let tx_send = match &input.sig.output { let tx_send = match &input.sig.output {
syn::ReturnType::Default => { syn::ReturnType::Default => {
todo!( unreachable!("All functions should have a output of (Result<$type, rlua::Error>)");
"Does this case even trigger? All functions should have a output of (Result<$type, rlua::Error>)"
);
quote! {
{
let tx: std::sync::mpsc::Sender<crate::app::events::event_types::Event> =
context
.named_registry_value("sender_for_ci_commands")
.expect("This exists, it was set before");
tx
.send(Event::CommandEvent(Command::#function_name_pascal))
.expect("This should work, as the reciever is not dropped");
}
}
} }
syn::ReturnType::Type(_, ret_type) => { syn::ReturnType::Type(_, ret_type) => {
let return_type = match *(ret_type.clone()) { let return_type = match *(ret_type.clone()) {