Skip to content

Commit 5505a3e

Browse files
committedFeb 18, 2023
feat: rename addLString to addBytes
This is for consistency. Also removes several unnecessary pointer casts
1 parent 582bf5f commit 5505a3e

File tree

8 files changed

+20
-24
lines changed

8 files changed

+20
-24
lines changed
 

‎src/ziglua-5.1/lib.zig

+4-5
Original file line numberDiff line numberDiff line change
@@ -705,8 +705,7 @@ pub const Lua = struct {
705705
/// Push a formatted string onto the stack and return a pointer to the string
706706
/// See https://www.lua.org/manual/5.1/manual.html#lua_pushfstring
707707
pub fn pushFStringEx(lua: *Lua, fmt: [:0]const u8, args: anytype) [*:0]const u8 {
708-
const ptr = @call(.auto, c.lua_pushfstring, .{ lua.state, fmt.ptr } ++ args);
709-
return @ptrCast([*:0]const u8, ptr);
708+
return @call(.auto, c.lua_pushfstring, .{ lua.state, fmt.ptr } ++ args);
710709
}
711710

712711
/// Pushes an integer with value `n` onto the stack
@@ -1193,7 +1192,7 @@ pub const Lua = struct {
11931192
/// See https://www.lua.org/manual/5.1/manual.html#luaL_checklstring
11941193
pub fn checkBytes(lua: *Lua, arg: i32) [:0]const u8 {
11951194
var length: usize = 0;
1196-
const str = c.luaL_checklstring(lua.state, arg, @ptrCast([*c]usize, &length));
1195+
const str = c.luaL_checklstring(lua.state, arg, &length);
11971196
// luaL_checklstring never returns null (throws lua error)
11981197
return str[0..length :0];
11991198
}
@@ -1558,8 +1557,8 @@ pub const Buffer = struct {
15581557
/// Adds the string to the buffer
15591558
/// See https://www.lua.org/manual/5.1/manual.html#luaL_addlstring
15601559
/// TODO: rename to addBytes
1561-
pub fn addLString(buf: *Buffer, str: []const u8) void {
1562-
c.luaL_addlstring(&buf.b, @ptrCast([*c]const u8, str), str.len);
1560+
pub fn addBytes(buf: *Buffer, str: []const u8) void {
1561+
c.luaL_addlstring(&buf.b, str.ptr, str.len);
15631562
}
15641563

15651564
/// Adds to the buffer a string of `length` previously copied to the buffer area

‎src/ziglua-5.1/tests.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ test "string buffers" {
373373
str[1] = 'a';
374374
buffer.addSize(2);
375375

376-
buffer.addLString(" api ");
376+
buffer.addBytes(" api ");
377377
lua.pushNumber(5.1);
378378
buffer.addValue();
379379
buffer.pushResult();

‎src/ziglua-5.2/lib.zig

+4-5
Original file line numberDiff line numberDiff line change
@@ -774,8 +774,7 @@ pub const Lua = struct {
774774

775775
/// Push a formatted string onto the stack and return a pointer to the string
776776
pub fn pushFStringEx(lua: *Lua, fmt: [:0]const u8, args: anytype) [*:0]const u8 {
777-
const ptr = @call(.auto, c.lua_pushfstring, .{ lua.state, fmt.ptr } ++ args);
778-
return @ptrCast([*:0]const u8, ptr);
777+
return @call(.auto, c.lua_pushfstring, .{ lua.state, fmt.ptr } ++ args);
779778
}
780779

781780
/// Pushes the global environment onto the stack
@@ -1288,7 +1287,7 @@ pub const Lua = struct {
12881287
/// Checks whether the function argument `arg` is a slice of bytes and returns the slice
12891288
pub fn checkBytes(lua: *Lua, arg: i32) [:0]const u8 {
12901289
var length: usize = 0;
1291-
const str = c.luaL_checklstring(lua.state, arg, @ptrCast([*c]usize, &length));
1290+
const str = c.luaL_checklstring(lua.state, arg, &length);
12921291
// luaL_checklstring never returns null (throws lua error)
12931292
return str[0..length :0];
12941293
}
@@ -1712,8 +1711,8 @@ pub const Buffer = struct {
17121711
}
17131712

17141713
/// Adds the string to the buffer
1715-
pub fn addLString(buf: *Buffer, str: []const u8) void {
1716-
c.luaL_addlstring(&buf.b, @ptrCast([*c]const u8, str), str.len);
1714+
pub fn addBytes(buf: *Buffer, str: []const u8) void {
1715+
c.luaL_addlstring(&buf.b, str.ptr, str.len);
17171716
}
17181717

17191718
/// Adds to the buffer a string of `length` previously copied to the buffer area

‎src/ziglua-5.2/tests.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ test "string buffers" {
426426
str[2] = 'a';
427427
buffer.addSize(3);
428428

429-
buffer.addLString(" api ");
429+
buffer.addBytes(" api ");
430430
lua.pushNumber(5.4);
431431
buffer.addValue();
432432
buffer.sub(4);

‎src/ziglua-5.3/lib.zig

+4-5
Original file line numberDiff line numberDiff line change
@@ -826,8 +826,7 @@ pub const Lua = struct {
826826

827827
/// Push a formatted string onto the stack and return a pointer to the string
828828
pub fn pushFStringEx(lua: *Lua, fmt: [:0]const u8, args: anytype) [*:0]const u8 {
829-
const ptr = @call(.auto, c.lua_pushfstring, .{ lua.state, fmt.ptr } ++ args);
830-
return @ptrCast([*:0]const u8, ptr);
829+
return @call(.auto, c.lua_pushfstring, .{ lua.state, fmt.ptr } ++ args);
831830
}
832831

833832
/// Pushes the global environment onto the stack
@@ -1349,7 +1348,7 @@ pub const Lua = struct {
13491348
/// Checks whether the function argument `arg` is a slice of bytes and returns the slice
13501349
pub fn checkBytes(lua: *Lua, arg: i32) [:0]const u8 {
13511350
var length: usize = 0;
1352-
const str = c.luaL_checklstring(lua.state, arg, @ptrCast([*c]usize, &length));
1351+
const str = c.luaL_checklstring(lua.state, arg, &length);
13531352
// luaL_checklstring never returns null (throws lua error)
13541353
return str[0..length :0];
13551354
}
@@ -1762,8 +1761,8 @@ pub const Buffer = struct {
17621761
}
17631762

17641763
/// Adds the string to the buffer
1765-
pub fn addLString(buf: *Buffer, str: []const u8) void {
1766-
c.luaL_addlstring(&buf.b, @ptrCast([*c]const u8, str), str.len);
1764+
pub fn addBytes(buf: *Buffer, str: []const u8) void {
1765+
c.luaL_addlstring(&buf.b, str.ptr, str.len);
17671766
}
17681767

17691768
/// Adds to the buffer a string of `length` previously copied to the buffer area

‎src/ziglua-5.3/tests.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ test "string buffers" {
453453
str[2] = 'a';
454454
buffer.addSize(3);
455455

456-
buffer.addLString(" api ");
456+
buffer.addBytes(" api ");
457457
lua.pushNumber(5.4);
458458
buffer.addValue();
459459
buffer.sub(4);

‎src/ziglua-5.4/lib.zig

+4-5
Original file line numberDiff line numberDiff line change
@@ -838,8 +838,7 @@ pub const Lua = struct {
838838

839839
/// Push a formatted string onto the stack and return a pointer to the string
840840
pub fn pushFStringEx(lua: *Lua, fmt: [:0]const u8, args: anytype) [*:0]const u8 {
841-
const ptr = @call(.auto, c.lua_pushfstring, .{ lua.state, fmt.ptr } ++ args);
842-
return @ptrCast([*:0]const u8, ptr);
841+
return @call(.auto, c.lua_pushfstring, .{ lua.state, fmt.ptr } ++ args);
843842
}
844843

845844
/// Pushes the global environment onto the stack
@@ -1393,7 +1392,7 @@ pub const Lua = struct {
13931392
/// Checks whether the function argument `arg` is a slice of bytes and returns the slice
13941393
pub fn checkBytes(lua: *Lua, arg: i32) [:0]const u8 {
13951394
var length: usize = 0;
1396-
const str = c.luaL_checklstring(lua.state, arg, @ptrCast([*c]usize, &length));
1395+
const str = c.luaL_checklstring(lua.state, arg, &length);
13971396
// luaL_checklstring never returns null (throws lua error)
13981397
return str[0..length :0];
13991398
}
@@ -1822,8 +1821,8 @@ pub const Buffer = struct {
18221821
}
18231822

18241823
/// Adds the string to the buffer
1825-
pub fn addLString(buf: *Buffer, str: []const u8) void {
1826-
c.luaL_addlstring(&buf.b, @ptrCast([*c]const u8, str), str.len);
1824+
pub fn addBytes(buf: *Buffer, str: []const u8) void {
1825+
c.luaL_addlstring(&buf.b, str.ptr, str.len);
18271826
}
18281827

18291828
/// Adds to the buffer a string of `length` previously copied to the buffer area

‎src/ziglua-5.4/tests.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ test "string buffers" {
460460
try expectEqual(@as(usize, 6), buffer.len());
461461
try expectEqualStrings("ziglua", buffer.addr());
462462

463-
buffer.addLString(" api ");
463+
buffer.addBytes(" api ");
464464
try expectEqualStrings("ziglua api ", buffer.addr());
465465

466466
lua.pushNumber(5.4);

0 commit comments

Comments
 (0)