Skip to content

Conversation

@makspll
Copy link
Owner

@makspll makspll commented Feb 10, 2025

Closes #264

Adds a macro which can be used to generate registrator functions for an impl block i.e.:

    #[test]
    fn test_macro_generates_correct_registrator_function() {
        #[derive(Reflect)]
        struct TestStruct;

        #[script_bindings(bms_core_path = "crate", name = "test_fn")]
        impl TestStruct {
            /// My docs !!
            fn test_fn(_self: Ref<TestStruct>, mut _arg1: usize) {}
        }

        let mut test_world = bevy::ecs::world::World::default();

        register_test_fn(&mut test_world);

        let app_registry = test_world
            .get_resource::<AppScriptFunctionRegistry>()
            .unwrap();
        let app_registry = app_registry.read();

        let test_fn = app_registry
            .get_function(TestStruct::into_namespace(), "test_fn")
            .unwrap();

        assert_eq!(test_fn.info.docs, Some("My docs !!".into()));
        assert_eq!(test_fn.info.arg_info.len(), 2);

        assert_eq!(
            test_fn.info.arg_info[0].type_id,
            std::any::TypeId::of::<Ref<TestStruct>>()
        );
        assert_eq!(test_fn.info.arg_info[0].name, Some("_self".into()));

        assert_eq!(
            test_fn.info.arg_info[1].type_id,
            std::any::TypeId::of::<usize>()
        );
        assert_eq!(test_fn.info.arg_info[1].name, Some("_arg1".into()));

        assert_eq!(
            test_fn.info.return_info.type_id,
            std::any::TypeId::of::<()>()
        );
    }

@makspll makspll added the needs documentation For features or changes which still need changes in the book label Feb 10, 2025
@makspll makspll merged commit 15b1d9a into main Feb 10, 2025
1 check passed
@makspll makspll deleted the feat/script-bindings-derive-macro branch February 10, 2025 00:33
This was referenced Feb 10, 2025
This was referenced Feb 12, 2025
@makspll makspll removed the needs documentation For features or changes which still need changes in the book label Mar 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Derive macro for easier docstring/arg_name registration

2 participants