Skip to main content

Udata51Probe

Trait Udata51Probe 

Source
pub trait Udata51Probe: Any {
    // Required methods
    fn is_alive(&self) -> bool;
    fn as_any(&self) -> &dyn Any;
}
Expand description

A Lua 5.1 collect-time finalizability probe for a single userdata.

Lua 5.1 decides which userdata need finalization at collection time, not at setmetatable time: luaC_separateudata (lgc.c) walks every userdata and, for each white non-finalized one, reads its live metatable for __gc. This is observably different from 5.2+, where luaC_checkfinalizer makes the decision eagerly at setmetatable and a __gc added to a shared metatable afterwards never takes effect.

The collector cannot read a userdata’s metatable (a VM concept), so the VM supplies one probe per userdata. The collector only stores probes and prunes dead ones via is_alive; the VM drives the metatable read and the actual finalizer registration. Probes are erased behind std::any::Any so the VM can downcast back to its concrete type without the collector naming a VM type.

Required Methods§

Source

fn is_alive(&self) -> bool

True while the backing userdata box has not yet been swept. Backed by a weak handle on the VM side, so this is safe to call after a sweep freed the box.

Source

fn as_any(&self) -> &dyn Any

Erased self for VM-side downcast.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§