low-luajit 0.1.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(mut 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);
	}

	// Push and return the result.
	lua.push_number(result);
	lua.finish(1)
}

#[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.finish(2)
}

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

	// Push and return the boolean.
	lua.push_boolean(string.is_ascii());
	lua.finish(1)
}

#[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])
}