pub struct UpVal {
pub state: RefCell<UpValState>,
/* private fields */
}Expand description
A closure upvalue. Open upvalues point at a slot on a thread’s stack (referred to by index, since the stack reallocates). Closed upvalues own the value.
Canonical state lives in two Cell fields (the tag and the open payload)
plus a RefCell<LuaValue> holding the closed payload. The state
RefCell<UpValState> mirror is kept consistent so cold consumers that
still call slot() see the correct view. The split lets
state.rs::upvalue_get / upvalue_set short-circuit the Open path with
zero RefCell borrow overhead, which is the dominant cost in
fibonacci-class recursion benchmarks.
Fields§
§state: RefCell<UpValState>Implementations§
Source§impl UpVal
impl UpVal
pub fn open(thread_id: usize, idx: StackIdx) -> Self
pub fn closed(v: LuaValue) -> Self
Sourcepub fn slot(&self) -> Ref<'_, UpValState>
pub fn slot(&self) -> Ref<'_, UpValState>
Backwards-compat handle on the full UpValState. Out-of-crate code
matches against this through Ref::deref. Hot-path callers should
use try_open_payload / closed_value instead.
pub fn is_open(&self) -> bool
pub fn is_closed(&self) -> bool
Sourcepub fn try_open_payload(&self) -> Option<(usize, StackIdx)>
pub fn try_open_payload(&self) -> Option<(usize, StackIdx)>
Zero-RefCell fast path used by upvalue_get / upvalue_set.
Returns Some((thread_id, idx)) when the upvalue is still open,
None otherwise.
Sourcepub fn closed_value(&self) -> Ref<'_, LuaValue>
pub fn closed_value(&self) -> Ref<'_, LuaValue>
Borrows the closed-side value. Callers must have confirmed the
upvalue is closed (try_open_payload returned None).