low-luajit 0.4.0

Low level but safe bindings to the LuaJIT C API with no dependencies and no-std support to create Lua modules using Rust.
Documentation
use crate::{AmountReturned, LuaState, ffi};

/// Nil (& none) related functions.
impl LuaState {
	/// Returns `true` if the value at the given acceptable `index` is `nil`, `false` otherwise.
	#[inline]
	#[must_use]
	pub fn is_nil(&self, index: i32) -> bool {
		// SAFETY: self.0 is always valid.
		unsafe { ffi::lua_isnil(self.0, index) != 0 }
	}

	/// Returns `true` if the value at the given acceptable `index` is invalid (out of bounds), `false` otherwise.
	#[inline]
	#[must_use]
	pub fn is_none(&self, index: i32) -> bool {
		// SAFETY: self.0 is always valid.
		unsafe { ffi::lua_isnone(self.0, index) != 0 }
	}

	/// Returns `true` if the value at the given acceptable `index` is `nil` or invalid (out of bounds), `false` otherwise.
	#[inline]
	#[must_use]
	pub fn is_none_or_nil(&self, index: i32) -> bool {
		// SAFETY: self.0 is always valid.
		unsafe { ffi::lua_isnoneornil(self.0, index) != 0 }
	}

	/// Pushes `nil` onto the stack.
	#[inline]
	pub fn push_nil(&mut self) {
		// SAFETY: self.0 is always valid.
		unsafe { ffi::lua_pushnil(self.0); }
	}

	/// Finishes the currently called [`CFunction`], returning `nil` to the caller.
	///
	/// The `LuaState` wrapper is consumed to prevent invalidating the [`AmountReturned`] (the Lua state itself is left intact).
	///
	/// To return no value at all instead of `nil`, see [`LuaState::return_none`].
	/// *(There is a small difference, but it's usually negligible.)*
	///
	/// [`CFunction`]: ./type.CFunction.html
	#[inline]
	pub fn return_nil(mut self) -> AmountReturned {
		self.push_nil();

		// SAFETY: There should always be at least one element in the stack.
		unsafe { AmountReturned::unchecked(1) }
	}

	/// Finishes the currently called [`CFunction`], returning no value to the caller.
	///
	/// This is currently effectively the same as just returning [`AmountReturned::NONE`].
	///
	/// To return `nil` instead of no value at all, see [`LuaState::return_nil`].
	/// *(There is a small difference, but it's usually negligible.)*
	///
	/// [`CFunction`]: ./type.CFunction.html
	#[inline]
	pub fn return_none(self) -> AmountReturned {
		AmountReturned::NONE
	}
}