Add Table::to_pointer() and String::to_pointer() functions

This commit is contained in:
Alex Orlenko
2022-06-27 14:56:31 +01:00
parent 113f91ace3
commit 04ba93137c
4 changed files with 33 additions and 13 deletions
+12
View File
@@ -1,5 +1,6 @@
use std::borrow::{Borrow, Cow};
use std::hash::{Hash, Hasher};
use std::os::raw::c_void;
use std::string::String as StdString;
use std::{slice, str};
@@ -112,6 +113,17 @@ impl<'lua> String<'lua> {
slice::from_raw_parts(data as *const u8, size + 1)
}
}
/// Converts the string to a generic C pointer.
///
/// There is no way to convert the pointer back to its original value.
///
/// Typically this function is used only for hashing and debug information.
#[inline]
pub fn to_pointer(&self) -> *const c_void {
let lua = self.0.lua;
unsafe { lua.ref_thread_exec(|refthr| ffi::lua_topointer(refthr, self.0.index)) }
}
}
impl<'lua> AsRef<[u8]> for String<'lua> {