luaur_analysis/functions/
create_negation.rs1use crate::functions::alloc_type_user_data::alloc_type_user_data;
2use crate::functions::get_tag::get_tag;
3use crate::functions::get_type_function_runtime_alt_o::get_type_function_type_id;
4use crate::functions::get_type_user_data::get_type_user_data;
5use crate::records::type_function_function_type::TypeFunctionFunctionType;
6use crate::records::type_function_negation_type::TypeFunctionNegationType;
7use crate::records::type_function_table_type::TypeFunctionTableType;
8use crate::type_aliases::lua_state::lua_State;
9use crate::type_aliases::type_function_type_variant::TypeFunctionTypeVariant;
10use luaur_vm::functions::lua_gettop::lua_gettop;
11use luaur_vm::functions::lua_l_error_l::lua_l_error_l;
12
13#[allow(non_snake_case)]
14pub unsafe fn create_negation(l: *mut lua_State) -> core::ffi::c_int {
15 let vm_l = l as *mut luaur_vm::records::lua_state::lua_State;
16 let argument_count = lua_gettop(vm_l);
17 if argument_count != 1 {
18 lua_l_error_l(
19 vm_l,
20 c"%s".as_ptr(),
21 core::format_args!(
22 "types.negationof: expected 1 argument, but got {}",
23 argument_count
24 ),
25 );
26 }
27
28 let arg = get_type_user_data(l, 1);
29
30 let table_type_ptr = get_type_function_type_id::<TypeFunctionTableType>(arg);
31 let function_type_ptr = get_type_function_type_id::<TypeFunctionFunctionType>(arg);
32
33 if !table_type_ptr.is_null() || !function_type_ptr.is_null() {
34 let tag = get_tag(l, arg);
35 lua_l_error_l(
36 vm_l,
37 c"%s".as_ptr(),
38 core::format_args!(
39 "types.negationof: cannot perform negation on `{}` type",
40 tag
41 ),
42 );
43 }
44
45 let negation = TypeFunctionNegationType { type_id: arg };
46 alloc_type_user_data(l, TypeFunctionTypeVariant::Negation(negation), false);
47
48 1
49}