mirror of
https://github.com/luau-lang/luau.git
synced 2025-05-04 10:33:46 +01:00
Add typedef lua_Destructor
This commit is contained in:
parent
c6e4f49e32
commit
25384218ca
3 changed files with 8 additions and 6 deletions
|
@ -313,8 +313,11 @@ LUA_API uintptr_t lua_encodepointer(lua_State* L, uintptr_t p);
|
||||||
LUA_API double lua_clock();
|
LUA_API double lua_clock();
|
||||||
|
|
||||||
LUA_API void lua_setuserdatatag(lua_State* L, int idx, int tag);
|
LUA_API void lua_setuserdatatag(lua_State* L, int idx, int tag);
|
||||||
LUA_API void lua_setuserdatadtor(lua_State* L, int tag, void (*dtor)(lua_State*, void*));
|
|
||||||
LUA_API void (*lua_getuserdatadtor(lua_State* L, int tag))(lua_State*, void*);
|
typedef void (*lua_Destructor)(lua_State* L, void* userdata);
|
||||||
|
|
||||||
|
LUA_API void lua_setuserdatadtor(lua_State* L, int tag, lua_Destructor dtor);
|
||||||
|
LUA_API lua_Destructor lua_getuserdatadtor(lua_State* L, int tag);
|
||||||
|
|
||||||
LUA_API void lua_clonefunction(lua_State* L, int idx);
|
LUA_API void lua_clonefunction(lua_State* L, int idx);
|
||||||
|
|
||||||
|
|
|
@ -1378,13 +1378,13 @@ void lua_setuserdatatag(lua_State* L, int idx, int tag)
|
||||||
uvalue(o)->tag = uint8_t(tag);
|
uvalue(o)->tag = uint8_t(tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
void lua_setuserdatadtor(lua_State* L, int tag, void (*dtor)(lua_State*, void*))
|
void lua_setuserdatadtor(lua_State* L, int tag, lua_Destructor dtor)
|
||||||
{
|
{
|
||||||
api_check(L, unsigned(tag) < LUA_UTAG_LIMIT);
|
api_check(L, unsigned(tag) < LUA_UTAG_LIMIT);
|
||||||
L->global->udatagc[tag] = dtor;
|
L->global->udatagc[tag] = dtor;
|
||||||
}
|
}
|
||||||
|
|
||||||
void (*lua_getuserdatadtor(lua_State* L, int tag))(lua_State*, void*)
|
lua_Destructor lua_getuserdatadtor(lua_State* L, int tag)
|
||||||
{
|
{
|
||||||
api_check(L, unsigned(tag) < LUA_UTAG_LIMIT);
|
api_check(L, unsigned(tag) < LUA_UTAG_LIMIT);
|
||||||
return L->global->udatagc[tag];
|
return L->global->udatagc[tag];
|
||||||
|
|
|
@ -24,8 +24,7 @@ void luaU_freeudata(lua_State* L, Udata* u, lua_Page* page)
|
||||||
{
|
{
|
||||||
if (u->tag < LUA_UTAG_LIMIT)
|
if (u->tag < LUA_UTAG_LIMIT)
|
||||||
{
|
{
|
||||||
void (*dtor)(lua_State*, void*) = nullptr;
|
lua_Destructor dtor = L->global->udatagc[u->tag];
|
||||||
dtor = L->global->udatagc[u->tag];
|
|
||||||
// TODO: access to L here is highly unsafe since this is called during internal GC traversal
|
// TODO: access to L here is highly unsafe since this is called during internal GC traversal
|
||||||
// certain operations such as lua_getthreaddata are okay, but by and large this risks crashes on improper use
|
// certain operations such as lua_getthreaddata are okay, but by and large this risks crashes on improper use
|
||||||
if (dtor)
|
if (dtor)
|
||||||
|
|
Loading…
Add table
Reference in a new issue