Skip to content

Commit 8e6e6f8

Browse files
committed
refactor: rename newUserdataUV -> newUserdata
Although Lua 5.4 renamed this function, the old name is fine and more clear
1 parent 1479dd9 commit 8e6e6f8

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

src/tests.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ test "userdata and uservalues" {
800800
};
801801

802802
// create a Lua-owned pointer to a Data with 2 associated user values
803-
var data = lua.newUserdataUV(Data, 2);
803+
var data = lua.newUserdata(Data, 2);
804804
data.val = 1;
805805
std.mem.copy(u8, &data.code, "abcd");
806806

@@ -1468,7 +1468,7 @@ test "userdata" {
14681468
const Type = struct { a: i32, b: f32 };
14691469
try lua.newMetatable("Type");
14701470

1471-
var t = lua.newUserdataUV(Type, 0);
1471+
var t = lua.newUserdata(Type, 0);
14721472
lua.setMetatableAux("Type");
14731473
t.a = 1234;
14741474
t.b = 3.14;

src/ziglua.zig

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -695,13 +695,12 @@ pub const Lua = struct {
695695
}
696696

697697
/// This function creates and pushes a new full userdata onto the stack
698-
/// with `num_uvalue` associated Lua values, plus an associated block of raw memory with `size` bytes
698+
/// with `upvalues` associated Lua values, plus an associated block of raw memory with `size` bytes
699699
/// Returns the address of the block of memory
700-
/// TODO: rename to newUserdata?
701-
pub fn newUserdataUV(lua: *Lua, comptime T: type, new_uvalue: i32) *T {
700+
pub fn newUserdata(lua: *Lua, comptime T: type, upvalues: i32) *T {
702701
// safe to .? because this function throws a Lua error on out of memory
703702
// so the returned pointer should never be null
704-
const ptr = c.lua_newuserdatauv(lua.state, @sizeOf(T), new_uvalue).?;
703+
const ptr = c.lua_newuserdatauv(lua.state, @sizeOf(T), upvalues).?;
705704
return opaqueCast(T, ptr);
706705
}
707706

0 commit comments

Comments
 (0)