Unsafe Rust bindings for the latest Lua version (5.4.4).
Lua is not a very backwards compatible friendly language[1][2].
The goal of this repository is to support the latest and only the latest version of the Lua language.
Add the following line to your Cargo.toml file.
lua-latest-sys = "0.0.1"
Now you can utilize lua-latest-sys
in your crate.
An example follows which grabs and prints the global Lua _VERSION
variable to Rust console output.
```rust use lualatestsys::{luaLnewstate, luaLopenlibs, luagetglobal, luatostring}; use std::{ error::Error, ffi::{CStr, CString}, };
fn main() -> Result<(), Box
// Get the global _VERSION field
let version = CString::new("_VERSION")?;
unsafe { lua_getglobal(l, version.as_ptr()) };
// Convert the _VERSION field into a Rust string
let version_string_ptr = unsafe { lua_tostring(l, -1) };
let version_string = unsafe { CStr::from_ptr(version_string_ptr) }.to_str()?;
// Print the version string to output
println!("{}", version_string);
Ok(())
} ```
The bindings are generated with bindgen
using the following command.
sh
bindgen lua.hpp -o bindings.rs --no-layout-tests --size_t-is-usize --default-macro-constant-type signed