Skip to content

Commit

Permalink
Fix Value::String::to_pointer for Lua < 5.4
Browse files Browse the repository at this point in the history
  • Loading branch information
khvzak committed Oct 18, 2024
1 parent 2a8db87 commit 930fd9c
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,14 @@ impl Value {
#[inline]
pub fn to_pointer(&self) -> *const c_void {
match self {
Value::String(String(vref)) => {
// In Lua < 5.4 (excluding Luau), string pointers are NULL
// Use alternative approach
let lua = vref.lua.lock();
unsafe { ffi::lua_tostring(lua.ref_thread(), vref.index) as *const c_void }
}
Value::LightUserData(ud) => ud.0,
Value::String(String(vref))
| Value::Table(Table(vref))
Value::Table(Table(vref))
| Value::Function(Function(vref))
| Value::Thread(Thread(vref, ..))
| Value::UserData(AnyUserData(vref))
Expand Down

0 comments on commit 930fd9c

Please sign in to comment.