luaur_vm/functions/
tremove.rs1use crate::enums::lua_type::lua_Type;
2use crate::functions::lua_l_checktype::lua_l_checktype;
3use crate::functions::lua_l_optinteger::lua_l_optinteger;
4use crate::functions::lua_objlen::lua_objlen;
5use crate::functions::lua_pushnil::lua_pushnil;
6use crate::functions::lua_rawgeti::lua_rawgeti;
7use crate::functions::lua_rawseti::lua_rawseti;
8use crate::functions::moveelements::moveelements;
9use crate::type_aliases::lua_state::lua_State;
10
11#[no_mangle]
12pub unsafe fn tremove(L: *mut lua_State) -> core::ffi::c_int {
13 lua_l_checktype(L, 1, lua_Type::LUA_TTABLE as core::ffi::c_int);
14 let n = lua_objlen(L, 1);
15 let pos = lua_l_optinteger(L, 2, n);
16
17 if !(1 <= pos && pos <= n) {
18 return 0;
19 }
20
21 lua_rawgeti(L, 1, pos);
22
23 moveelements(L, 1, 1, pos + 1, n, pos);
24
25 lua_pushnil(L);
26 lua_rawseti(L, 1, n);
27
28 1
29}