-- 07: inout Image parameters mutate the caller's cdata in place, and the -- wrapper returns that same object so the GC sees exactly one owner. local M = dofile("tests/helpers.lua") local R = M.load() M.reset() local b = M.snapshot() local rgba = R.PIXELFORMAT_UNCOMPRESSED_R8G8B8A8 local gray = R.PIXELFORMAT_UNCOMPRESSED_GRAYSCALE local img = R.GenImageColor(4, 4, R.RED) M.eq(img.format, rgba, "GenImageColor produced RGBA") local out = R.ImageFormat(img, gray) M.ok(rawequal(out, img), "ImageFormat returned the caller's cdata") M.eq(img.format, gray, "ImageFormat mutated the cdata") img = nil out = nil M.gc(3) M.eq(M.delta(b, "released"), 1, "ImageFormat did not create a second owner") M.eq(M.delta(b, "errors"), 0, "no finalizer errors") local img2 = R.GenImageColor(4, 4, R.RED) local resized = R.ImageResize(img2, 2, 2) M.ok(rawequal(resized, img2), "ImageResize returned the caller's cdata") M.eq(img2.width, 2, "ImageResize width") M.eq(img2.height, 2, "ImageResize height") img2 = nil resized = nil M.gc(3) M.eq(M.delta(b, "released"), 2, "ImageResize did not create a second owner") M.eq(M.delta(b, "errors"), 0, "no finalizer errors after resize") print("ok 07_inout")