mirror of
https://github.com/luau-lang/luau.git
synced 2024-12-13 13:30:40 +00:00
Add lua_cleartable (#678)
To my understanding lua_cleartable does not need GC barriers because it's only removing elements and not modifying the stack. But I'm not a GC expert so please correct if I'm wrong. resolves #672 Co-authored-by: Petri Häkkinen <petrih@rmd.remedy.fi>
This commit is contained in:
parent
bdf7d8c185
commit
fc4871989a
3 changed files with 17 additions and 0 deletions
|
@ -316,6 +316,8 @@ LUA_API void lua_setuserdatadtor(lua_State* L, int tag, void (*dtor)(lua_State*,
|
||||||
|
|
||||||
LUA_API void lua_clonefunction(lua_State* L, int idx);
|
LUA_API void lua_clonefunction(lua_State* L, int idx);
|
||||||
|
|
||||||
|
LUA_API void lua_cleartable(lua_State* L, int idx);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** reference system, can be used to pin objects
|
** reference system, can be used to pin objects
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1376,6 +1376,16 @@ void lua_clonefunction(lua_State* L, int idx)
|
||||||
api_incr_top(L);
|
api_incr_top(L);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void lua_cleartable(lua_State* L, int idx)
|
||||||
|
{
|
||||||
|
StkId t = index2addr(L, idx);
|
||||||
|
api_check(L, ttistable(t));
|
||||||
|
Table* tt = hvalue(t);
|
||||||
|
if (tt->readonly)
|
||||||
|
luaG_runerror(L, "Attempt to modify a readonly table");
|
||||||
|
luaH_clear(tt);
|
||||||
|
}
|
||||||
|
|
||||||
lua_Callbacks* lua_callbacks(lua_State* L)
|
lua_Callbacks* lua_callbacks(lua_State* L)
|
||||||
{
|
{
|
||||||
return &L->global->cb;
|
return &L->global->cb;
|
||||||
|
|
|
@ -778,6 +778,11 @@ TEST_CASE("ApiTables")
|
||||||
CHECK(strcmp(lua_tostring(L, -1), "test") == 0);
|
CHECK(strcmp(lua_tostring(L, -1), "test") == 0);
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
|
|
||||||
|
// lua_cleartable
|
||||||
|
lua_cleartable(L, -1);
|
||||||
|
lua_pushnil(L);
|
||||||
|
CHECK(lua_next(L, -2) == 0);
|
||||||
|
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue