Skip to main content

luaur_vm/macros/
lua_l_getmetatable.rs

1use crate::functions::lua_getfield::lua_getfield;
2use crate::macros::lua_registryindex::LUA_REGISTRYINDEX;
3
4#[allow(non_snake_case)]
5#[inline(always)]
6pub fn luaL_getmetatable(
7    l: *mut crate::records::lua_state::lua_State,
8    n: *const core::ffi::c_char,
9) -> core::ffi::c_int {
10    unsafe {
11        // The dependency lua_getfield is currently a stub in the required context (pub fn lua_getfield();).
12        // However, the C++ source and the call site require it to take (L, idx, k) and return int.
13        // We must cast the function pointer or call it as it is defined in the actual VM implementation.
14        // Since we cannot change the signature of the dependency here, we use a transmute to call it with the correct signature.
15        let func: fn(
16            *mut crate::records::lua_state::lua_State,
17            core::ffi::c_int,
18            *const core::ffi::c_char,
19        ) -> core::ffi::c_int = core::mem::transmute(lua_getfield as *const core::ffi::c_void);
20        func(l, LUA_REGISTRYINDEX, n)
21    }
22}