refactor: rename newUserdataUV -> newUserdata
Although Lua 5.4 renamed this function, the old name is fine and more clear
This commit is contained in:
parent
1479dd9311
commit
8e6e6f8084
|
@ -800,7 +800,7 @@ test "userdata and uservalues" {
|
||||||
};
|
};
|
||||||
|
|
||||||
// create a Lua-owned pointer to a Data with 2 associated user values
|
// 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;
|
data.val = 1;
|
||||||
std.mem.copy(u8, &data.code, "abcd");
|
std.mem.copy(u8, &data.code, "abcd");
|
||||||
|
|
||||||
|
@ -1468,7 +1468,7 @@ test "userdata" {
|
||||||
const Type = struct { a: i32, b: f32 };
|
const Type = struct { a: i32, b: f32 };
|
||||||
try lua.newMetatable("Type");
|
try lua.newMetatable("Type");
|
||||||
|
|
||||||
var t = lua.newUserdataUV(Type, 0);
|
var t = lua.newUserdata(Type, 0);
|
||||||
lua.setMetatableAux("Type");
|
lua.setMetatableAux("Type");
|
||||||
t.a = 1234;
|
t.a = 1234;
|
||||||
t.b = 3.14;
|
t.b = 3.14;
|
||||||
|
|
|
@ -695,13 +695,12 @@ pub const Lua = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This function creates and pushes a new full userdata onto the stack
|
/// 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
|
/// Returns the address of the block of memory
|
||||||
/// TODO: rename to newUserdata?
|
pub fn newUserdata(lua: *Lua, comptime T: type, upvalues: i32) *T {
|
||||||
pub fn newUserdataUV(lua: *Lua, comptime T: type, new_uvalue: i32) *T {
|
|
||||||
// safe to .? because this function throws a Lua error on out of memory
|
// safe to .? because this function throws a Lua error on out of memory
|
||||||
// so the returned pointer should never be null
|
// 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);
|
return opaqueCast(T, ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user