Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add script_bindings impl block derive macro #263

Merged
merged 3 commits into from
Feb 10, 2025

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs documentation For features or changes which still need changes in the book
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Derive macro for easier docstring/arg_name registration
1 participant