Skip to main content

luaur_analysis/functions/
get_function_parameters.rs

1use crate::functions::get_tag::get_tag;
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_pack::push_type_pack;
5use crate::records::type_function_function_type::TypeFunctionFunctionType;
6use crate::type_aliases::lua_state::lua_State;
7use core::ffi::c_int;
8use luaur_vm::functions::lua_gettop::lua_gettop;
9use luaur_vm::functions::lua_l_error_l::lua_l_error_l;
10
11#[allow(non_snake_case)]
12pub unsafe fn get_function_parameters(l: *mut lua_State) -> c_int {
13    let vm_l = l as *mut luaur_vm::records::lua_state::lua_State;
14    let argument_count = lua_gettop(vm_l);
15    if argument_count != 1 {
16        lua_l_error_l(
17            vm_l,
18            c"%s".as_ptr(),
19            core::format_args!(
20                "type.parameters: expected 1 arguments, but got {}",
21                argument_count
22            ),
23        );
24    }
25
26    let self_ty = get_type_user_data(l, 1);
27    let tfft = get_type_function_type_id::<TypeFunctionFunctionType>(self_ty);
28
29    if tfft.is_null() {
30        lua_l_error_l(
31            vm_l,
32            c"%s".as_ptr(),
33            core::format_args!(
34                "type.parameters: expected self to be a function, but got {} instead",
35                get_tag(l, self_ty)
36            ),
37        );
38    }
39
40    push_type_pack(l, (*tfft).arg_types);
41
42    1
43}