Implement Component using vtable

(the C++ part not yet ported)
This commit is contained in:
Olivier Goffart 2020-05-14 12:28:48 +02:00
parent 4b19818f6c
commit fb691e0808
2 changed files with 8 additions and 5 deletions

View file

@ -177,6 +177,8 @@ pub fn vtable(_attr: TokenStream, item: TokenStream) -> TokenStream {
} }
// Remove pub, if any // Remove pub, if any
field.vis = Visibility::Inherited; field.vis = Visibility::Inherited;
// FIXME!!!
field.vis = Visibility::Public(VisPublic{ pub_token: Default::default() });
let mut wrap_trait_call = None; let mut wrap_trait_call = None;
if !has_self { if !has_self {

View file

@ -54,18 +54,19 @@ unsafe fn set_property<T: PropertyWriter>(ptr: *mut u8, e: &Expression) {
T::write(ptr, e); T::write(ptr, e);
} }
unsafe extern "C" fn dummy_destroy(_: *const ComponentType, _: *mut ComponentImpl) { unsafe extern "C" fn dummy_destroy(_: *const ComponentVTable, _: *mut ComponentImpl) {
panic!(); panic!();
} }
#[repr(C)] #[repr(C)]
struct MyComponentType { struct MyComponentType {
ct: ComponentType, ct: ComponentVTable,
it: Vec<corelib::abi::datastructures::ItemTreeNode>, it: Vec<corelib::abi::datastructures::ItemTreeNode>,
} }
unsafe extern "C" fn item_tree( unsafe extern "C" fn item_tree(
c: *const ComponentType, c: *const ComponentVTable,
i: *const ComponentImpl,
) -> *const corelib::abi::datastructures::ItemTreeNode { ) -> *const corelib::abi::datastructures::ItemTreeNode {
(*(c as *const MyComponentType)).it.as_ptr() (*(c as *const MyComponentType)).it.as_ptr()
} }
@ -148,7 +149,7 @@ fn main() -> std::io::Result<()> {
current_offset += rt.size; current_offset += rt.size;
}); });
let t = ComponentType { create: None, destroy: dummy_destroy, item_tree }; let t = ComponentVTable {/* create: None, */ drop: dummy_destroy, item_tree };
let t = MyComponentType { ct: t, it: tree_array }; let t = MyComponentType { ct: t, it: tree_array };
let mut my_impl = Vec::<u64>::new(); let mut my_impl = Vec::<u64>::new();
@ -167,7 +168,7 @@ fn main() -> std::io::Result<()> {
} }
gl::sixtyfps_runtime_run_component_with_gl_renderer( gl::sixtyfps_runtime_run_component_with_gl_renderer(
&t as *const MyComponentType as *const ComponentType, &t as *const MyComponentType as *const ComponentVTable,
std::ptr::NonNull::new(mem).unwrap().cast(), std::ptr::NonNull::new(mem).unwrap().cast(),
); );