Skip to content

Commit 5ac473d

Browse files
committed
refactor: rename KContext -> Context
1 parent 4ce0da4 commit 5ac473d

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

docs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ The major differences between the C and Zig Lua APIs are described below. This i
7272

7373
### Continuations
7474

75-
All functions and types that deal with continuations have been renamed. For example, `KFunction` is now `LuaContFn`, and `lua_yieldk` is now `yieldCont`.
75+
All functions and types that deal with continuations have been renamed. For example, `KFunction` is now `LuaContFn`, and `lua_yieldk` is now `yieldCont`. One exception is the `KContext` type which has been simply renamed to `Context`. This is only ever used in continuation functions, so the `K` doesn't add much detail.
7676

7777
In general, just replace the "k" with the word "cont". This is just to make the API more clear and Zig-like.
7878

src/ziglua.zig

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,10 @@ pub const hook_tail_call = c.LUA_HOOKTAILCALL;
133133
pub const Integer = c.lua_Integer;
134134

135135
/// Type for continuation-function contexts (usually isize)
136-
pub const KContext = isize;
136+
pub const Context = isize;
137137

138138
/// Type for continuation functions
139-
pub const CContFn = fn (state: ?*LuaState, status: c_int, ctx: KContext) callconv(.C) c_int;
139+
pub const CContFn = fn (state: ?*LuaState, status: c_int, ctx: Context) callconv(.C) c_int;
140140

141141
/// Bitflag for the Lua standard libraries
142142
pub const Libs = packed struct {
@@ -346,7 +346,7 @@ pub const Lua = struct {
346346
}
347347

348348
/// Like `call`, but allows the called function to yield
349-
pub fn callCont(lua: *Lua, num_args: i32, num_results: i32, ctx: KContext, k: ?CContFn) void {
349+
pub fn callCont(lua: *Lua, num_args: i32, num_results: i32, ctx: Context, k: ?CContFn) void {
350350
c.lua_callk(lua.state, num_args, num_results, ctx, k);
351351
}
352352

@@ -653,7 +653,7 @@ pub const Lua = struct {
653653
}
654654

655655
/// 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: KContext, k: ?CContFn) !void {
656+
pub fn protectedCallCont(lua: *Lua, num_args: i32, num_results: i32, msg_handler: i32, ctx: Context, k: ?CContFn) !void {
657657
const ret = c.lua_pcallk(lua.state, num_args, num_results, msg_handler, ctx, k);
658658
switch (ret) {
659659
StatusCode.ok => return,
@@ -1047,7 +1047,7 @@ pub const Lua = struct {
10471047
}
10481048

10491049
/// Yields this coroutine (thread)
1050-
pub fn yieldCont(lua: *Lua, num_results: i32, ctx: KContext, k: CContFn) noreturn {
1050+
pub fn yieldCont(lua: *Lua, num_results: i32, ctx: Context, k: CContFn) noreturn {
10511051
_ = c.lua_yieldk(lua.state, num_results, ctx, k);
10521052
unreachable;
10531053
}
@@ -1674,7 +1674,7 @@ pub inline fn opaqueCast(comptime T: type, ptr: *anyopaque) *T {
16741674

16751675
pub const ZigFn = fn (lua: *Lua) i32;
16761676
pub const ZigHookFn = fn (lua: *Lua, ar: *DebugInfo) void;
1677-
pub const ZigContFn = fn (lua: *Lua, status: Status, ctx: KContext) i32;
1677+
pub const ZigContFn = fn (lua: *Lua, status: Status, ctx: Context) i32;
16781678
pub const ZigReaderFn = fn (lua: *Lua, data: *anyopaque) ?[]const u8;
16791679
pub const ZigWarnFn = fn (data: ?*anyopaque, msg: []const u8, to_cont: bool) void;
16801680
pub const ZigWriterFn = fn (lua: *Lua, buf: []const u8, data: *anyopaque) bool;
@@ -1735,7 +1735,7 @@ fn wrapZigHookFn(comptime f: ZigHookFn) CHookFn {
17351735
/// Wrap a ZigContFn in a CContFn for passing to the API
17361736
fn wrapZigContFn(comptime f: ZigContFn) CContFn {
17371737
return struct {
1738-
fn inner(state: ?*LuaState, status: c_int, ctx: KContext) callconv(.C) c_int {
1738+
fn inner(state: ?*LuaState, status: c_int, ctx: Context) callconv(.C) c_int {
17391739
// this is called by Lua, state should never be null
17401740
var lua: Lua = .{ .state = state.? };
17411741
return @call(.{ .modifier = .always_inline }, f, .{ &lua, @intToEnum(Status, status), ctx });

0 commit comments

Comments
 (0)