summaryrefslogtreecommitdiff
path: root/src/types.rs
diff options
context:
space:
mode:
authorkyren <kerriganw@gmail.com>2018-03-28 01:09:51 -0400
committerkyren <kerriganw@gmail.com>2018-03-28 01:09:51 -0400
commit71f3dd50a1f396ea2ff36462e3deb6a48a132c43 (patch)
treebfac178b134bfd15f587305c26dcecfe51f46b0b /src/types.rs
parent60bfe1fb077a75b37fa2aef1883db45298761987 (diff)
downloadmlua-71f3dd50a1f396ea2ff36462e3deb6a48a132c43.zip
New approach for ref types, use an auxillary thread stack
Vastly simpler and less magical than using a fixed size magical section of the active stack, and seems to be no slower. The only real downside is that it *seems* extremely extremely hacky (and to be fair, it is).
Diffstat (limited to 'src/types.rs')
-rw-r--r--src/types.rs35
1 files changed, 18 insertions, 17 deletions
diff --git a/src/types.rs b/src/types.rs
index cf6961d..f3f1896 100644
--- a/src/types.rs
+++ b/src/types.rs
@@ -22,26 +22,34 @@ pub(crate) type Callback<'lua, 'a> =
/// An auto generated key into the Lua registry.
///
/// This is a handle to a value stored inside the Lua registry. It is not directly usable like the
-/// `Table` or `Function` handle types, but it is much more flexible and can be used in many
-/// situations where it is impossible to directly store a normal handle type. It is Send + Sync +
-/// 'static, and can be used by *any* `Lua` instance as long as it is derived from the same
-/// underlying main state (such as one received in a Rust callback). It is not automatically
-/// garbage collected on Drop, but it can be removed with [`Lua::remove_registry_value`], and
-/// instances not manually removed can be garbage collected with [`Lua::expire_registry_values`].
+/// `Table` or `Function` handle types, but since it doesn't hold a reference to a parent Lua and is
+/// Send + Sync + 'static, it is much more flexible and can be used in many situations where it is
+/// impossible to directly store a normal handle type. It is not automatically garbage collected on
+/// Drop, but it can be removed with [`Lua::remove_registry_value`], and instances not manually
+/// removed can be garbage collected with [`Lua::expire_registry_values`].
///
/// Be warned, If you place this into Lua via a `UserData` type or a rust callback, it is *very
/// easy* to accidentally cause reference cycles that the Lua garbage collector cannot resolve.
/// Instead of placing a `RegistryKey` into a `UserData` type, prefer instead to use
-/// `UserData::set_user_value` / `UserData::get_user_value`, and instead of moving a RegistryKey
-/// into a callback, prefer `Lua::scope`.
+/// [`UserData::set_user_value`] / [`UserData::get_user_value`], and instead of moving a RegistryKey
+/// into a callback, prefer [`Lua::scope`].
///
/// [`Lua::remove_registry_value`]: struct.Lua.html#method.remove_registry_value
/// [`Lua::expire_registry_values`]: struct.Lua.html#method.expire_registry_values
+/// [`Lua::scope`]: struct.Lua.html#method.scope
+/// [`UserData::set_user_value`]: struct.UserData.html#method.set_user_value
+/// [`UserData::get_user_value`]: struct.UserData.html#method.get_user_value
pub struct RegistryKey {
pub(crate) registry_id: c_int,
pub(crate) unref_list: Arc<Mutex<Option<Vec<c_int>>>>,
}
+impl fmt::Debug for RegistryKey {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ write!(f, "RegistryKey({})", self.registry_id)
+ }
+}
+
impl Drop for RegistryKey {
fn drop(&mut self) {
if let Some(list) = self.unref_list.lock().unwrap().as_mut() {
@@ -62,21 +70,14 @@ impl RegistryKey {
}
}
-#[derive(Debug)]
-pub(crate) enum RefType {
- Nil,
- Stack { stack_slot: c_int },
- Registry { registry_id: c_int },
-}
-
pub(crate) struct LuaRef<'lua> {
pub(crate) lua: &'lua Lua,
- pub(crate) ref_type: RefType,
+ pub(crate) index: c_int,
}
impl<'lua> fmt::Debug for LuaRef<'lua> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write!(f, "{:?}", self.ref_type)
+ write!(f, "Ref({})", self.index)
}
}