1#[macro_export]
2macro_rules! implement_lua_push {
3 ($ty:ty, $cb:expr) => {
4 impl<'lua, L> $crate::Push<L> for $ty where L: $crate::AsMutLua<'lua> {
5 type Err = $crate::Void; #[inline]
7 fn push_to_lua(self, lua: L) -> Result<$crate::PushGuard<L>, ($crate::Void, L)> {
8 Ok($crate::push_userdata(self, lua, $cb))
9 }
10 }
11
12 impl<'lua, L> $crate::PushOne<L> for $ty where L: $crate::AsMutLua<'lua> {
13 }
14 };
15}
16
17#[macro_export]
18macro_rules! implement_lua_read {
19 ($ty:ty) => {
20 impl<'s, 'c> hlua::LuaRead<&'c mut hlua::InsideCallback> for &'s mut $ty {
21 #[inline]
22 fn lua_read_at_position(lua: &'c mut hlua::InsideCallback, index: i32) -> Result<&'s mut $ty, &'c mut hlua::InsideCallback> {
23 unsafe { ::std::mem::transmute($crate::read_userdata::<$ty>(lua, index)) }
25 }
26 }
27
28 impl<'s, 'c> hlua::LuaRead<&'c mut hlua::InsideCallback> for &'s $ty {
29 #[inline]
30 fn lua_read_at_position(lua: &'c mut hlua::InsideCallback, index: i32) -> Result<&'s $ty, &'c mut hlua::InsideCallback> {
31 unsafe { ::std::mem::transmute($crate::read_userdata::<$ty>(lua, index)) }
33 }
34 }
35
36 impl<'s, 'b, 'c> hlua::LuaRead<&'b mut &'c mut hlua::InsideCallback> for &'s mut $ty {
37 #[inline]
38 fn lua_read_at_position(lua: &'b mut &'c mut hlua::InsideCallback, index: i32) -> Result<&'s mut $ty, &'b mut &'c mut hlua::InsideCallback> {
39 let ptr_lua = lua as *mut &mut hlua::InsideCallback;
40 let deref_lua = unsafe { ::std::ptr::read(ptr_lua) };
41 let res = Self::lua_read_at_position(deref_lua, index);
42 match res {
43 Ok(x) => Ok(x),
44 _ => Err(lua)
45 }
46 }
47 }
48
49 impl<'s, 'b, 'c> hlua::LuaRead<&'b mut &'c mut hlua::InsideCallback> for &'s $ty {
50 #[inline]
51 fn lua_read_at_position(lua: &'b mut &'c mut hlua::InsideCallback, index: i32) -> Result<&'s $ty, &'b mut &'c mut hlua::InsideCallback> {
52 let ptr_lua = lua as *mut &mut hlua::InsideCallback;
53 let deref_lua = unsafe { ::std::ptr::read(ptr_lua) };
54 let res = Self::lua_read_at_position(deref_lua, index);
55 match res {
56 Ok(x) => Ok(x),
57 _ => Err(lua)
58 }
59 }
60 }
61 };
62}