mirror of
https://github.com/luau-lang/luau.git
synced 2025-05-04 10:33:46 +01:00
Add lua_State* argument to destructors registered with lua_newuserdatadtor
This commit is contained in:
parent
61766a692c
commit
949581db23
4 changed files with 8 additions and 8 deletions
|
@ -177,7 +177,7 @@ LUA_API int lua_pushthread(lua_State* L);
|
||||||
|
|
||||||
LUA_API void lua_pushlightuserdata(lua_State* L, void* p);
|
LUA_API void lua_pushlightuserdata(lua_State* L, void* p);
|
||||||
LUA_API void* lua_newuserdatatagged(lua_State* L, size_t sz, int tag);
|
LUA_API void* lua_newuserdatatagged(lua_State* L, size_t sz, int tag);
|
||||||
LUA_API void* lua_newuserdatadtor(lua_State* L, size_t sz, void (*dtor)(void*));
|
LUA_API void* lua_newuserdatadtor(lua_State* L, size_t sz, void (*dtor)(lua_State*, void*));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** get functions (Lua -> stack)
|
** get functions (Lua -> stack)
|
||||||
|
|
|
@ -1213,7 +1213,7 @@ void* lua_newuserdatatagged(lua_State* L, size_t sz, int tag)
|
||||||
return u->data;
|
return u->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* lua_newuserdatadtor(lua_State* L, size_t sz, void (*dtor)(void*))
|
void* lua_newuserdatadtor(lua_State* L, size_t sz, void (*dtor)(lua_State*, void*))
|
||||||
{
|
{
|
||||||
luaC_checkGC(L);
|
luaC_checkGC(L);
|
||||||
luaC_checkthreadsleep(L);
|
luaC_checkthreadsleep(L);
|
||||||
|
|
|
@ -31,10 +31,10 @@ void luaU_freeudata(lua_State* L, Udata* u, lua_Page* page)
|
||||||
}
|
}
|
||||||
else if (u->tag == UTAG_IDTOR)
|
else if (u->tag == UTAG_IDTOR)
|
||||||
{
|
{
|
||||||
void (*dtor)(void*) = nullptr;
|
void (*dtor)(lua_State*, void*) = nullptr;
|
||||||
memcpy(&dtor, &u->data + u->len - sizeof(dtor), sizeof(dtor));
|
memcpy(&dtor, &u->data + u->len - sizeof(dtor), sizeof(dtor));
|
||||||
if (dtor)
|
if (dtor)
|
||||||
dtor(u->data);
|
dtor(L, u->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -668,10 +668,10 @@ TEST_CASE("Reference")
|
||||||
lua_State* L = globalState.get();
|
lua_State* L = globalState.get();
|
||||||
|
|
||||||
// note, we push two userdata objects but only pin one of them (the first one)
|
// note, we push two userdata objects but only pin one of them (the first one)
|
||||||
lua_newuserdatadtor(L, 0, [](void*) {
|
lua_newuserdatadtor(L, 0, [](lua_State*, void*) {
|
||||||
dtorhits++;
|
dtorhits++;
|
||||||
});
|
});
|
||||||
lua_newuserdatadtor(L, 0, [](void*) {
|
lua_newuserdatadtor(L, 0, [](lua_State*, void*) {
|
||||||
dtorhits++;
|
dtorhits++;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1092,11 +1092,11 @@ TEST_CASE("UserdataApi")
|
||||||
CHECK(lua_userdatatag(L, -1) == 42);
|
CHECK(lua_userdatatag(L, -1) == 42);
|
||||||
|
|
||||||
// user data with inline dtor
|
// user data with inline dtor
|
||||||
void* ud3 = lua_newuserdatadtor(L, 4, [](void* data) {
|
void* ud3 = lua_newuserdatadtor(L, 4, [](lua_State*, void* data) {
|
||||||
dtorhits += *(int*)data;
|
dtorhits += *(int*)data;
|
||||||
});
|
});
|
||||||
|
|
||||||
void* ud4 = lua_newuserdatadtor(L, 1, [](void* data) {
|
void* ud4 = lua_newuserdatadtor(L, 1, [](lua_State*, void* data) {
|
||||||
dtorhits += *(char*)data;
|
dtorhits += *(char*)data;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue