diff options
Diffstat (limited to 'src/scope.rs')
-rw-r--r-- | src/scope.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/scope.rs b/src/scope.rs index 238e52d..2c88083 100644 --- a/src/scope.rs +++ b/src/scope.rs @@ -175,6 +175,12 @@ impl<'lua, 'scope> Scope<'lua, 'scope> { assert_stack(lua.state, 1); lua.push_ref(&u.0); ffi::lua_getuservalue(lua.state, -1); + #[cfg(not(feature = "lua53"))] + { + ffi::lua_pushinteger(lua.state, 1); + ffi::lua_gettable(lua.state, -2); + ffi::lua_remove(lua.state, -2); + } return ffi::lua_touserdata(lua.state, -1) == check_data.as_ptr() as *mut c_void; } @@ -239,7 +245,16 @@ impl<'lua, 'scope> Scope<'lua, 'scope> { assert_stack(lua.state, 6); push_userdata(lua.state, ())?; + #[cfg(feature = "lua53")] ffi::lua_pushlightuserdata(lua.state, data.as_ptr() as *mut c_void); + #[cfg(not(feature = "lua53"))] + protect_lua_closure(lua.state, 0, 1, |state| { + // Lua 5.1 allows to store only table. Then we will wrap the value. + ffi::lua_createtable(state, 1, 0); + ffi::lua_pushinteger(state, 1); + ffi::lua_pushlightuserdata(state, data.as_ptr() as *mut c_void); + ffi::lua_settable(state, -3); + })?; ffi::lua_setuservalue(lua.state, -2); protect_lua_closure(lua.state, 0, 1, move |state| { |