Skip to content

Commit 29f730a

Browse files
committed
feat: remove X variants of load functions
It is simpler to just have one type of function and make the argument explicit
1 parent a7b78d9 commit 29f730a

File tree

6 files changed

+12
-47
lines changed

6 files changed

+12
-47
lines changed

src/ziglua-5.2/lib.zig

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,7 +1414,7 @@ pub const Lua = struct {
14141414
/// See https://www.lua.org/manual/5.2/manual.html#luaL_dofile
14151415
pub fn doFile(lua: *Lua, file_name: [:0]const u8) !void {
14161416
// translate-c failure
1417-
try lua.loadFile(file_name);
1417+
try lua.loadFile(file_name, .binary_text);
14181418
try lua.protectedCall(0, mult_return, 0);
14191419
}
14201420

@@ -1483,15 +1483,9 @@ pub const Lua = struct {
14831483
return c.luaL_len(lua.state, index);
14841484
}
14851485

1486-
/// The same as `Lua.loadBufferX` with `mode` set to binary+text
1487-
/// See https://www.lua.org/manual/5.2/manual.html#luaL_loadbuffer
1488-
pub fn loadBuffer(lua: *Lua, buf: []const u8, name: [:0]const u8) !void {
1489-
try lua.loadBufferX(buf, name, .binary_text);
1490-
}
1491-
14921486
/// Loads a buffer as a Lua chunk
14931487
/// See https://www.lua.org/manual/5.2/manual.html#luaL_loadbufferx
1494-
pub fn loadBufferX(lua: *Lua, buf: []const u8, name: [:0]const u8, mode: Mode) !void {
1488+
pub fn loadBuffer(lua: *Lua, buf: []const u8, name: [:0]const u8, mode: Mode) !void {
14951489
const mode_str = switch (mode) {
14961490
.binary => "b",
14971491
.text => "t",
@@ -1505,15 +1499,9 @@ pub const Lua = struct {
15051499
}
15061500
}
15071501

1508-
/// Equivalent to `Lua.loadFileX()` with mode equal to binary+text
1509-
/// See https://www.lua.org/manual/5.2/manual.html#luaL_loadfile
1510-
pub fn loadFile(lua: *Lua, file_name: [:0]const u8) !void {
1511-
try lua.loadFileX(file_name, .binary_text);
1512-
}
1513-
15141502
/// Loads a file as a Lua chunk
15151503
/// See https://www.lua.org/manual/5.2/manual.html#luaL_loadfilex
1516-
pub fn loadFileX(lua: *Lua, file_name: [:0]const u8, mode: Mode) !void {
1504+
pub fn loadFile(lua: *Lua, file_name: [:0]const u8, mode: Mode) !void {
15171505
const mode_str = switch (mode) {
15181506
.binary => "b",
15191507
.text => "t",

src/ziglua-5.2/tests.zig

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,7 +1223,7 @@ test "loadBuffer" {
12231223
var lua = try Lua.init(testing.allocator);
12241224
defer lua.deinit();
12251225

1226-
_ = try lua.loadBuffer("global = 10", "chunkname");
1226+
_ = try lua.loadBuffer("global = 10", "chunkname", .text);
12271227
try lua.protectedCall(0, ziglua.mult_return, 0);
12281228
lua.getGlobal("global");
12291229
try expectEqual(@as(Integer, 10), try lua.toInteger(-1));
@@ -1409,7 +1409,6 @@ test "refs" {
14091409
// no need to test file loading
14101410
_ = Lua.doFile;
14111411
_ = Lua.loadFile;
1412-
_ = Lua.loadFileX;
14131412

14141413
// probably not needed in ziglua
14151414
_ = Lua.execResult;

src/ziglua-5.3/lib.zig

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,7 +1370,7 @@ pub const Lua = struct {
13701370
/// Loads and runs the given file
13711371
pub fn doFile(lua: *Lua, file_name: [:0]const u8) !void {
13721372
// translate-c failure
1373-
try lua.loadFile(file_name);
1373+
try lua.loadFile(file_name, .binary_text);
13741374
try lua.protectedCall(0, mult_return, 0);
13751375
}
13761376

@@ -1430,13 +1430,8 @@ pub const Lua = struct {
14301430
return c.luaL_len(lua.state, index);
14311431
}
14321432

1433-
/// The same as `Lua.loadBufferX` with `mode` set to binary+text
1434-
pub fn loadBuffer(lua: *Lua, buf: []const u8, name: [:0]const u8) !void {
1435-
try lua.loadBufferX(buf, name, .binary_text);
1436-
}
1437-
14381433
/// Loads a buffer as a Lua chunk
1439-
pub fn loadBufferX(lua: *Lua, buf: []const u8, name: [:0]const u8, mode: Mode) !void {
1434+
pub fn loadBuffer(lua: *Lua, buf: []const u8, name: [:0]const u8, mode: Mode) !void {
14401435
const mode_str = switch (mode) {
14411436
.binary => "b",
14421437
.text => "t",
@@ -1450,13 +1445,8 @@ pub const Lua = struct {
14501445
}
14511446
}
14521447

1453-
/// Equivalent to `Lua.loadFileX()` with mode equal to binary+text
1454-
pub fn loadFile(lua: *Lua, file_name: [:0]const u8) !void {
1455-
try lua.loadFileX(file_name, .binary_text);
1456-
}
1457-
14581448
/// Loads a file as a Lua chunk
1459-
pub fn loadFileX(lua: *Lua, file_name: [:0]const u8, mode: Mode) !void {
1449+
pub fn loadFile(lua: *Lua, file_name: [:0]const u8, mode: Mode) !void {
14601450
const mode_str = switch (mode) {
14611451
.binary => "b",
14621452
.text => "t",

src/ziglua-5.3/tests.zig

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,7 +1252,7 @@ test "loadBuffer" {
12521252
var lua = try Lua.init(testing.allocator);
12531253
defer lua.deinit();
12541254

1255-
_ = try lua.loadBuffer("global = 10", "chunkname");
1255+
_ = try lua.loadBuffer("global = 10", "chunkname", .text);
12561256
try lua.protectedCall(0, ziglua.mult_return, 0);
12571257
_ = try lua.getGlobal("global");
12581258
try expectEqual(@as(Integer, 10), try lua.toInteger(-1));
@@ -1431,7 +1431,6 @@ test "refs" {
14311431
// no need to test file loading
14321432
_ = Lua.doFile;
14331433
_ = Lua.loadFile;
1434-
_ = Lua.loadFileX;
14351434

14361435
// probably not needed in ziglua
14371436
_ = Lua.execResult;

src/ziglua-5.4/lib.zig

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,7 +1414,7 @@ pub const Lua = struct {
14141414
/// Loads and runs the given file
14151415
pub fn doFile(lua: *Lua, file_name: [:0]const u8) !void {
14161416
// translate-c failure
1417-
try lua.loadFile(file_name);
1417+
try lua.loadFile(file_name, .binary_text);
14181418
try lua.protectedCall(0, mult_return, 0);
14191419
}
14201420

@@ -1474,13 +1474,8 @@ pub const Lua = struct {
14741474
return c.luaL_len(lua.state, index);
14751475
}
14761476

1477-
/// The same as `Lua.loadBufferX` with `mode` set to binary+text
1478-
pub fn loadBuffer(lua: *Lua, buf: []const u8, name: [:0]const u8) !void {
1479-
try lua.loadBufferX(buf, name, .binary_text);
1480-
}
1481-
14821477
/// Loads a buffer as a Lua chunk
1483-
pub fn loadBufferX(lua: *Lua, buf: []const u8, name: [:0]const u8, mode: Mode) !void {
1478+
pub fn loadBuffer(lua: *Lua, buf: []const u8, name: [:0]const u8, mode: Mode) !void {
14841479
const mode_str = switch (mode) {
14851480
.binary => "b",
14861481
.text => "t",
@@ -1494,13 +1489,8 @@ pub const Lua = struct {
14941489
}
14951490
}
14961491

1497-
/// Equivalent to `Lua.loadFileX()` with mode equal to binary+text
1498-
pub fn loadFile(lua: *Lua, file_name: [:0]const u8) !void {
1499-
try lua.loadFileX(file_name, .binary_text);
1500-
}
1501-
15021492
/// Loads a file as a Lua chunk
1503-
pub fn loadFileX(lua: *Lua, file_name: [:0]const u8, mode: Mode) !void {
1493+
pub fn loadFile(lua: *Lua, file_name: [:0]const u8, mode: Mode) !void {
15041494
const mode_str = switch (mode) {
15051495
.binary => "b",
15061496
.text => "t",

src/ziglua-5.4/tests.zig

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,7 +1333,7 @@ test "loadBuffer" {
13331333
var lua = try Lua.init(testing.allocator);
13341334
defer lua.deinit();
13351335

1336-
_ = try lua.loadBuffer("global = 10", "chunkname");
1336+
_ = try lua.loadBuffer("global = 10", "chunkname", .text);
13371337
try lua.protectedCall(0, ziglua.mult_return, 0);
13381338
_ = try lua.getGlobal("global");
13391339
try expectEqual(@as(Integer, 10), try lua.toInteger(-1));
@@ -1522,7 +1522,6 @@ test "refs" {
15221522
// no need to test file loading
15231523
_ = Lua.doFile;
15241524
_ = Lua.loadFile;
1525-
_ = Lua.loadFileX;
15261525

15271526
// probably not needed in ziglua
15281527
_ = Lua.execResult;

0 commit comments

Comments
 (0)