Add more garbage collector functions

This commit is contained in:
Nathan Craddock 2023-12-30 21:07:33 -07:00
parent 9f63b1e90d
commit 5b7b930485
2 changed files with 15 additions and 0 deletions

View File

@ -384,6 +384,18 @@ pub const Lua = struct {
return c.lua_gc(lua.state, c.LUA_GCSETSTEPMUL, multiplier);
}
pub fn gcIsRunning(lua: *Lua) bool {
return c.lua_gc(lua.state, c.LUA_GCISRUNNING, 0) == 1;
}
pub fn gcSetGoal(lua: *Lua, goal: i32) i32 {
return c.lua_gc(lua.state, c.LUA_GCSETGOAL, goal);
}
pub fn gcSetStepSize(lua: *Lua, size: i32) i32 {
return c.lua_gc(lua.state, c.LUA_GCSETSTEPSIZE, size);
}
/// Returns the memory allocation function of a given state
/// If data is not null, it is set to the opaque pointer given when the allocator function was set
/// See https://www.lua.org/manual/5.1/manual.html#lua_getallocf

View File

@ -421,9 +421,12 @@ test "garbage collector" {
lua.gcCollect();
lua.gcRestart();
lua.gcStep();
_ = lua.gcIsRunning();
_ = lua.gcCount();
_ = lua.gcCountB();
_ = lua.gcSetGoal(10);
_ = lua.gcSetStepMul(2);
_ = lua.gcSetStepSize(1);
}
test "table access" {