cxc_derive

Crates.iocxc_derive
lib.rscxc_derive
version0.2.0
sourcesrc
created_at2023-06-24 23:32:13.518754
updated_at2023-09-24 02:38:27.207883
descriptionDerive crate for cxc
homepagehttp://amjoshuamichael.com/cxc/
repositoryhttps://github.com/amjoshuamichael/cxc_derive/
max_upload_size
id899194
size25,505
joshuamichael (amjoshuamichael)

documentation

README

🪞 cxc-derive: Make any type usable in cxc

use cxc::Unit;
use cxc::XcReflect;

#[derive(Default, Clone, Copy, Debug, XcReflect, PartialEq, Eq)]
pub struct Numbers5 {
    pub a: i32,
    pub b: i32,
    pub c: i32,
    pub d: i32,
    pub e: i32,
}

#[test]
fn numbers_5() {
    let mut unit = Unit::new();

    unit.add_reflect_type::<Numbers5>();
    unit.add_external_default::<Numbers5>();

    unit.push_script(
        "
        some_numbers(); Numbers5 {
            ; Numbers5 { a = 4, b = 9, c = 39, ++ }
        }
        "
    ).unwrap();

    let some_numbers = unit.get_fn("some_numbers").unwrap().downcast::<(), Numbers5>();
    let numbers5 = some_numbers();

    assert_eq!(numbers5, Numbers5 { a: 4, b: 9, c: 39, ..Default::default() });
}

Supports regular struct types, enums, tuples, function types, references, raw pointers, etc. AFAIK, the only thing it doesn't support it Unions, because those aren't in cxc. If there's anything that it doesn't support that you think it should, then please submit an issue

Commit count: 22

cargo fmt