# Docs inputs (tools/fixtures.py): the shared files the guide snippets read (tools/docs_check.py), made by reference # tools: a PNG written here (zlib), GIF / JPEG / WebP by ImageMagick, a stereo tone as WAV (Python's wave), FLAC, MP3 # and Ogg Vorbis by ffmpeg with tags. # tests/gen/docs_inputs.luau { files = { [name] = bytes }, vars = { pngBytes = "photo.png", ... } } # tests/gen/docs_files/assets/ the same files, for the snippets that load by path import importlib.util, io, math, os, struct, tempfile, wave, zlib INPUTS = ["tools/docs_check.py"] def docs_check(ctx): spec = importlib.util.spec_from_file_location("docs_check", os.path.join(ctx.root, "tools", "docs_check.py")) m = importlib.util.module_from_spec(spec) spec.loader.exec_module(m) return m def png(w, h, rgba): def chunk(t, d): return struct.pack(">I", len(d)) + t + d + struct.pack(">I", zlib.crc32(t + d) & 0xffffffff) raw = b"".join(b"\0" + rgba[y * w * 4:(y + 1) * w * 4] for y in range(h)) return (b"\x89PNG\r\n\x1a\n" + chunk(b"IHDR", struct.pack(">IIBBBBB", w, h, 8, 6, 0, 0, 0)) + chunk(b"IDAT", zlib.compress(raw, 9)) + chunk(b"IEND", b"")) def photo(w, h): """a gradient with a soft-edged disc: red across, green down, a translucent right edge""" out = bytearray() for y in range(h): for x in range(w): d = math.hypot(x - w / 2, y - h / 2) / (h / 2) out += bytes((x * 255 // (w - 1), y * 255 // (h - 1), 255 if d < 0.6 else 64, 255 if x < w - 8 else 128)) return bytes(out) def tone(rate, seconds, channels=2): n = int(rate * seconds) b = io.BytesIO() with wave.open(b, "wb") as wv: wv.setnchannels(channels) wv.setsampwidth(2) wv.setframerate(rate) frames = bytearray() for i in range(n): env = min(1.0, i / 441, (n - i) / 441) for c in range(channels): f = 440 if c == 0 else 660 frames += struct.pack("