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 low_luajit::{AmountReturned, LuaState, reg};

extern "C-unwind" fn sum(lua: LuaState) -> AmountReturned {
	let mut result = 0.0;

	// Sum up all the arguments together, erroring if a non-number is passed.
	for i in 1..=lua.get_top() {
		result += lua.check_number(i);
	}

	lua.return_number(result)
}

#[allow(clippy::cast_possible_wrap)]
extern "C-unwind" fn count_bits(mut lua: LuaState) -> AmountReturned {
	let number = lua.check_integer(1);

	// Push and return the amount of zeros and ones in the integer.
	lua.push_integer(number.count_zeros() as isize);
	lua.push_integer(number.count_ones() as isize);
	lua.return_any(2)
}

extern "C-unwind" fn is_ascii(lua: LuaState) -> AmountReturned {
	let string = lua.check_string(1);

	let is_ascii = string.is_ascii();
	lua.return_boolean(is_ascii)
}

#[unsafe(no_mangle)]
extern "C-unwind" fn luaopen_simple(lua: LuaState) -> AmountReturned {
	println!("Hello from Rust!");

	lua.return_module(reg![sum, count_bits, is_ascii])
}