#lua-bindings #lua #lua-state

no-std lunka

Pretty thin bindings to Lua 5.4

14 releases (9 breaking)

Uses new Rust 2024

0.12.0 Aug 8, 2025
0.10.0 Oct 12, 2024
0.8.0 Jun 2, 2024
0.2.0 Mar 30, 2024

#215 in FFI

Download history 233/week @ 2025-08-07 2/week @ 2025-08-14 8/week @ 2025-08-21 3/week @ 2025-09-25 4/week @ 2025-10-02

984 downloads per month

MIT license

175KB
2.5K SLoC

lunka

Pretty thin bindings to Lua 5.4.

This crate is still a work-in-progress.

Please check the latest documentation here: Documentation on docs.rs.

Examples

Creating a Lua "C" library:

use core::ffi::c_int;
use lunka::prelude::*;

unsafe extern "C-unwind" fn l_hello(l: *mut LuaState) -> c_int {
	// SAFETY: Caller ensures `l` is valid.
	let lua = unsafe { LuaThread::from_ptr(l) };

	// SAFETY: An error being raised will not skip any important pieces of code.
	let n = unsafe { lua.check_number(1) };

	// SAFETY: Ditto.
	unsafe { lua.push_string("Hello, world!") };
	lua.push_number(n * core::f64::consts::PI as LuaNumber);

	2
}

const LIBRARY: LuaLibrary<1> = lua_library! {
	hello: l_hello
};

#[unsafe(no_mangle)]
unsafe extern "C-unwind" fn luaopen_hello(l: *mut LuaState) -> c_int {
	// SAFETY: Caller ensures `l` is valid.
	let lua = unsafe { LuaThread::from_ptr(l) };

	// SAFETY: An error being raised will not skip any important pieces of code.
	unsafe { lua.new_lib(&LIBRARY) };

	1
}

For some more examples, check the examples directory in the crate's repository. They are comprehensive enough for actual usage.

No runtime deps