Skip to content

Commit 86f234c

Browse files
committedMay 14, 2023
Add new closeThread() function added in 5.4.6
1 parent 291bce6 commit 86f234c

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed
 

‎src/ziglua-5.4/lib.zig

+14-3
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,18 @@ pub const Lua = struct {
432432
c.lua_closeslot(lua.state, index);
433433
}
434434

435+
/// Resets a thread, cleaning its call stack and closing all pending to-be-closed variables.
436+
/// Returns a status code: LUA_OK for no errors in the thread, or an error status otherwise.
437+
/// In case of error, leaves the error object on the top of the stack.
438+
/// The parameter from represents the coroutine that is resetting L.
439+
/// If there is no such coroutine, this parameter can be NULL.
440+
/// (This function was introduced in release 5.4.6.)
441+
/// See https://www.lua.org/manual/5.4/manual.html#lua_closethread
442+
pub fn closeThread(lua: *Lua, from: ?Lua) !void {
443+
if (c.lua_closethread(lua.state, if (from) |f| f.state else null) != StatusCode.ok) return error.Fail;
444+
}
445+
446+
435447
/// Compares two Lua values
436448
/// Returns true if the value at index1 satisisfies the comparison with the value at index2
437449
/// Returns false otherwise, or if any index is not valid
@@ -987,11 +999,10 @@ pub const Lua = struct {
987999
lua.pop(1);
9881000
}
9891001

990-
/// Resets a thread, cleaning its call stack and closing all pending to-be-closed variables
991-
/// Returns an error if an error occured and leaves an error object on top of the stack
1002+
/// This function is deprecated; it is equivalent to closeThread() with from being null.
9921003
/// See https://www.lua.org/manual/5.4/manual.html#lua_resetthread
9931004
pub fn resetThread(lua: *Lua) !void {
994-
if (c.lua_resetthread(lua.state) != StatusCode.ok) return error.Fail;
1005+
return lua.closeThread(null);
9951006
}
9961007

9971008
/// Starts and resumes a coroutine in the given thread

‎src/ziglua-5.4/tests.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ test "dump and load" {
750750
try lua.dump(ziglua.wrap(writer), &buffer, false);
751751

752752
// clear the stack
753-
try lua.resetThread();
753+
try lua.closeThread(lua);
754754

755755
const reader = struct {
756756
fn inner(l: *Lua, data: *anyopaque) ?[]const u8 {

0 commit comments

Comments
 (0)