Skip to content

Commit 0582f77

Browse files
committed
refactor: remove C from pushFunction and pushClosure
It doesn't add any value to mention C
1 parent 1dfe071 commit 0582f77

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

docs.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ pub fn main() anyerror!void {
218218
var lua = try Lua.init(allocator);
219219
defer lua.deinit();
220220
221-
lua.pushCFunction(ziglua.wrap(adder));
221+
lua.pushFunction(ziglua.wrap(adder));
222222
lua.pushInteger(10);
223223
lua.pushInteger(32);
224224
@@ -229,6 +229,6 @@ pub fn main() anyerror!void {
229229
}
230230
```
231231

232-
Notice the use of `ziglua.wrap`. This is because the function `fn adder(*Lua) i32` is a `ziglua.ZigFn`, when the `lua.register` call expects a `ziglua.CFn` type.
232+
Notice the use of `ziglua.wrap`. This is because the function `fn adder(*Lua) i32` is a `ziglua.ZigFn`, when the `lua.pushFunction` call expects a `ziglua.CFn` type.
233233

234-
The `ziglua.wrap` function generates a new function at compile time that wraps the Zig function in a function compatible with the Lua C API. This could be done automatically by the register function, but that would require the parameter to be comptime-known. The call to `ziglua.wrap` is slightly more verbose, but has the benefit of being more flexible.
234+
The `ziglua.wrap` function generates a new function at compile time that wraps the Zig function in a function compatible with the Lua C API. This could be done automatically by `lua.pushFunction`, but that would require the parameter to be comptime-known. The call to `ziglua.wrap` is slightly more verbose, but has the benefit of being more flexible.

src/tests.zig

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ test "type of and getting values" {
252252
lua.pushNumber(0.1);
253253
_ = lua.pushThread();
254254
_ = lua.pushString("all your codebase are belong to us");
255-
lua.pushCFunction(ziglua.wrap(add));
255+
lua.pushFunction(ziglua.wrap(add));
256256
_ = lua.pushBytes("hello world");
257257
_ = lua.pushFString("%s %s %d", .{ "hello", "world", @as(i32, 10) });
258258
lua.pushValue(1);
@@ -655,7 +655,7 @@ test "table access" {
655655

656656
// create a metatable (it isn't a useful one)
657657
lua.newTable();
658-
lua.pushCFunction(ziglua.wrap(add));
658+
lua.pushFunction(ziglua.wrap(add));
659659
lua.setField(-2, "__len");
660660
lua.setMetatable(1);
661661

@@ -830,7 +830,7 @@ test "upvalues" {
830830

831831
// Initialize the counter at 0
832832
lua.pushInteger(0);
833-
lua.pushCClosure(ziglua.wrap(counter), 1);
833+
lua.pushClosure(ziglua.wrap(counter), 1);
834834
lua.setGlobal("counter");
835835

836836
// call the function repeatedly, each time ensuring the result increases by one
@@ -930,7 +930,7 @@ test "raise error" {
930930
}
931931
}.inner;
932932

933-
lua.pushCFunction(ziglua.wrap(makeError));
933+
lua.pushFunction(ziglua.wrap(makeError));
934934
try expectError(Error.Runtime, lua.protectedCall(0, 0, 0));
935935
try expectEqualStrings("makeError made an error", try lua.toBytes(-1));
936936
}
@@ -961,7 +961,7 @@ test "yielding" {
961961
}.inner;
962962

963963
var thread = lua.newThread();
964-
thread.pushCFunction(ziglua.wrap(willYield));
964+
thread.pushFunction(ziglua.wrap(willYield));
965965

966966
try expect(!lua.isYieldable());
967967
try expect(thread.isYieldable());

src/ziglua.zig

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -681,16 +681,16 @@ pub const Lua = struct {
681681
c.lua_pushboolean(lua.state, @boolToInt(b));
682682
}
683683

684-
/// Pushes a new C Closure onto the stack
684+
/// Pushes a new Closure onto the stack
685685
/// `n` tells how many upvalues this function will have
686-
pub fn pushCClosure(lua: *Lua, c_fn: CFn, n: i32) void {
686+
pub fn pushClosure(lua: *Lua, c_fn: CFn, n: i32) void {
687687
c.lua_pushcclosure(lua.state, c_fn, n);
688688
}
689689

690-
/// Pushes a C function onto the stack.
691-
/// Equivalent to pushCClosure with no upvalues
692-
pub fn pushCFunction(lua: *Lua, c_fn: CFn) void {
693-
lua.pushCClosure(c_fn, 0);
690+
/// Pushes a function onto the stack.
691+
/// Equivalent to pushClosure with no upvalues
692+
pub fn pushFunction(lua: *Lua, c_fn: CFn) void {
693+
lua.pushClosure(c_fn, 0);
694694
}
695695

696696
/// Push a formatted string onto the stack and return a pointer to the string
@@ -1422,7 +1422,7 @@ pub const Lua = struct {
14221422
var i: i32 = 0;
14231423
// copy upvalues to the top
14241424
while (i < num_upvalues) : (i += 1) lua.pushValue(-num_upvalues);
1425-
lua.pushCClosure(func, num_upvalues);
1425+
lua.pushClosure(func, num_upvalues);
14261426
} else lua.pushBoolean(false); // register a placeholder
14271427
lua.setField(-(num_upvalues + 2), f.name);
14281428
}

0 commit comments

Comments
 (0)