use std::ffi::{c_char, CStr, CString};
use crate::ffi;
use libc::free;
pub fn get_from_table(key: String) -> Option<String> {
unsafe {
#[allow(clippy::expect_used)]
let c_string = CString::new(key).expect("");
let key_ptr = c_string.into_raw();
let val_ptr: *mut c_char = ffi::TableOut_get(key_ptr);
drop(CString::from_raw(key_ptr));
if val_ptr.is_null() {
free(val_ptr as _);
None
} else {
#[allow(clippy::unwrap_used)]
let res = CStr::from_ptr(val_ptr).to_str().unwrap().to_owned();
free(val_ptr as _);
Some(res)
}
}
}