feo_oop_engine/macros/
script_macro.rs

1//! Script macros
2//! 
3//! The script macros are in here because of an attempt to pass a dyn GameObject.
4
5
6// Generalized
7// #[macro_export]
8// macro_rules! dyn_async {(
9//     $( #[$attr:meta] )*
10//     $pub:vis
11//     async
12//     fn $fname:ident<$lt:lifetime> ( $($args:tt)* ) $(-> $Ret:ty)?
13//     {
14//         $($body:tt)*
15//     }
16// ) => (
17//     $( #[$attr] )*
18//     #[allow(unused_parens)]
19//     $pub
20//     fn $fname<$lt> ( $($args)* ) -> ::std::pin::Pin<::std::boxed::Box<
21//         dyn ::std::future::Future<Output = ($($Ret)?)>
22//             + ::std::marker::Send + $lt
23//     >>
24//     {
25//         ::std::boxed::Box::pin(async move { $($body)* })
26//     }
27// )}
28
29#[macro_export]
30macro_rules! start_script {
31    (
32        $( #[$attr:meta] )*
33        $pub:vis
34        async
35        fn start<$lt:lifetime> ($this:tt : $this_ty:ty, $engine_globals:tt : $engine_globals_ty:ty) -> Swap
36        {
37            $($body:tt)*
38        }
39    ) => (
40        $( #[$attr] )*
41        #[allow(unused_parens)]
42        $pub
43        fn start<$lt> ($this : $this_ty, $engine_globals : $engine_globals_ty) -> ::std::pin::Pin<::std::boxed::Box<
44            dyn ::std::future::Future<Output = Swap>
45                + ::std::marker::Send + $lt
46        >>
47        {
48            ::std::boxed::Box::pin(async move { 
49                $($body)*
50            })
51        }
52    )
53}
54
55#[macro_export]
56macro_rules! frame_script {
57    (
58        $( #[$attr:meta] )*
59        $pub:vis
60        async
61        fn frame<$lt:lifetime> ($this:tt : $this_ty:ty , $engine_globals:tt : $engine_globals_ty:ty) -> Swap
62        {
63            $($body:tt)*
64        }
65    ) => (
66        $( #[$attr] )*
67        #[allow(unused_parens)]
68        $pub
69        fn frame<$lt> ($this : $this_ty, $engine_globals : $engine_globals_ty) -> ::std::pin::Pin<::std::boxed::Box<
70            dyn ::std::future::Future<Output = Swap>
71                + ::std::marker::Send + $lt
72        >>
73        {
74            ::std::boxed::Box::pin(async move { 
75                $($body)*
76            })
77        }
78    )
79}
80
81#[macro_export]
82macro_rules! event_handler {
83    (
84        $( #[$attr:meta] )*
85        $pub:vis
86        async
87        fn event_handler<$lt:lifetime> ($this:tt : $this_ty:ty , $engine_globals:tt : $engine_globals_ty:ty, $event:tt : $event_ty:ty) -> Swap
88        {
89            $($body:tt)*
90        }
91    ) => (
92        $( #[$attr] )*
93        #[allow(unused_parens)]
94        $pub
95        fn event_handler<$lt> ($this : $this_ty, $engine_globals : $engine_globals_ty, $event: $event_ty) -> ::std::pin::Pin<::std::boxed::Box<
96            dyn ::std::future::Future<Output = Swap>
97                + ::std::marker::Send + $lt
98        >>
99        {
100            ::std::boxed::Box::pin(async move { 
101                $($body)*
102            })
103        }
104    )
105}