Skip to content

Commit 7070be0

Browse files
committed
feat: rename all *Aux() functions
The new names are more clear on the use
1 parent 837048b commit 7070be0

File tree

8 files changed

+61
-66
lines changed

8 files changed

+61
-66
lines changed

src/ziglua-5.1/lib.zig

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,6 @@ pub const Lua = struct {
657657
/// Calls a function (or callable object) in protected mode
658658
/// See https://www.lua.org/manual/5.1/manual.html#lua_pcall
659659
pub fn protectedCall(lua: *Lua, num_args: i32, num_results: i32, msg_handler: i32) !void {
660-
// NOTE: it might be good to make the args named struct params?
661660
// The translate-c version of lua_pcall does not type-check so we must rewrite it
662661
// (macros don't always translate well with translate-c)
663662
const ret = c.lua_pcall(lua.state, num_args, num_results, msg_handler);
@@ -1229,7 +1228,7 @@ pub const Lua = struct {
12291228
/// Grows the stack size to top + `size` elements, raising an error if the stack cannot grow to that size
12301229
/// `msg` is an additional text to go into the error message
12311230
/// See https://www.lua.org/manual/5.1/manual.html#luaL_checkstack
1232-
pub fn checkStackAux(lua: *Lua, size: i32, msg: ?[*:0]const u8) void {
1231+
pub fn checkStackErr(lua: *Lua, size: i32, msg: ?[*:0]const u8) void {
12331232
c.luaL_checkstack(lua.state, size, msg);
12341233
}
12351234

@@ -1272,14 +1271,13 @@ pub const Lua = struct {
12721271

12731272
/// Raises an error
12741273
/// See https://www.lua.org/manual/5.1/manual.html#luaL_error
1275-
pub fn raiseErrorAux(lua: *Lua, fmt: [:0]const u8, args: anytype) noreturn {
1274+
pub fn raiseErrorStr(lua: *Lua, fmt: [:0]const u8, args: anytype) noreturn {
12761275
_ = @call(.auto, c.luaL_error, .{ lua.state, fmt.ptr } ++ args);
12771276
unreachable;
12781277
}
12791278

12801279
/// Pushes onto the stack the field `e` from the metatable of the object at index `obj`
12811280
/// and returns the type of the pushed value
1282-
/// TODO: possibly return an error if nil
12831281
/// See https://www.lua.org/manual/5.1/manual.html#luaL_getmetafield
12841282
pub fn getMetaField(lua: *Lua, obj: i32, field: [:0]const u8) !LuaType {
12851283
const val_type = @intToEnum(LuaType, c.luaL_getmetafield(lua.state, obj, field.ptr));
@@ -1289,10 +1287,9 @@ pub const Lua = struct {
12891287

12901288
/// Pushes onto the stack the metatable associated with the name `type_name` in the registry
12911289
/// or nil if there is no metatable associated with that name. Returns the type of the pushed value
1292-
/// TODO: return error when type is nil?
12931290
/// See https://www.lua.org/manual/5.1/manual.html#luaL_getmetatable
1294-
pub fn getMetatableAux(lua: *Lua, type_name: [:0]const u8) void {
1295-
c.luaL_getmetatable(lua.state, type_name);
1291+
pub fn getMetatableRegistry(lua: *Lua, table_name: [:0]const u8) void {
1292+
c.luaL_getmetatable(lua.state, table_name);
12961293
}
12971294

12981295
/// Creates a copy of string `str`, replacing any occurrence of the string `pat` with the string `rep`
@@ -1351,7 +1348,7 @@ pub const Lua = struct {
13511348

13521349
/// Creates a new Lua state with an allocator using the default libc allocator
13531350
/// See https://www.lua.org/manual/5.1/manual.html#luaL_newstate
1354-
pub fn newStateAux() !Lua {
1351+
pub fn newStateLibc() !Lua {
13551352
const state = c.luaL_newstate() orelse return error.Memory;
13561353
return Lua{ .state = state };
13571354
}
@@ -1416,7 +1413,7 @@ pub const Lua = struct {
14161413
if (!lua.isTable(-1)) {
14171414
lua.pop(1);
14181415
if (c.luaL_findtable(lua.state, globals_index, name, @intCast(c_int, funcs.len))) |_| {
1419-
lua.raiseErrorAux("name conflict for module " ++ c.LUA_QS, .{name.ptr});
1416+
lua.raiseErrorStr("name conflict for module " ++ c.LUA_QS, .{name.ptr});
14201417
}
14211418
lua.pushValue(-1);
14221419
lua.setField(-3, name);
@@ -1554,7 +1551,6 @@ pub const Buffer = struct {
15541551

15551552
/// Adds the string to the buffer
15561553
/// See https://www.lua.org/manual/5.1/manual.html#luaL_addlstring
1557-
/// TODO: rename to addBytes
15581554
pub fn addBytes(buf: *Buffer, str: []const u8) void {
15591555
c.luaL_addlstring(&buf.b, str.ptr, str.len);
15601556
}

src/ziglua-5.1/tests.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ test "initialization" {
8686
try expectError(error.Memory, Lua.newState(failing_alloc, null));
8787

8888
// use the auxiliary library (uses libc realloc and cannot be checked for leaks!)
89-
lua = try Lua.newStateAux();
89+
lua = try Lua.newStateLibc();
9090
lua.close();
9191
}
9292

@@ -273,7 +273,7 @@ test "filling and checking the stack" {
273273
try expectError(error.Fail, lua.checkStack(1_000_000));
274274

275275
// this is small enough it won't fail (would raise an error if it did)
276-
lua.checkStackAux(40, null);
276+
lua.checkStackErr(40, null);
277277
while (count < 40) : (count += 1) {
278278
lua.pushNil();
279279
}
@@ -1099,7 +1099,7 @@ test "args and errors" {
10991099

11001100
const raisesError = ziglua.wrap(struct {
11011101
fn inner(l: *Lua) i32 {
1102-
l.raiseErrorAux("some error %s!", .{"zig"});
1102+
l.raiseErrorStr("some error %s!", .{"zig"});
11031103
unreachable;
11041104
}
11051105
}.inner);

src/ziglua-5.2/lib.zig

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,6 @@ pub const Lua = struct {
717717
}
718718

719719
/// Calls a function (or callable object) in protected mode
720-
/// NOTE: it might be good to make the args named struct params?
721720
pub fn protectedCall(lua: *Lua, num_args: i32, num_results: i32, msg_handler: i32) !void {
722721
// The translate-c version of lua_pcall does not type-check so we must rewrite it
723722
// (macros don't always translate well with translate-c)
@@ -1321,7 +1320,7 @@ pub const Lua = struct {
13211320

13221321
/// Grows the stack size to top + `size` elements, raising an error if the stack cannot grow to that size
13231322
/// `msg` is an additional text to go into the error message
1324-
pub fn checkStackAux(lua: *Lua, size: i32, msg: ?[*:0]const u8) void {
1323+
pub fn checkStackErr(lua: *Lua, size: i32, msg: ?[*:0]const u8) void {
13251324
c.luaL_checkstack(lua.state, size, msg);
13261325
}
13271326

@@ -1369,7 +1368,7 @@ pub const Lua = struct {
13691368
}
13701369

13711370
/// Raises an error
1372-
pub fn raiseErrorAux(lua: *Lua, fmt: [:0]const u8, args: anytype) noreturn {
1371+
pub fn raiseErrorStr(lua: *Lua, fmt: [:0]const u8, args: anytype) noreturn {
13731372
_ = @call(.auto, c.luaL_error, .{ lua.state, fmt.ptr } ++ args);
13741373
unreachable;
13751374
}
@@ -1396,8 +1395,8 @@ pub const Lua = struct {
13961395
/// Pushes onto the stack the metatable associated with the name `type_name` in the registry
13971396
/// or nil if there is no metatable associated with that name. Returns the type of the pushed value
13981397
/// TODO: return error when type is nil?
1399-
pub fn getMetatableAux(lua: *Lua, type_name: [:0]const u8) void {
1400-
c.luaL_getmetatable(lua.state, type_name.ptr);
1398+
pub fn getMetatableRegistry(lua: *Lua, table_name: [:0]const u8) void {
1399+
c.luaL_getmetatable(lua.state, table_name.ptr);
14011400
}
14021401

14031402
/// Ensures that the value t[`field`], where t is the value at `index`, is a table, and pushes that table onto the stack.
@@ -1413,7 +1412,7 @@ pub const Lua = struct {
14131412

14141413
/// Returns the "length" of the value at the given index as a number
14151414
/// it is equivalent to the '#' operator in Lua
1416-
pub fn lenAux(lua: *Lua, index: i32) i64 {
1415+
pub fn lenRaiseErr(lua: *Lua, index: i32) i64 {
14171416
return c.luaL_len(lua.state, index);
14181417
}
14191418

@@ -1495,7 +1494,7 @@ pub const Lua = struct {
14951494
}
14961495

14971496
/// Creates a new Lua state with an allocator using the default libc allocator
1498-
pub fn newStateAux() !Lua {
1497+
pub fn newStateLibc() !Lua {
14991498
const state = c.luaL_newstate() orelse return error.Memory;
15001499
return Lua{ .state = state };
15011500
}
@@ -1553,7 +1552,7 @@ pub const Lua = struct {
15531552
/// Registers all functions in the array `fns` into the table on the top of the stack
15541553
/// All functions are created with `num_upvalues` upvalues
15551554
pub fn setFuncs(lua: *Lua, funcs: []const FnReg, num_upvalues: i32) void {
1556-
lua.checkStackAux(num_upvalues, "too many upvalues");
1555+
lua.checkStackErr(num_upvalues, "too many upvalues");
15571556
for (funcs) |f| {
15581557
if (f.func) |func| {
15591558
var i: i32 = 0;
@@ -1568,7 +1567,7 @@ pub const Lua = struct {
15681567

15691568
/// Sets the metatable of the object on the top of the stack as the metatable associated
15701569
/// with `table_name` in the registry
1571-
pub fn setMetatableAux(lua: *Lua, table_name: [:0]const u8) void {
1570+
pub fn setMetatableRegistry(lua: *Lua, table_name: [:0]const u8) void {
15721571
c.luaL_setmetatable(lua.state, table_name.ptr);
15731572
}
15741573

@@ -1580,7 +1579,7 @@ pub const Lua = struct {
15801579
}
15811580

15821581
/// Converts any Lua value at the given index into a string in a reasonable format
1583-
pub fn toBytesAux(lua: *Lua, index: i32) [:0]const u8 {
1582+
pub fn toBytesFmt(lua: *Lua, index: i32) [:0]const u8 {
15841583
var length: usize = undefined;
15851584
const ptr = c.luaL_tolstring(lua.state, index, &length);
15861585
return ptr[0..length :0];

src/ziglua-5.2/tests.zig

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ test "initialization" {
8787
try expectError(error.Memory, Lua.newState(failing_alloc, null));
8888

8989
// use the auxiliary library (uses libc realloc and cannot be checked for leaks!)
90-
lua = try Lua.newStateAux();
90+
lua = try Lua.newStateLibc();
9191
lua.close();
9292
}
9393

@@ -346,7 +346,7 @@ test "filling and checking the stack" {
346346
try expectError(error.Fail, lua.checkStack(1_000_000));
347347

348348
// this is small enough it won't fail (would raise an error if it did)
349-
lua.checkStackAux(40, null);
349+
lua.checkStackErr(40, null);
350350
while (count < 40) : (count += 1) {
351351
lua.pushNil();
352352
}
@@ -443,7 +443,7 @@ test "string buffers" {
443443
b = buffer.prep();
444444
std.mem.copy(u8, b, "defghijklmnopqrstuvwxyz");
445445
buffer.pushResultSize(23);
446-
try expectEqualStrings("abcdefghijklmnopqrstuvwxyz", lua.toBytesAux(-1));
446+
try expectEqualStrings("abcdefghijklmnopqrstuvwxyz", lua.toBytesFmt(-1));
447447
lua.pop(1);
448448

449449
lua.len(-1);
@@ -626,7 +626,7 @@ test "table access" {
626626
lua.rawSetIndex(-2, index);
627627
}
628628
try expectEqual(@as(usize, 5), lua.rawLen(-1));
629-
try expectEqual(@as(Integer, 5), lua.lenAux(-1));
629+
try expectEqual(@as(Integer, 5), lua.lenRaiseErr(-1));
630630

631631
// add a few more
632632
while (index <= 10) : (index += 1) {
@@ -1116,7 +1116,7 @@ test "metatables" {
11161116
try lua.doString("f = function() return 10 end");
11171117

11181118
try lua.newMetatable("mt");
1119-
_ = lua.getMetatableAux("mt");
1119+
_ = lua.getMetatableRegistry("mt");
11201120
try expect(lua.compare(1, 2, .eq));
11211121
lua.pop(1);
11221122

@@ -1125,7 +1125,7 @@ test "metatables" {
11251125
lua.setField(1, "__len");
11261126

11271127
lua.newTable();
1128-
lua.setMetatableAux("mt");
1128+
lua.setMetatableRegistry("mt");
11291129

11301130
try lua.callMeta(-1, "__len");
11311131
try expectEqual(@as(Number, 10), try lua.toNumber(-1));
@@ -1285,7 +1285,7 @@ test "args and errors" {
12851285

12861286
const raisesError = ziglua.wrap(struct {
12871287
fn inner(l: *Lua) i32 {
1288-
l.raiseErrorAux("some error %s!", .{"zig"});
1288+
l.raiseErrorStr("some error %s!", .{"zig"});
12891289
unreachable;
12901290
}
12911291
}.inner);
@@ -1361,7 +1361,7 @@ test "userdata" {
13611361

13621362
{
13631363
var t = lua.newUserdata(Type);
1364-
lua.setMetatableAux(@typeName(Type));
1364+
lua.setMetatableRegistry(@typeName(Type));
13651365
t.a = 1234;
13661366
t.b = 3.14;
13671367

@@ -1392,7 +1392,7 @@ test "userdata" {
13921392

13931393
{
13941394
var t = lua.newUserdata(Type);
1395-
lua.setMetatableAux(@typeName(Type));
1395+
lua.setMetatableRegistry(@typeName(Type));
13961396
t.a = 1234;
13971397
t.b = 3.14;
13981398

src/ziglua-5.3/lib.zig

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,7 +1382,7 @@ pub const Lua = struct {
13821382

13831383
/// Grows the stack size to top + `size` elements, raising an error if the stack cannot grow to that size
13841384
/// `msg` is an additional text to go into the error message
1385-
pub fn checkStackAux(lua: *Lua, size: i32, msg: ?[*:0]const u8) void {
1385+
pub fn checkStackErr(lua: *Lua, size: i32, msg: ?[*:0]const u8) void {
13861386
c.luaL_checkstack(lua.state, size, msg);
13871387
}
13881388

@@ -1425,7 +1425,7 @@ pub const Lua = struct {
14251425
}
14261426

14271427
/// Raises an error
1428-
pub fn raiseErrorAux(lua: *Lua, fmt: [:0]const u8, args: anytype) noreturn {
1428+
pub fn raiseErrorStr(lua: *Lua, fmt: [:0]const u8, args: anytype) noreturn {
14291429
_ = @call(.auto, c.luaL_error, .{ lua.state, fmt.ptr } ++ args);
14301430
unreachable;
14311431
}
@@ -1452,8 +1452,8 @@ pub const Lua = struct {
14521452
/// Pushes onto the stack the metatable associated with the name `type_name` in the registry
14531453
/// or nil if there is no metatable associated with that name. Returns the type of the pushed value
14541454
/// TODO: return error when type is nil?
1455-
pub fn getMetatableAux(lua: *Lua, type_name: [:0]const u8) LuaType {
1456-
return @intToEnum(LuaType, c.luaL_getmetatable(lua.state, type_name.ptr));
1455+
pub fn getMetatableRegistry(lua: *Lua, table_name: [:0]const u8) LuaType {
1456+
return @intToEnum(LuaType, c.luaL_getmetatable(lua.state, table_name.ptr));
14571457
}
14581458

14591459
/// Ensures that the value t[`field`], where t is the value at `index`, is a table, and pushes that table onto the stack.
@@ -1469,7 +1469,7 @@ pub const Lua = struct {
14691469

14701470
/// Returns the "length" of the value at the given index as a number
14711471
/// it is equivalent to the '#' operator in Lua
1472-
pub fn lenAux(lua: *Lua, index: i32) i64 {
1472+
pub fn lenRaiseErr(lua: *Lua, index: i32) i64 {
14731473
return c.luaL_len(lua.state, index);
14741474
}
14751475

@@ -1551,7 +1551,7 @@ pub const Lua = struct {
15511551
}
15521552

15531553
/// Creates a new Lua state with an allocator using the default libc allocator
1554-
pub fn newStateAux() !Lua {
1554+
pub fn newStateLibc() !Lua {
15551555
const state = c.luaL_newstate() orelse return error.Memory;
15561556
return Lua{ .state = state };
15571557
}
@@ -1603,7 +1603,7 @@ pub const Lua = struct {
16031603
/// Registers all functions in the array `fns` into the table on the top of the stack
16041604
/// All functions are created with `num_upvalues` upvalues
16051605
pub fn setFuncs(lua: *Lua, funcs: []const FnReg, num_upvalues: i32) void {
1606-
lua.checkStackAux(num_upvalues, "too many upvalues");
1606+
lua.checkStackErr(num_upvalues, "too many upvalues");
16071607
for (funcs) |f| {
16081608
if (f.func) |func| {
16091609
var i: i32 = 0;
@@ -1618,7 +1618,7 @@ pub const Lua = struct {
16181618

16191619
/// Sets the metatable of the object on the top of the stack as the metatable associated
16201620
/// with `table_name` in the registry
1621-
pub fn setMetatableAux(lua: *Lua, table_name: [:0]const u8) void {
1621+
pub fn setMetatableRegistry(lua: *Lua, table_name: [:0]const u8) void {
16221622
c.luaL_setmetatable(lua.state, table_name.ptr);
16231623
}
16241624

@@ -1630,7 +1630,7 @@ pub const Lua = struct {
16301630
}
16311631

16321632
/// Converts any Lua value at the given index into a string in a reasonable format
1633-
pub fn toBytesAux(lua: *Lua, index: i32) [:0]const u8 {
1633+
pub fn toBytesFmt(lua: *Lua, index: i32) [:0]const u8 {
16341634
var length: usize = undefined;
16351635
const ptr = c.luaL_tolstring(lua.state, index, &length);
16361636
return ptr[0..length :0];

0 commit comments

Comments
 (0)