Skip to content

Commit ab83287

Browse files
committed
refactor: remove null argument from protectedCallCont
1 parent 9e4f3db commit ab83287

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/ziglua.zig

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -647,13 +647,20 @@ pub const Lua = struct {
647647

648648
/// Calls a function (or callable object) in protected mode
649649
pub fn protectedCall(lua: *Lua, num_args: i32, num_results: i32, msg_handler: i32) !void {
650-
// The translate-c version of lua_pcall does not type-check so we must use this one
650+
// The translate-c version of lua_pcall does not type-check so we must rewrite it
651651
// (macros don't always translate well with translate-c)
652-
try lua.protectedCallCont(num_args, num_results, msg_handler, 0, null);
652+
const ret = c.lua_pcallk(lua.state, num_args, num_results, msg_handler, 0, null);
653+
switch (ret) {
654+
StatusCode.ok => return,
655+
StatusCode.err_runtime => return Error.Runtime,
656+
StatusCode.err_memory => return Error.Memory,
657+
StatusCode.err_error => return Error.MsgHandler,
658+
else => unreachable,
659+
}
653660
}
654661

655662
/// Behaves exactly like `Lua.protectedCall()` except that it allows the called function to yield
656-
pub fn protectedCallCont(lua: *Lua, num_args: i32, num_results: i32, msg_handler: i32, ctx: Context, k: ?CContFn) !void {
663+
pub fn protectedCallCont(lua: *Lua, num_args: i32, num_results: i32, msg_handler: i32, ctx: Context, k: CContFn) !void {
657664
const ret = c.lua_pcallk(lua.state, num_args, num_results, msg_handler, ctx, k);
658665
switch (ret) {
659666
StatusCode.ok => return,

0 commit comments

Comments
 (0)