diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/conversion.rs | 102 | ||||
-rw-r--r-- | src/lua.rs | 9 |
2 files changed, 111 insertions, 0 deletions
diff --git a/src/conversion.rs b/src/conversion.rs index 1321b42..74d532e 100644 --- a/src/conversion.rs +++ b/src/conversion.rs @@ -44,6 +44,18 @@ impl<'lua> IntoLua<'lua> for String<'lua> { } } +impl<'lua> IntoLua<'lua> for &String<'lua> { + #[inline] + fn into_lua(self, _: &'lua Lua) -> Result<Value<'lua>> { + Ok(Value::String(self.clone())) + } + + #[inline] + unsafe fn push_into_stack(self, lua: &'lua Lua) -> Result<()> { + Ok(lua.push_ref(&self.0)) + } +} + impl<'lua> FromLua<'lua> for String<'lua> { #[inline] fn from_lua(value: Value<'lua>, lua: &'lua Lua) -> Result<String<'lua>> { @@ -64,6 +76,18 @@ impl<'lua> IntoLua<'lua> for Table<'lua> { } } +impl<'lua> IntoLua<'lua> for &Table<'lua> { + #[inline] + fn into_lua(self, _: &'lua Lua) -> Result<Value<'lua>> { + Ok(Value::Table(self.clone())) + } + + #[inline] + unsafe fn push_into_stack(self, lua: &'lua Lua) -> Result<()> { + Ok(lua.push_ref(&self.0)) + } +} + impl<'lua> FromLua<'lua> for Table<'lua> { #[inline] fn from_lua(value: Value<'lua>, _: &'lua Lua) -> Result<Table<'lua>> { @@ -89,6 +113,20 @@ impl<'lua> IntoLua<'lua> for OwnedTable { #[cfg(all(feature = "unstable", any(not(feature = "send"), doc)))] #[cfg_attr(docsrs, doc(cfg(all(feature = "unstable", not(feature = "send")))))] +impl<'lua> IntoLua<'lua> for &OwnedTable { + #[inline] + fn into_lua(self, lua: &'lua Lua) -> Result<Value<'lua>> { + OwnedTable::into_lua(self.clone(), lua) + } + + #[inline] + unsafe fn push_into_stack(self, lua: &'lua Lua) -> Result<()> { + Ok(lua.push_owned_ref(&self.0)) + } +} + +#[cfg(all(feature = "unstable", any(not(feature = "send"), doc)))] +#[cfg_attr(docsrs, doc(cfg(all(feature = "unstable", not(feature = "send")))))] impl<'lua> FromLua<'lua> for OwnedTable { #[inline] fn from_lua(value: Value<'lua>, lua: &'lua Lua) -> Result<OwnedTable> { @@ -103,6 +141,18 @@ impl<'lua> IntoLua<'lua> for Function<'lua> { } } +impl<'lua> IntoLua<'lua> for &Function<'lua> { + #[inline] + fn into_lua(self, _: &'lua Lua) -> Result<Value<'lua>> { + Ok(Value::Function(self.clone())) + } + + #[inline] + unsafe fn push_into_stack(self, lua: &'lua Lua) -> Result<()> { + Ok(lua.push_ref(&self.0)) + } +} + impl<'lua> FromLua<'lua> for Function<'lua> { #[inline] fn from_lua(value: Value<'lua>, _: &'lua Lua) -> Result<Function<'lua>> { @@ -128,6 +178,20 @@ impl<'lua> IntoLua<'lua> for OwnedFunction { #[cfg(all(feature = "unstable", any(not(feature = "send"), doc)))] #[cfg_attr(docsrs, doc(cfg(all(feature = "unstable", not(feature = "send")))))] +impl<'lua> IntoLua<'lua> for &OwnedFunction { + #[inline] + fn into_lua(self, lua: &'lua Lua) -> Result<Value<'lua>> { + OwnedFunction::into_lua(self.clone(), lua) + } + + #[inline] + unsafe fn push_into_stack(self, lua: &'lua Lua) -> Result<()> { + Ok(lua.push_owned_ref(&self.0)) + } +} + +#[cfg(all(feature = "unstable", any(not(feature = "send"), doc)))] +#[cfg_attr(docsrs, doc(cfg(all(feature = "unstable", not(feature = "send")))))] impl<'lua> FromLua<'lua> for OwnedFunction { #[inline] fn from_lua(value: Value<'lua>, lua: &'lua Lua) -> Result<OwnedFunction> { @@ -142,6 +206,18 @@ impl<'lua> IntoLua<'lua> for Thread<'lua> { } } +impl<'lua> IntoLua<'lua> for &Thread<'lua> { + #[inline] + fn into_lua(self, _: &'lua Lua) -> Result<Value<'lua>> { + Ok(Value::Thread(self.clone())) + } + + #[inline] + unsafe fn push_into_stack(self, lua: &'lua Lua) -> Result<()> { + Ok(lua.push_ref(&self.0)) + } +} + impl<'lua> FromLua<'lua> for Thread<'lua> { #[inline] fn from_lua(value: Value<'lua>, _: &'lua Lua) -> Result<Thread<'lua>> { @@ -163,6 +239,18 @@ impl<'lua> IntoLua<'lua> for AnyUserData<'lua> { } } +impl<'lua> IntoLua<'lua> for &AnyUserData<'lua> { + #[inline] + fn into_lua(self, _: &'lua Lua) -> Result<Value<'lua>> { + Ok(Value::UserData(self.clone())) + } + + #[inline] + unsafe fn push_into_stack(self, lua: &'lua Lua) -> Result<()> { + Ok(lua.push_ref(&self.0)) + } +} + impl<'lua> FromLua<'lua> for AnyUserData<'lua> { #[inline] fn from_lua(value: Value<'lua>, _: &'lua Lua) -> Result<AnyUserData<'lua>> { @@ -191,6 +279,20 @@ impl<'lua> IntoLua<'lua> for OwnedAnyUserData { #[cfg(all(feature = "unstable", any(not(feature = "send"), doc)))] #[cfg_attr(docsrs, doc(cfg(all(feature = "unstable", not(feature = "send")))))] +impl<'lua> IntoLua<'lua> for &OwnedAnyUserData { + #[inline] + fn into_lua(self, lua: &'lua Lua) -> Result<Value<'lua>> { + OwnedAnyUserData::into_lua(self.clone(), lua) + } + + #[inline] + unsafe fn push_into_stack(self, lua: &'lua Lua) -> Result<()> { + Ok(lua.push_owned_ref(&self.0)) + } +} + +#[cfg(all(feature = "unstable", any(not(feature = "send"), doc)))] +#[cfg_attr(docsrs, doc(cfg(all(feature = "unstable", not(feature = "send")))))] impl<'lua> FromLua<'lua> for OwnedAnyUserData { #[inline] fn from_lua(value: Value<'lua>, lua: &'lua Lua) -> Result<OwnedAnyUserData> { @@ -2558,6 +2558,15 @@ impl Lua { ffi::lua_xpush(self.ref_thread(), self.state(), lref.index); } + #[cfg(all(feature = "unstable", not(feature = "send")))] + pub(crate) unsafe fn push_owned_ref(&self, loref: &crate::types::LuaOwnedRef) { + assert!( + Arc::ptr_eq(&loref.inner, &self.0), + "Lua instance passed Value created from a different main Lua state" + ); + ffi::lua_xpush(self.ref_thread(), self.state(), loref.index); + } + // Pops the topmost element of the stack and stores a reference to it. This pins the object, // preventing garbage collection until the returned `LuaRef` is dropped. // |