@@ -592,7 +592,7 @@ pub const Lua = struct {
592
592
// just like malloc() returns a pointer "which is suitably aligned for any built-in type",
593
593
// the memory allocated by this function should also be aligned for any type that Lua may
594
594
// desire to allocate. use the largest alignment for the target
595
- const allocator_ptr = opaqueCast ( Allocator , data .? );
595
+ const allocator_ptr : * Allocator = @ptrCast ( @alignCast ( data .? ) );
596
596
597
597
if (@as (? [* ]align (alignment ) u8 , @ptrCast (@alignCast (ptr )))) | prev_ptr | {
598
598
const prev_slice = prev_ptr [0.. osize ];
@@ -1266,7 +1266,7 @@ pub const Lua = struct {
1266
1266
// safe to .? because this function throws a Lua error on out of memory
1267
1267
// so the returned pointer should never be null
1268
1268
const ptr = c .lua_newuserdata (lua .state , @sizeOf (T )).? ;
1269
- return opaqueCast ( T , ptr );
1269
+ return @ptrCast ( @alignCast ( ptr ) );
1270
1270
}
1271
1271
1272
1272
/// This function allocates a new userdata of the given type with user_values associated Lua values.
@@ -1276,7 +1276,7 @@ pub const Lua = struct {
1276
1276
// safe to .? because this function throws a Lua error on out of memory
1277
1277
// so the returned pointer should never be null
1278
1278
const ptr = c .lua_newuserdatauv (lua .state , @sizeOf (T ), user_values ).? ;
1279
- return opaqueCast ( T , ptr );
1279
+ return @ptrCast ( @alignCast ( ptr ) );
1280
1280
}
1281
1281
1282
1282
pub const newUserdata = switch (lang ) {
@@ -1313,7 +1313,7 @@ pub const Lua = struct {
1313
1313
// safe to .? because this function throws a Lua error on out of memory
1314
1314
// so the returned pointer should never be null
1315
1315
const ptr = c .lua_newuserdatatagged (lua .state , @sizeOf (T ), tag ).? ;
1316
- return opaqueCast ( T , ptr );
1316
+ return @ptrCast ( @alignCast ( ptr ) );
1317
1317
}
1318
1318
1319
1319
/// Returns the tag of a userdata at the given index
@@ -1334,7 +1334,7 @@ pub const Lua = struct {
1334
1334
// safe to .? because this function throws a Lua error on out of memory
1335
1335
// so the returned pointer should never be null
1336
1336
const ptr = c .lua_newuserdatadtor (lua .state , @sizeOf (T ), @ptrCast (dtor_fn )).? ;
1337
- return opaqueCast ( T , ptr );
1337
+ return @ptrCast ( @alignCast ( ptr ) );
1338
1338
}
1339
1339
1340
1340
/// Pops a key from the stack, and pushes a key-value pair from the table at the given index
@@ -1987,7 +1987,7 @@ pub const Lua = struct {
1987
1987
/// Returns an error if the value is not a userdata.
1988
1988
/// See https://www.lua.org/manual/5.4/manual.html#lua_touserdata
1989
1989
pub fn toUserdata (lua : * Lua , comptime T : type , index : i32 ) ! * T {
1990
- if (c .lua_touserdata (lua .state , index )) | ptr | return opaqueCast ( T , ptr );
1990
+ if (c .lua_touserdata (lua .state , index )) | ptr | return @ptrCast ( @alignCast ( ptr ) );
1991
1991
return error .Fail ;
1992
1992
}
1993
1993
@@ -2007,7 +2007,7 @@ pub const Lua = struct {
2007
2007
}
2008
2008
2009
2009
pub fn toUserdataTagged (lua : * Lua , comptime T : type , index : i32 , tag : i32 ) ! * T {
2010
- if (c .lua_touserdatatagged (lua .state , index , tag )) | ptr | return opaqueCast ( T , ptr );
2010
+ if (c .lua_touserdatatagged (lua .state , index , tag )) | ptr | return @ptrCast ( @alignCast ( ptr ) );
2011
2011
return error .Fail ;
2012
2012
}
2013
2013
@@ -2467,7 +2467,7 @@ pub const Lua = struct {
2467
2467
/// See https://www.lua.org/manual/5.4/manual.html#luaL_checkudata
2468
2468
pub fn checkUserdata (lua : * Lua , comptime T : type , arg : i32 , name : [:0 ]const u8 ) * T {
2469
2469
// the returned pointer will not be null
2470
- return opaqueCast ( T , c .luaL_checkudata (lua .state , arg , name .ptr ).? );
2470
+ return @ptrCast ( @alignCast ( c .luaL_checkudata (lua .state , arg , name .ptr ).? ) );
2471
2471
}
2472
2472
2473
2473
/// Checks whether the function argument `arg` is a userdata of the type `name`
@@ -2858,7 +2858,7 @@ pub const Lua = struct {
2858
2858
/// See https://www.lua.org/manual/5.4/manual.html#luaL_testudata
2859
2859
pub fn testUserdata (lua : * Lua , comptime T : type , arg : i32 , name : [:0 ]const u8 ) ! * T {
2860
2860
if (c .luaL_testudata (lua .state , arg , name .ptr )) | ptr | {
2861
- return opaqueCast ( T , ptr );
2861
+ return @ptrCast ( @alignCast ( ptr ) );
2862
2862
} else return error .Fail ;
2863
2863
}
2864
2864
@@ -3585,12 +3585,6 @@ pub const Buffer = struct {
3585
3585
3586
3586
// Helper functions to make the ziglua API easier to use
3587
3587
3588
- /// Casts the opaque pointer to a pointer of the given type with the proper alignment
3589
- /// Useful for casting pointers from the Lua API like userdata or other data
3590
- pub inline fn opaqueCast (comptime T : type , ptr : * anyopaque ) * T {
3591
- return @ptrCast (@alignCast (ptr ));
3592
- }
3593
-
3594
3588
pub const ZigFn = fn (lua : * Lua ) i32 ;
3595
3589
pub const ZigHookFn = fn (lua : * Lua , event : Event , info : * DebugInfo ) void ;
3596
3590
pub const ZigContFn = fn (lua : * Lua , status : Status , ctx : Context ) i32 ;
0 commit comments