refactor: rename newUserdataUV -> newUserdata

Although Lua 5.4 renamed this function, the old name is fine and more
clear
This commit is contained in:
Nathan Craddock 2022-09-17 14:11:42 -06:00
parent 1479dd9311
commit 8e6e6f8084
2 changed files with 5 additions and 6 deletions

View File

@ -800,7 +800,7 @@ test "userdata and uservalues" {
};
// create a Lua-owned pointer to a Data with 2 associated user values
var data = lua.newUserdataUV(Data, 2);
var data = lua.newUserdata(Data, 2);
data.val = 1;
std.mem.copy(u8, &data.code, "abcd");
@ -1468,7 +1468,7 @@ test "userdata" {
const Type = struct { a: i32, b: f32 };
try lua.newMetatable("Type");
var t = lua.newUserdataUV(Type, 0);
var t = lua.newUserdata(Type, 0);
lua.setMetatableAux("Type");
t.a = 1234;
t.b = 3.14;

View File

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