Function lua_tostring

Source
pub unsafe fn lua_tostring(state: *mut lua_State, i: c_int) -> *const c_char
Examples found in repository?
examples/version_grab.rs (line 17)
7fn main() -> Result<(), Box<dyn Error>> {
8    // Create the new Lua state and open related libaries
9    let l = unsafe { luaL_newstate() };
10    unsafe { luaL_openlibs(l) };
11
12    // Get the global _VERSION field
13    let version = CString::new("_VERSION")?;
14    unsafe { lua_getglobal(l, version.as_ptr()) };
15
16    // Convert the _VERSION field into a Rust string
17    let version_string_ptr = unsafe { lua_tostring(l, -1) };
18    let version_string = unsafe { CStr::from_ptr(version_string_ptr) }.to_str()?;
19
20    // Print the version string to output
21    println!("{}", version_string);
22
23    Ok(())
24}