Skip to content

Instantly share code, notes, and snippets.

@eseidel
Created August 3, 2021 03:39
Show Gist options
  • Save eseidel/a05d737d297de125adc313492a02aabc to your computer and use it in GitHub Desktop.
Save eseidel/a05d737d297de125adc313492a02aabc to your computer and use it in GitHub Desktop.
so unsafe
#[no_mangle]
pub extern "C" fn wrenSetSlotNewForeign(
vm: *mut WrenVM,
slot: c_int,
class_slot: c_int,
size: size_t,
) -> *mut c_void {
let mut user_data = UserDataWrapper {
buffer: vec![0; size].into_boxed_slice(),
};
let c_ptr = user_data.buffer.as_mut_ptr();
unsafe { std::mem::transmute::<*mut WrenVM, &mut RustWrenVM>(vm) }.set_slot_new_foreign(
usize::try_from(slot).unwrap(),
usize::try_from(class_slot).unwrap(),
Box::new(user_data),
);
unsafe { std::mem::transmute::<*mut u8, *mut c_void>(c_ptr) }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment