luaur_code_gen/records/
native_module_ref.rs1use crate::records::native_module::NativeModule;
4
5#[derive(Debug)]
6pub struct NativeModuleRef {
7 pub(crate) native_module: *const NativeModule,
8}
9
10impl Default for NativeModuleRef {
11 fn default() -> Self {
12 Self {
13 native_module: core::ptr::null(),
14 }
15 }
16}
17
18impl NativeModuleRef {
19 pub fn native_module_ref_default() -> Self {
20 Self::default()
21 }
22
23 pub unsafe fn native_module_ref_native_module(native_module: *const NativeModule) -> Self {
24 if !native_module.is_null() {
25 unsafe {
26 (*native_module).native_module_add_ref();
27 }
28 }
29
30 Self { native_module }
31 }
32
33 pub unsafe fn native_module_ref_native_module_ref(other: &NativeModuleRef) -> Self {
34 unsafe { Self::native_module_ref_native_module(other.native_module) }
35 }
36
37 pub fn native_module_ref_native_module_ref_mut(other: &mut NativeModuleRef) -> Self {
38 let native_module = other.native_module;
39 other.native_module = core::ptr::null();
40 Self { native_module }
41 }
42}
43
44impl Clone for NativeModuleRef {
45 fn clone(&self) -> Self {
46 unsafe { Self::native_module_ref_native_module(self.native_module) }
47 }
48}
49
50impl Drop for NativeModuleRef {
51 fn drop(&mut self) {
52 self.native_module_ref_reset();
53 }
54}