Fix(lua_macros): Add sender trough app_data
This commit is contained in:
parent
c3a2b2d566
commit
6412650686
|
@ -88,7 +88,7 @@ fn append_tx_send_code(input: &mut syn::ItemFn) -> &mut syn::ItemFn {
|
|||
.expect("This is valid.");
|
||||
return_type_as_return_type
|
||||
} else {
|
||||
// There is only rlua
|
||||
// There is only mlua::Error left
|
||||
ReturnType::Default
|
||||
}
|
||||
}
|
||||
|
@ -108,23 +108,22 @@ fn append_tx_send_code(input: &mut syn::ItemFn) -> &mut syn::ItemFn {
|
|||
ReturnType::Type(_, _) => {
|
||||
quote! {
|
||||
{
|
||||
Event::CommandEvent(Command::#function_name_pascal(input_str))
|
||||
Event::CommandEvent(Command::#function_name_pascal(input_str.clone()))
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
quote! {
|
||||
{
|
||||
let tx: std::sync::Arc<std::sync::Mutex<tokio::sync::mpsc::Sender<crate::app::events::event_types::Event>>> =
|
||||
let tx:
|
||||
core::cell::Ref<
|
||||
tokio::sync::mpsc::Sender<crate::app::events::event_types::Event>
|
||||
> =
|
||||
lua
|
||||
.named_registry_value("sender_for_ci_commands")
|
||||
.app_data_ref()
|
||||
.expect("This exists, it was set before");
|
||||
|
||||
tx
|
||||
// FIXME: This is sync code, it needs to be run in a blocking allowed
|
||||
// executor
|
||||
.lock()
|
||||
.expect("This should work, as only one function is executed. It wil however fail, when concurrency is added");
|
||||
(*tx)
|
||||
.send(#send_data)
|
||||
.await
|
||||
.expect("This should work, as the reciever is not dropped");
|
||||
|
|
|
@ -44,7 +44,7 @@ pub fn generate_generate_ci_function(input: &syn::DeriveInput) -> TokenStream2 {
|
|||
lua: &mut mlua::Lua,
|
||||
tx: tokio::sync::mpsc::Sender<crate::app::events::event_types::Event>)
|
||||
{
|
||||
lua.set_named_registry_value("sender_for_ci_commands", std::sync::Arc::new(std::sync::Mutex::new(tx))).expect("This should always work, as the value is added before all else");
|
||||
lua.set_app_data(tx);
|
||||
let globals = lua.globals();
|
||||
#input_tokens
|
||||
}
|
||||
|
|
Reference in New Issue