Skip to main content

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