| Crates.io | lunka |
| lib.rs | lunka |
| version | 0.12.0 |
| created_at | 2024-03-30 00:52:58.606587+00 |
| updated_at | 2025-08-08 23:37:10.688897+00 |
| description | Pretty thin bindings to Lua 5.4 |
| homepage | |
| repository | https://github.com/b0mbie/lunka |
| max_upload_size | |
| id | 1190690 |
| size | 183,838 |
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.
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.