luaur_analysis/functions/
create_intersection.rs1use crate::functions::alloc_type_user_data::alloc_type_user_data;
2use crate::functions::get_type_function_runtime_alt_o::get_type_function_type_id;
3use crate::functions::get_type_user_data::get_type_user_data;
4use crate::functions::push_type::push_type;
5use crate::records::type_function_intersection_type::TypeFunctionIntersectionType;
6use crate::records::type_function_unknown_type::TypeFunctionUnknownType;
7use crate::type_aliases::lua_state::lua_State;
8use crate::type_aliases::type_function_type_id::TypeFunctionTypeId;
9use crate::type_aliases::type_function_type_variant::TypeFunctionTypeVariant;
10use alloc::vec::Vec;
11use luaur_vm::functions::lua_gettop::lua_gettop;
12
13#[allow(unused_variables)]
14pub unsafe fn create_intersection(l: *mut lua_State) -> core::ffi::c_int {
15 let vm_l = l as *mut luaur_vm::records::lua_state::lua_State;
16 let arg_size = lua_gettop(vm_l);
17
18 let mut components: Vec<TypeFunctionTypeId> = Vec::with_capacity(arg_size as usize);
19
20 for i in 1..=arg_size {
21 let component = get_type_user_data(l, i);
22
23 if let Some(intersection_component) =
24 get_type_function_type_id::<TypeFunctionIntersectionType>(component).as_ref()
25 {
26 components.extend(intersection_component.components.iter().copied());
27 } else if !get_type_function_type_id::<TypeFunctionUnknownType>(component).is_null() {
28 continue;
29 } else {
30 components.push(component);
31 }
32 }
33
34 if components.is_empty() {
35 alloc_type_user_data(
36 l,
37 TypeFunctionTypeVariant::Unknown(TypeFunctionUnknownType::default()),
38 false,
39 );
40 } else if components.len() == 1 {
41 push_type(l, components[0]);
42 } else {
43 alloc_type_user_data(
44 l,
45 TypeFunctionTypeVariant::Intersection(TypeFunctionIntersectionType { components }),
46 false,
47 );
48 }
49
50 1
51}