Skip to content

Commit

Permalink
Fix attaching __gc metamethod
Browse files Browse the repository at this point in the history
Bug introdused in ddebf56
  • Loading branch information
khvzak committed Oct 29, 2024
1 parent ddebf56 commit 76b896e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/state/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -961,9 +961,9 @@ impl RawLua {
#[cfg(feature = "luau")]
let extra_init = None;
#[cfg(not(feature = "luau"))]
let extra_init: Option<fn(*mut ffi::lua_State) -> Result<()>> = Some(|state| {
let extra_init: Option<fn(*mut ffi::lua_State, c_int) -> Result<()>> = Some(|state, mt_idx| {
ffi::lua_pushcfunction(state, crate::util::userdata_destructor::<UserDataStorage<T>>);
rawset_field(state, -2, "__gc")
rawset_field(state, mt_idx, "__gc")
});

init_userdata_metatable(
Expand Down
4 changes: 2 additions & 2 deletions src/util/userdata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ pub(crate) unsafe fn init_userdata_metatable(
field_getters: Option<c_int>,
field_setters: Option<c_int>,
methods: Option<c_int>,
extra_init: Option<fn(*mut ffi::lua_State) -> Result<()>>,
extra_init: Option<fn(*mut ffi::lua_State, c_int) -> Result<()>>,
) -> Result<()> {
if field_getters.is_some() || methods.is_some() {
// Push `__index` generator function
Expand Down Expand Up @@ -197,7 +197,7 @@ pub(crate) unsafe fn init_userdata_metatable(

// Additional initialization
if let Some(extra_init) = extra_init {
extra_init(state)?;
extra_init(state, metatable)?;
}

ffi::lua_pushboolean(state, 0);
Expand Down

0 comments on commit 76b896e

Please sign in to comment.