Skip to content

Commit

Permalink
refactor <()>::pop()
Browse files Browse the repository at this point in the history
  • Loading branch information
noib3 committed Apr 2, 2023
1 parent 9b36ad0 commit 7b29c78
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions crates/luajit-bindings/src/poppable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,15 @@ pub trait Poppable: Sized {
}

impl Poppable for () {
#[inline(always)]
unsafe fn pop(state: *mut lua_State) -> Result<Self, crate::Error> {
if lua_gettop(state) == 0 {
return Ok(());
}

match lua_type(state, -1) {
LUA_TNIL => {
lua_pop(state, 1);
Ok(())
},
other => Err(Error::pop_wrong_type::<Self>(LUA_TNIL, other)),
Ok(())
} else if lua_type(state, -1) == LUA_TNIL {
lua_pop(state, 1);
Ok(())
} else {
Err(Error::pop_wrong_type::<Self>(LUA_TNIL, lua_type(state, -1)))
}
}
}
Expand Down

0 comments on commit 7b29c78

Please sign in to comment.