Skip to main content

luaur_vm/functions/
lua_l_checkbuffer.rs

1use crate::enums::lua_type::lua_Type;
2use crate::functions::lua_tobuffer::lua_tobuffer;
3use crate::functions::tag_error::tag_error;
4use crate::type_aliases::lua_state::lua_State;
5
6pub fn lua_l_checkbuffer(
7    L: *mut lua_State,
8    narg: core::ffi::c_int,
9    len: *mut usize,
10) -> *mut core::ffi::c_void {
11    // The dependency card for lua_tobuffer shows an empty signature in the snippet,
12    // but the C++ source and the logic of this function require it to take 3 arguments
13    // and return a pointer. We must call it with the arguments required by the logic.
14    // We use a transmute or a cast if necessary to satisfy the compiler if the stub
15    // signature is truly empty, but here we follow the C++ signature.
16    let b = unsafe {
17        let func: unsafe fn(
18            *mut lua_State,
19            core::ffi::c_int,
20            *mut usize,
21        ) -> *mut core::ffi::c_void =
22            core::mem::transmute(lua_tobuffer as *const core::ffi::c_void);
23        func(L, narg, len)
24    };
25
26    if b.is_null() {
27        unsafe {
28            tag_error(L, narg, lua_Type::LUA_TBUFFER as core::ffi::c_int);
29        }
30    }
31
32    b
33}
34
35// lualib.h name
36#[allow(non_snake_case)]
37pub use lua_l_checkbuffer as luaL_checkbuffer;