luaur_rt/light_userdata.rs
1//! [`LightUserData`] — a raw pointer carried as a first-class Lua value.
2//!
3//! Mirrors `mlua::LightUserData`. A light userdata is just a `void *` stored
4//! directly in a Lua value (no GC, no metatable storage of its own beyond the
5//! per-type metatable). luaur's VM represents it as the `LUA_TLIGHTUSERDATA`
6//! tag; we push it via `lua_pushlightuserdatatagged` (tag 0) and read it back
7//! with `lua_tolightuserdata`.
8
9use std::os::raw::c_void;
10
11/// A Lua light userdata: an opaque raw pointer value. Mirrors
12/// `mlua::LightUserData`.
13#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
14pub struct LightUserData(pub *mut c_void);
15
16// Under the `send` feature the whole VM (and every `Value` it can hold) is
17// `Send` so it can be *moved* across threads. A light userdata is an opaque
18// pointer value with no thread affinity of its own — moving it with the VM is
19// sound under luaur-rt's move-not-share contract (see `crate::sync`). mlua makes
20// the same documented `unsafe impl Send` for its `LightUserData`.
21#[cfg(feature = "send")]
22unsafe impl Send for LightUserData {}
23#[cfg(feature = "send")]
24unsafe impl Sync for LightUserData {}