@@ -21,11 +21,11 @@ const Allocator = std.mem.Allocator;
21
21
/// `osize` is the original size or a code, and `nsize` is the new size
22
22
///
23
23
/// See https://www.lua.org/manual/5.4/manual.html#lua_Alloc for more details
24
- pub const AllocFn = fn (data : ? * anyopaque , ptr : ? * anyopaque , osize : usize , nsize : usize ) callconv (.C ) ? * anyopaque ;
24
+ pub const AllocFn = * const fn (data : ? * anyopaque , ptr : ? * anyopaque , osize : usize , nsize : usize ) callconv (.C ) ? * anyopaque ;
25
25
26
26
/// Type for C functions
27
27
/// See https://www.lua.org/manual/5.4/manual.html#lua_CFunction for the protocol
28
- pub const CFn = fn (state : ? * LuaState ) callconv (.C ) c_int ;
28
+ pub const CFn = * const fn (state : ? * LuaState ) callconv (.C ) c_int ;
29
29
30
30
/// The internal Lua debug structure
31
31
const Debug = c .lua_Debug ;
@@ -109,7 +109,7 @@ pub const FnReg = struct {
109
109
};
110
110
111
111
/// Type for debugging hook functions
112
- pub const CHookFn = fn (state : ? * LuaState , ar : ? * Debug ) callconv (.C ) void ;
112
+ pub const CHookFn = * const fn (state : ? * LuaState , ar : ? * Debug ) callconv (.C ) void ;
113
113
114
114
/// Specifies on which events the hook will be called
115
115
pub const HookMask = packed struct {
@@ -199,7 +199,7 @@ pub const mult_return = c.LUA_MULTRET;
199
199
pub const Number = c .lua_Number ;
200
200
201
201
/// The type of the reader function used by `Lua.load()`
202
- pub const CReaderFn = fn (state : ? * LuaState , data : ? * anyopaque , size : [* c ]usize ) callconv (.C ) [* c ]const u8 ;
202
+ pub const CReaderFn = * const fn (state : ? * LuaState , data : ? * anyopaque , size : [* c ]usize ) callconv (.C ) [* c ]const u8 ;
203
203
204
204
/// The possible status of a call to `Lua.resumeThread`
205
205
pub const ResumeStatus = enum (u1 ) {
@@ -251,7 +251,7 @@ pub const err_file = c.LUA_ERRFILE;
251
251
pub const Stream = c .luaL_Stream ;
252
252
253
253
/// The type of the writer function used by `Lua.dump()`
254
- pub const CWriterFn = fn (state : ? * LuaState , buf : ? * const anyopaque , size : usize , data : ? * anyopaque ) callconv (.C ) c_int ;
254
+ pub const CWriterFn = * const fn (state : ? * LuaState , buf : ? * const anyopaque , size : usize , data : ? * anyopaque ) callconv (.C ) c_int ;
255
255
256
256
/// A Zig wrapper around the Lua C API
257
257
/// Represents a Lua state or thread and contains the entire state of the Lua interpreter
@@ -262,8 +262,6 @@ pub const Lua = struct {
262
262
/// Allows Lua to allocate memory using a Zig allocator passed in via data.
263
263
/// See https://www.lua.org/manual/5.4/manual.html#lua_Alloc for more details
264
264
fn alloc (data : ? * anyopaque , ptr : ? * anyopaque , osize : usize , nsize : usize ) callconv (.C ) ? * anyopaque {
265
- _ = osize ; // unused
266
-
267
265
// just like malloc() returns a pointer "which is suitably aligned for any built-in type",
268
266
// the memory allocated by this function should also be aligned for any type that Lua may
269
267
// desire to allocate. use the largest alignment for the target
@@ -282,6 +280,8 @@ pub const Lua = struct {
282
280
// when nsize is not zero the allocator must behave like realloc
283
281
const new_ptr = allocator .reallocAdvanced (prev_slice , alignment , nsize , .exact ) catch return null ;
284
282
return new_ptr .ptr ;
283
+ } else if (nsize == 0 ) {
284
+ return null ;
285
285
} else {
286
286
// ptr is null, allocate a new block of memory
287
287
const new_ptr = allocator .alignedAlloc (u8 , alignment , nsize ) catch return null ;
0 commit comments