{
  "about": "The import table of SPEC.md 16, the WebAssembly binding: every import a runtime \"wasm\" cart may declare, all from module \"moy\". params and results are wasm value types; wamr is the WAMR NativeSymbol signature string for the same function; spec is the SPEC.md section that defines the import. libmoy/include/moy_cart.h declares the same rows for a C or C++ cart, and libmoy/test/wasm_table_check.py holds the two, the Lua binding and libmoy/src/moy_wasm.c to one another.",
  "module": "moy",
  "imports": [
    {"name": "cls", "params": ["i32"], "results": [], "wamr": "(i)", "spec": "§6", "notes": "cls(c). Lua's default c is 0."},
    {"name": "background", "params": ["i32"], "results": [], "wamr": "(i)", "spec": "§6", "notes": "background(c)."},
    {"name": "view", "params": ["i32", "i32"], "results": [], "wamr": "(ii)", "spec": "§6", "notes": "view(w, h). Lua's defaults are W and H."},
    {"name": "pix", "params": ["i32", "i32", "i32"], "results": ["i32"], "wamr": "(iii)i", "spec": "§6", "notes": "pix(x, y, c). c >= 0 writes and returns 0; c < 0 is Lua's two-argument form and returns the index at x, y (0 off the canvas)."},
    {"name": "line", "params": ["i32", "i32", "i32", "i32", "i32"], "results": [], "wamr": "(iiiii)", "spec": "§6", "notes": "line(x0, y0, x1, y1, c)."},
    {"name": "rect", "params": ["i32", "i32", "i32", "i32", "i32"], "results": [], "wamr": "(iiiii)", "spec": "§6", "notes": "rect(x, y, w, h, c), filled."},
    {"name": "rectb", "params": ["i32", "i32", "i32", "i32", "i32"], "results": [], "wamr": "(iiiii)", "spec": "§6", "notes": "rectb(x, y, w, h, c), outline."},
    {"name": "circ", "params": ["i32", "i32", "i32", "i32"], "results": [], "wamr": "(iiii)", "spec": "§6", "notes": "circ(cx, cy, r, c), filled."},
    {"name": "circb", "params": ["i32", "i32", "i32", "i32"], "results": [], "wamr": "(iiii)", "spec": "§6", "notes": "circb(cx, cy, r, c), outline."},
    {"name": "oval", "params": ["i32", "i32", "i32", "i32", "i32"], "results": [], "wamr": "(iiiii)", "spec": "§6", "notes": "oval(x, y, w, h, c), filled."},
    {"name": "ovalb", "params": ["i32", "i32", "i32", "i32", "i32"], "results": [], "wamr": "(iiiii)", "spec": "§6", "notes": "ovalb(x, y, w, h, c), outline."},
    {"name": "print", "params": ["i32", "i32", "i32", "i32", "i32"], "results": [], "wamr": "(*~iii)", "spec": "§6", "notes": "print(s, len, x, y, c). s is len bytes of linear memory, walked one byte per cell; a compiled cart formats its own numbers."},
    {"name": "camera", "params": ["i32", "i32", "i32"], "results": [], "wamr": "(iii)", "spec": "§6", "notes": "camera(x, y, out). camera() is camera(0, 0). The previous offset, Lua's two results, is written at out as two i32 unless out is 0."},
    {"name": "clip", "params": ["i32", "i32", "i32", "i32"], "results": [], "wamr": "(iiii)", "spec": "§6", "notes": "clip(x, y, w, h). clip() is clip(0, 0, W, H)."},
    {"name": "pal", "params": ["i32", "i32", "i32"], "results": [], "wamr": "(iii)", "spec": "§6", "notes": "pal(c0, c1, p). p = 1 is the screen palette, as in Lua; c0 < 0 is pal() and resets both palettes."},
    {"name": "palt", "params": ["i32", "i32"], "results": [], "wamr": "(ii)", "spec": "§6", "notes": "palt(c, on). c < 0 is palt() and resets."},
    {"name": "fillp", "params": ["i32", "i32"], "results": [], "wamr": "(ii)", "spec": "§6", "notes": "fillp(p, c). fillp() is fillp(0, -1); c < 0 leaves holes untouched."},
    {"name": "make_layer", "params": ["i32", "i32"], "results": ["i32"], "wamr": "(ii)i", "spec": "§6", "notes": "make_layer(w, h). A layer handle, or 0 where Lua returns nil (the host declined). Lua's defaults are W and H. A layer lives until the cart ends."},
    {"name": "draw_layer", "params": ["i32", "i32", "i32"], "results": [], "wamr": "(iii)", "spec": "§6", "notes": "draw_layer(layer, cx, cy). layer is a handle make_layer returned; any other value traps."},
    {"name": "tri", "params": ["i32", "i32", "i32", "i32", "i32", "i32", "i32"], "results": [], "wamr": "(iiiiiii)", "spec": "§6.1", "notes": "tri(x1, y1, x2, y2, x3, y3, c), filled."},
    {"name": "trib", "params": ["i32", "i32", "i32", "i32", "i32", "i32", "i32"], "results": [], "wamr": "(iiiiiii)", "spec": "§6.1", "notes": "trib(x1, y1, x2, y2, x3, y3, c), outline."},
    {"name": "tline", "params": ["i32", "i32", "i32", "i32", "i32", "i32", "i32", "i32", "i32"], "results": [], "wamr": "(iiiiiiiii)", "spec": "§6.1", "notes": "tline(x0, y0, x1, y1, u, v, du, dv, colorkey). u, v, du, dv are 16.16 fixed point; Lua's default colorkey is -1."},
    {"name": "spr", "params": ["i32", "i32", "i32", "i32", "i32", "i32"], "results": [], "wamr": "(iiiiii)", "spec": "§7.1", "notes": "spr(n, x, y, colorkey, scale, flip). Lua's defaults: colorkey -1, scale 1, flip 0."},
    {"name": "sspr", "params": ["i32", "i32", "i32", "i32", "i32", "i32", "i32", "i32", "i32", "i32"], "results": [], "wamr": "(iiiiiiiiii)", "spec": "§7.1", "notes": "sspr(sx, sy, sw, sh, dx, dy, dw, dh, colorkey, flip). Lua's defaults: dw = sw, dh = sh, colorkey -1, flip 0."},
    {"name": "sget", "params": ["i32", "i32"], "results": ["i32"], "wamr": "(ii)i", "spec": "§7.1", "notes": "sget(x, y)."},
    {"name": "sset", "params": ["i32", "i32", "i32"], "results": [], "wamr": "(iii)", "spec": "§7.1", "notes": "sset(x, y, c)."},
    {"name": "fget", "params": ["i32", "i32"], "results": ["i32"], "wamr": "(ii)i", "spec": "§7.1", "notes": "fget(n, b). b < 0 is Lua's fget(n) and returns the flag byte; otherwise 1 or 0 for bit b."},
    {"name": "fset", "params": ["i32", "i32", "i32"], "results": [], "wamr": "(iii)", "spec": "§7.1", "notes": "fset(n, b, v). b < 0 is Lua's fset(n, v) and writes v as the byte; otherwise bit b is set when v is non-zero and cleared when it is 0."},
    {"name": "map", "params": ["i32", "i32", "i32", "i32", "i32", "i32", "i32", "i32", "i32"], "results": [], "wamr": "(iiiiiiiii)", "spec": "§7.2", "notes": "map(mx, my, w, h, sx, sy, colorkey, scale, layers). Lua's w and h default to the map's edge, which a compiled cart passes itself; colorkey -1, scale 1, layers 0."},
    {"name": "mget", "params": ["i32", "i32"], "results": ["i32"], "wamr": "(ii)i", "spec": "§7.2", "notes": "mget(x, y). -1 for an empty cell or out of range."},
    {"name": "mset", "params": ["i32", "i32", "i32"], "results": [], "wamr": "(iii)", "spec": "§7.2", "notes": "mset(x, y, tile)."},
    {"name": "btn", "params": ["i32", "i32"], "results": ["i32"], "wamr": "(ii)i", "spec": "§7.3", "notes": "btn(b, player). b indexes SPEC.md 7.3's buttons in its order -- left 0, right 1, up 2, down 3, a 4, b 5, run 6 -- where Lua passes the name; any other index reads 0. Returns 1 or 0."},
    {"name": "btnp", "params": ["i32", "i32"], "results": ["i32"], "wamr": "(ii)i", "spec": "§7.3", "notes": "btnp(b, player). b as for btn. Returns 1 or 0."},
    {"name": "players", "params": [], "results": ["i32"], "wamr": "()i", "spec": "§7.3", "notes": "players(). Always at least 1."},
    {"name": "touch", "params": ["i32"], "results": ["i32"], "wamr": "(i)i", "spec": "§7.3", "notes": "touch(out). 0 where Lua returns nil (no pointer); otherwise 1, with x, y, tapped, held written at out as four i32 unless out is 0."},
    {"name": "key", "params": ["i32"], "results": ["i32"], "wamr": "(i)i", "spec": "§7.3", "notes": "key(code). code < 0 is key() and returns the last typed code, 0 for none; otherwise 1 or 0."},
    {"name": "keyp", "params": ["i32"], "results": ["i32"], "wamr": "(i)i", "spec": "§7.3", "notes": "keyp(code). code < 0 is keyp() and returns the last typed code, 0 for none; otherwise 1 or 0."},
    {"name": "textmode", "params": ["i32"], "results": [], "wamr": "(i)", "spec": "§7.3", "notes": "textmode(on)."},
    {"name": "sfx", "params": ["i32", "i32"], "results": [], "wamr": "(ii)", "spec": "§8.2", "notes": "sfx(n, chan). Lua's default chan is -1: round-robin."},
    {"name": "music", "params": ["i32", "i32"], "results": [], "wamr": "(ii)", "spec": "§8.2", "notes": "music(track, loop). Lua's default loop is 1."},
    {"name": "music_stop", "params": [], "results": [], "wamr": "()", "spec": "§8.2", "notes": "music_stop()."},
    {"name": "sound_stop", "params": ["i32"], "results": [], "wamr": "(i)", "spec": "§8.2", "notes": "sound_stop(chan). chan < 0 stops every channel, which is Lua's sound_stop()."},
    {"name": "volume", "params": ["i32"], "results": [], "wamr": "(i)", "spec": "§8.2", "notes": "volume(level)."},
    {"name": "beep", "params": ["f32", "f32"], "results": [], "wamr": "(ff)", "spec": "§8.2", "notes": "beep(freq, dur). Lua's default dur is 0.15."},
    {"name": "time", "params": [], "results": ["i32"], "wamr": "()i", "spec": "§9", "notes": "time(). Milliseconds since the cart started: the binding's only clock."},
    {"name": "pmem", "params": ["i32", "i32", "i32"], "results": ["i32"], "wamr": "(iii)i", "spec": "§9", "notes": "pmem(slot, v, write). write 0 is Lua's pmem(slot): returns the slot, v ignored. write 1 is pmem(slot, v): stores v and returns 0."},
    {"name": "cfg", "params": ["i32", "i32", "i32", "i32"], "results": ["i32"], "wamr": "(*~*~)i", "spec": "§9", "notes": "cfg(key, key_len, dst, dst_len). Copies the value's text -- a string without its quotes, a number as config.json spells it -- into dst, at most dst_len bytes, and returns its whole length; -1 where Lua returns the caller's default. Applying a default and parsing a number are the cart's."},
    {"name": "rnd", "params": ["f32"], "results": ["f32"], "wamr": "(f)f", "spec": "§9", "notes": "rnd(n). Lua's default n is 1.0."},
    {"name": "srand", "params": ["i32"], "results": [], "wamr": "(i)", "spec": "§9", "notes": "srand(seed)."},
    {"name": "flr", "params": ["f32"], "results": ["i32"], "wamr": "(f)i", "spec": "§9", "notes": "flr(x)."},
    {"name": "quit", "params": [], "results": [], "wamr": "()", "spec": "§9", "notes": "quit(). Does not return: the host unwinds the cart and ends it as the cart's own choice, not as a trap."},
    {"name": "target", "params": ["i32"], "results": [], "wamr": "(i)", "spec": "§16.4", "notes": "target(layer). The drawing verbs a Lua layer answers as methods (cls pix line rect rectb circ circb oval ovalb print camera clip pal palt fillp spr map tri trib sspr tline) draw into layer from here on; 0 is the screen. Lua's ly:rect(...) is target(ly) rect(...) target(0). The target is the screen whenever the host calls an export; a handle make_layer never returned traps."},
    {"name": "blit", "params": ["i32", "i32"], "results": [], "wamr": "(ii)", "spec": "§16.5", "notes": "blit(frame, pal). frame is W x H bytes of indices, row-major; pal is 0 for the cart's own palette (SPEC.md 2.2, index taken modulo 64) or 768 bytes of RGB, a 256-entry palette for this frame. Writes the whole screen, ignoring camera, clip, both palettes, palt, fillp and the target. Only inside _draw, and at most one blit or blit565 per _draw; anything else traps."},
    {"name": "blit565", "params": ["i32"], "results": [], "wamr": "(i)", "spec": "§16.5", "notes": "blit565(frame). frame is W x H RGB565 words, little-endian, row-major. Otherwise exactly blit's rules."},
    {"name": "read", "params": ["i32", "i32", "i32", "i32", "i32"], "results": ["i32"], "wamr": "(*~i*~)i", "spec": "§9.1", "notes": "read(name, name_len, offset, dst, len), SPEC.md 16.6. Copies up to len bytes of the cart's own file name, from byte offset, into dst and returns how many it copied. With len 0 it copies nothing and returns how many bytes remain from offset. A writable path (SPEC.md 16.12) with a written copy reads that copy; any other name reads the cart's own file. An absent name, a name outside the cart's folder, or an offset past the end reads 0."},
    {"name": "snd", "params": ["i32", "i32"], "results": ["i32"], "wamr": "(ii)i", "spec": "§16.9", "notes": "snd(pcm, n). pcm is n frames of signed 16-bit mono, little-endian, at 22050 Hz. Queues as many as the host has room for and returns how many; with n 0 it reads nothing and returns the room. The host holds at most 2048 frames its output has not yet taken, and a host with no audio drains them at the rate and drops them. A range outside linear memory traps."},
    {"name": "par", "params": ["i32", "i32", "i32", "i32"], "results": [], "wamr": "(iiii)", "spec": "§16.10", "notes": "par(n, arg, stacks, size). Runs the cart's _par(i, arg) export for every i in [0, n), across the host's cores or one after another on one, and returns when all have. Item i runs with the cart's __stack_pointer at stacks + (i + 1) * size, which the host puts back after. stacks and size are multiples of 16 and the n * size bytes from stacks lie in linear memory, or it traps. An item calls no import (one that does traps), writes nothing another item reads or writes, and uses no mutable global but its stack pointer. A trap in an item traps par with the lowest trapping item's message."},
    {"name": "write", "params": ["i32", "i32", "i32", "i32"], "results": ["i32"], "wamr": "(*~*~)i", "spec": "§9.1", "notes": "write(path, path_len, data, len), SPEC.md 16.12. Replaces the cart's written copy of path with the len bytes at data, atomically -- the old copy stays whole until the new one is -- and kept when it returns. path is one the manifest's \"writable\" declares, at most 64 bytes, under read's path rule. 0; -1 when path is malformed or not writable; -2 when the host has no room for it, or len is over 1048576; -3 when the host's storage failed."},
    {"name": "erase", "params": ["i32", "i32"], "results": ["i32"], "wamr": "(*~)i", "spec": "§9.1", "notes": "erase(path, path_len). Removes the cart's written copy of path, so read answers the file in the cart's folder again, or nothing. 0; -1 when there is no written copy or path is not writable."},
    {"name": "list", "params": ["i32", "i32", "i32", "i32", "i32"], "results": ["i32"], "wamr": "(*~i*~)i", "spec": "§9.1", "notes": "list(prefix, prefix_len, index, dst, dst_len). The index-th path, counting from 0 in bytewise order, of the cart's files that begin with the bytes of prefix -- every file in its folder and every written one, a path that is both counted once -- copied into dst, at most dst_len bytes, and its whole length; -1 past the last. The order holds while no file changes."}
  ]
}
