luaur_vm/functions/
vector_min.rs1use crate::functions::lua_gettop::lua_gettop;
2use crate::functions::lua_l_checkvector::lua_l_checkvector;
3use crate::functions::lua_pushvector_lapi::lua_pushvector_lua_state_f32_f32_f32_f32;
4use crate::functions::lua_pushvector_lapi_alt_b::lua_pushvector_lua_state_f32_f32_f32;
5use crate::macros::lua_vector_size::LUA_VECTOR_SIZE;
6use crate::type_aliases::lua_state::lua_State;
7
8#[allow(non_snake_case)]
9pub unsafe fn vector_min(L: *mut lua_State) -> core::ffi::c_int {
10 let n = lua_gettop(L);
11 let v = lua_l_checkvector(L, 1);
12
13 let mut result = [0.0f32; 4];
14 if LUA_VECTOR_SIZE == 4 {
15 result[0] = *v.offset(0);
16 result[1] = *v.offset(1);
17 result[2] = *v.offset(2);
18 result[3] = *v.offset(3);
19 } else {
20 result[0] = *v.offset(0);
21 result[1] = *v.offset(1);
22 result[2] = *v.offset(2);
23 }
24
25 for i in 2..=n {
26 let b = lua_l_checkvector(L, i);
27
28 if *b.offset(0) < result[0] {
29 result[0] = *b.offset(0);
30 }
31 if *b.offset(1) < result[1] {
32 result[1] = *b.offset(1);
33 }
34 if *b.offset(2) < result[2] {
35 result[2] = *b.offset(2);
36 }
37 if LUA_VECTOR_SIZE == 4 {
38 if *b.offset(3) < result[3] {
39 result[3] = *b.offset(3);
40 }
41 }
42 }
43
44 if LUA_VECTOR_SIZE == 4 {
45 lua_pushvector_lua_state_f32_f32_f32_f32(L, result[0], result[1], result[2], result[3]);
46 } else {
47 lua_pushvector_lua_state_f32_f32_f32(L, result[0], result[1], result[2]);
48 }
49
50 1
51}