Lua 5.1 support

This commit is contained in:
Alex Orlenko
2019-10-14 22:21:30 +01:00
parent 676ffc0dfd
commit c4fd7a9faf
25 changed files with 1276 additions and 291 deletions
+15
View File
@@ -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| {