summaryrefslogtreecommitdiff
path: root/src/types.rs
diff options
context:
space:
mode:
authorkyren <kerriganw@gmail.com>2018-01-26 19:27:41 -0500
committerkyren <kerriganw@gmail.com>2018-01-26 19:43:53 -0500
commit0801104762cda684e5728df386cd3962fb0fe3bc (patch)
tree5283e1b9946608bf4fff66431ba6867747b15905 /src/types.rs
parentb44a6c95df4afbe0682c5d7de2db5da7529a3ebf (diff)
downloadmlua-0801104762cda684e5728df386cd3962fb0fe3bc.zip
ACTUALLY expose `RegistryKey` API
Also fixes a safety issue with RegistryKey, where you could use RegistryKeys with mismatching Lua instances.
Diffstat (limited to 'src/types.rs')
-rw-r--r--src/types.rs29
1 files changed, 25 insertions, 4 deletions
diff --git a/src/types.rs b/src/types.rs
index 21384a1..0d4c5ec 100644
--- a/src/types.rs
+++ b/src/types.rs
@@ -1,5 +1,6 @@
use std::fmt;
use std::os::raw::{c_int, c_void};
+use std::rc::Rc;
use ffi;
use error::Result;
@@ -15,12 +16,32 @@ pub type Number = ffi::lua_Number;
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub struct LightUserData(pub *mut c_void);
+// Clone-able id where every clone of the same id compares equal, and are guaranteed unique.
+#[derive(Debug, Clone)]
+pub(crate) struct SharedId(Rc<()>);
+
+impl SharedId {
+ pub(crate) fn new() -> SharedId {
+ SharedId(Rc::new(()))
+ }
+}
+
+impl PartialEq for SharedId {
+ fn eq(&self, other: &SharedId) -> bool {
+ Rc::ptr_eq(&self.0, &other.0)
+ }
+}
+
+impl Eq for SharedId {}
+
/// An auto generated key into the Lua registry.
-pub struct RegistryKey(pub(crate) c_int);
+pub struct RegistryKey {
+ pub(crate) lua_id: SharedId,
+ pub(crate) registry_id: c_int,
+}
-pub(crate) type Callback<'lua> = Box<
- FnMut(&'lua Lua, MultiValue<'lua>) -> Result<MultiValue<'lua>> + 'lua,
->;
+pub(crate) type Callback<'lua> =
+ Box<FnMut(&'lua Lua, MultiValue<'lua>) -> Result<MultiValue<'lua>> + 'lua>;
pub(crate) struct LuaRef<'lua> {
pub lua: &'lua Lua,