luaur_analysis/functions/
get_read_parent.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_extern_type::TypeFunctionExternType;
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;
10use luaur_vm::functions::lua_pushnil::lua_pushnil;
11
12#[allow(non_snake_case)]
13pub unsafe fn get_read_parent(l: *mut lua_State) -> c_int {
14 let vm_l = l as *mut luaur_vm::records::lua_state::lua_State;
15 let argument_count = lua_gettop(vm_l);
16 if argument_count != 1 {
17 lua_l_error_l(
18 vm_l,
19 c"%s".as_ptr(),
20 core::format_args!(
21 "type.parent: expected 1 arguments, but got {}",
22 argument_count
23 ),
24 );
25 }
26
27 let self_ty = get_type_user_data(l, 1);
28 let tfct = get_type_function_type_id::<TypeFunctionExternType>(self_ty);
29
30 if tfct.is_null() {
31 lua_l_error_l(
32 vm_l,
33 c"%s".as_ptr(),
34 core::format_args!(
35 "type.parent: expected self to be a class, but got {} instead",
36 get_tag(l, self_ty)
37 ),
38 );
39 }
40
41 if let Some(read_parent) = (*tfct).read_parent {
42 alloc_type_user_data(l, (*read_parent).type_variant.clone(), false);
43 } else {
44 lua_pushnil(vm_l);
45 }
46
47 1
48}