Skip to content

Commit 975723f

Browse files
committed
Move association names(const &str) into mod association_names
1 parent 0eb9326 commit 975723f

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

crates/lune-std-ffi/src/carr.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use libffi::middle::Type;
22
use mlua::prelude::*;
33

44
use crate::association::{get_association, set_association};
5+
use crate::association_names::CARR_INNER;
56
use crate::chelper::{get_ensured_size, stringify_userdata, type_from_userdata};
67
use crate::cptr::CPtr;
78

@@ -16,8 +17,6 @@ use crate::cptr::CPtr;
1617
// Padding after each field inside the struct is set to next field can follow the alignment.
1718
// There is no problem even if you create a struct with n fields of a single type within the struct. Array adheres to the condition that there is no additional padding between each element. Padding to a struct is padding inside the struct. Simply think of the padding byte as a trailing unnamed field.
1819

19-
const CARR_INNER: &str = "__carr_inner";
20-
2120
pub struct CArr {
2221
libffi_type: Type,
2322
struct_type: Type,

crates/lune-std-ffi/src/cptr.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ use libffi::middle::Type;
66
use mlua::prelude::*;
77

88
use crate::association::{get_association, set_association};
9+
use crate::association_names::CPTR_INNER;
910
use crate::carr::CArr;
1011
use crate::chelper::{name_from_userdata, stringify_userdata};
1112

12-
const POINTER_INNER: &str = "__pointer_inner";
13-
1413
pub struct CPtr();
1514

1615
impl CPtr {
@@ -22,7 +21,7 @@ impl CPtr {
2221
) -> LuaResult<LuaValue<'lua>> {
2322
let value = Self().into_lua(lua)?;
2423

25-
set_association(lua, POINTER_INNER, value.borrow(), inner)?;
24+
set_association(lua, CPTR_INNER, value.borrow(), inner)?;
2625

2726
Ok(value)
2827
}
@@ -55,7 +54,7 @@ impl LuaUserData for CPtr {
5554
fn add_fields<'lua, F: LuaUserDataFields<'lua, Self>>(fields: &mut F) {
5655
fields.add_field_method_get("size", |_, _| Ok(size_of::<usize>()));
5756
fields.add_field_function_get("inner", |lua, this| {
58-
let inner = get_association(lua, POINTER_INNER, this)?
57+
let inner = get_association(lua, CPTR_INNER, this)?
5958
.ok_or(LuaError::external("inner type not found"))?;
6059
Ok(inner)
6160
});

crates/lune-std-ffi/src/cstruct.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use libffi::{
1010
use mlua::prelude::*;
1111

1212
use crate::association::{get_association, set_association};
13+
use crate::association_names::CSTRUCT_INNER;
1314
use crate::chelper::{name_from_userdata, stringify_userdata, type_list_from_table};
1415
use crate::ctype::CType;
1516
use crate::FFI_STATUS_NAMES;
@@ -23,8 +24,6 @@ pub struct CStruct {
2324
size: usize,
2425
}
2526

26-
const CSTRUCT_INNER: &str = "__cstruct_inner";
27-
2827
impl CStruct {
2928
pub fn new(fields: Vec<Type>) -> LuaResult<Self> {
3029
let libffi_type = Type::structure(fields.clone());

crates/lune-std-ffi/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,20 @@ use crate::ctype::create_all_types;
2323
use crate::ffibox::FfiBox;
2424
use crate::ffilib::FfiLib;
2525

26+
// Converts ffi status into &str
2627
pub const FFI_STATUS_NAMES: [&str; 4] = [
2728
"ffi_status_FFI_OK",
2829
"ffi_status_FFI_BAD_TYPEDEF",
2930
"ffi_status_FFI_BAD_ABI",
3031
"ffi_status_FFI_BAD_ARGTYPE",
3132
];
3233

34+
mod association_names {
35+
pub const CPTR_INNER: &str = "__cptr_inner";
36+
pub const CARR_INNER: &str = "__carr_inner";
37+
pub const CSTRUCT_INNER: &str = "__cstruct_inner";
38+
}
39+
3340
/**
3441
Creates the `ffi` standard library module.
3542

0 commit comments

Comments
 (0)