Skip to main content

luaur_vm/macros/
setvvalue.rs

1use crate::enums::lua_type::lua_Type;
2use crate::type_aliases::t_value::TValue;
3
4#[allow(non_snake_case)]
5#[macro_export]
6macro_rules! setvvalue {
7    ($obj:expr, $x:expr, $y:expr, $z:expr, $w:expr) => {
8        unsafe {
9            let i_o: *mut TValue = $obj;
10            // C stores v[0],v[1] in value.v and v[2] (plus v[3] for size 4) in
11            // TValue::extra, accessed as one contiguous float run. Derive the float
12            // pointer from the TValue base so its provenance spans value + extra
13            // (indexing value.v[2..] directly is out-of-bounds UB).
14            let i_v = i_o as *mut f32;
15            *i_v.add(0) = $x as f32;
16            *i_v.add(1) = $y as f32;
17            *i_v.add(2) = $z as f32;
18            if $crate::macros::lua_vector_size::LUA_VECTOR_SIZE == 4 {
19                *i_v.add(3) = $w as f32;
20            }
21            (*i_o).tt = $crate::enums::lua_type::lua_Type::LUA_TVECTOR as i32;
22        }
23    };
24}
25
26pub use setvvalue;