pub type lua_Alloc = extern "C-unwind" fn(ud: *mut c_void, ptr: *mut c_void, osize: usize, nsize: usize) -> *mut c_void;Expand description
The type of the memory allocator function used by Luau’s VM.
udis the same userdata pointer as was passed tolua_newstate.ptris the pointer to the memory block to be reallocated, or null if osize is zero.osizeis the size of the memory block pointed to byptr.nsizeis the new size of the memory block to be allocated.
If osize is zero, ptr will be null and the function should allocate a
new memory block of size nsize.
If nsize is zero, the function should free the memory block pointed to be
ptr.
If osize and nsize are both non-zero, the function should reallocate the
memory block pointed to by ptr to the new size nsize.
§Example
extern "C-unwind" fn alloc(
ud: *mut c_void,
ptr: *mut c_void,
osize: usize,
nsize: usize
) -> *mut c_void {
if nsize == 0 {
unsafe { libc::free(ptr) };
std::ptr::null_mut()
} else {
unsafe { libc::realloc(ptr, nsize) }
}
}