luaur_vm/functions/
vector_max.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_max(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 = if LUA_VECTOR_SIZE == 4 {
14 [*v.offset(0), *v.offset(1), *v.offset(2), *v.offset(3)]
15 } else {
16 [*v.offset(0), *v.offset(1), *v.offset(2), 0.0]
17 };
18
19 for i in 2..=n {
20 let b = lua_l_checkvector(L, i);
21
22 if *b.offset(0) > result[0] {
23 result[0] = *b.offset(0);
24 }
25 if *b.offset(1) > result[1] {
26 result[1] = *b.offset(1);
27 }
28 if *b.offset(2) > result[2] {
29 result[2] = *b.offset(2);
30 }
31 if LUA_VECTOR_SIZE == 4 {
32 if *b.offset(3) > result[3] {
33 result[3] = *b.offset(3);
34 }
35 }
36 }
37
38 if LUA_VECTOR_SIZE == 4 {
39 lua_pushvector_lua_state_f32_f32_f32_f32(L, result[0], result[1], result[2], result[3]);
40 } else {
41 lua_pushvector_lua_state_f32_f32_f32(L, result[0], result[1], result[2]);
42 }
43
44 1
45}