Skip to main content

luaur_vm/functions/
lua_setupvalue.rs

1use core::ffi::c_char;
2use core::ffi::c_int;
3
4use crate::functions::aux_upvalue::aux_upvalue;
5use crate::functions::index_2_addr::index_2_addr;
6use crate::macros::api_checknelems::api_checknelems;
7use crate::macros::clvalue::clvalue;
8use crate::macros::lua_c_barrier::luaC_barrier;
9use crate::macros::setobj::setobj;
10use crate::records::lua_state::lua_State;
11use crate::type_aliases::stk_id::StkId;
12use crate::type_aliases::t_value::TValue;
13
14#[allow(non_snake_case)]
15pub unsafe fn lua_setupvalue(L: *mut lua_State, funcindex: c_int, n: c_int) -> *const c_char {
16    api_checknelems!(L, 1);
17    let fi: StkId = index_2_addr(L, funcindex);
18    let mut val: *mut TValue = core::ptr::null_mut();
19    let name: *const c_char = aux_upvalue(fi, n, &mut val);
20
21    if !name.is_null() {
22        (*L).top = (*L).top.offset(-1);
23        setobj!(L, val, (*L).top);
24        luaC_barrier!(L, fi as *mut crate::records::gc_object::GCObject, (*L).top);
25    }
26
27    name
28}