feat: add daw.lua.common.io -- unified I/O wrapper with injectable handles #16

Closed
opened 2026-05-04 19:42:25 +02:00 by michael · 1 comment
Owner

Goal

Add a unified I/O wrapper to daw-lua-common so no module ever calls
io.* or os.exit() directly. All system I/O goes through one place.

Problem

Currently all DAW programs and modules call io.stderr:write(), print(),
os.exit() etc. directly. When Lua system calls change between versions
(as happened with os.execute in 5.1 vs 5.4), all repos must be searched
and patched. With 80-90 modules planned, this is not acceptable.

Solution

Add daw.lua.common.io with injectable handles for testability:

local dawio = require("daw.lua.common.io")

-- default: uses io.stdout, io.stderr, io.stdin
local out = dawio.new()

-- injectable for tests
local out = dawio.new({
  stdout = mock_stdout,
  stderr = mock_stderr,
  stdin  = mock_stdin,
})

out:write(msg)      -- stdout
out:write_err(msg)  -- stderr
out:read_line()     -- stdin, returns string
out:flush()         -- flush stdout
out:exit(code)      -- os.exit

Acceptance Criteria

  • daw.lua.common.io implemented with new(), write(), write_err(),
    read_line(), flush(), exit()
  • Default handles: io.stdout, io.stderr, io.stdin
  • Handles injectable via opts table (for testing)
  • Tests covering default and injected handles
  • All existing daw-lua-common modules updated to use it where applicable

References

  • DAW/daw-modul-berhtjan-cli (blocked on this)
  • DAW/openbookregister (commands/*.lua -- migration candidate)
  • DAW/steurjan (commands/*.lua -- migration candidate)
## Goal Add a unified I/O wrapper to daw-lua-common so no module ever calls io.* or os.exit() directly. All system I/O goes through one place. ## Problem Currently all DAW programs and modules call io.stderr:write(), print(), os.exit() etc. directly. When Lua system calls change between versions (as happened with os.execute in 5.1 vs 5.4), all repos must be searched and patched. With 80-90 modules planned, this is not acceptable. ## Solution Add `daw.lua.common.io` with injectable handles for testability: ```lua local dawio = require("daw.lua.common.io") -- default: uses io.stdout, io.stderr, io.stdin local out = dawio.new() -- injectable for tests local out = dawio.new({ stdout = mock_stdout, stderr = mock_stderr, stdin = mock_stdin, }) out:write(msg) -- stdout out:write_err(msg) -- stderr out:read_line() -- stdin, returns string out:flush() -- flush stdout out:exit(code) -- os.exit ``` ## Acceptance Criteria - [ ] daw.lua.common.io implemented with new(), write(), write_err(), read_line(), flush(), exit() - [ ] Default handles: io.stdout, io.stderr, io.stdin - [ ] Handles injectable via opts table (for testing) - [ ] Tests covering default and injected handles - [ ] All existing daw-lua-common modules updated to use it where applicable ## References - DAW/daw-modul-berhtjan-cli (blocked on this) - DAW/openbookregister (commands/*.lua -- migration candidate) - DAW/steurjan (commands/*.lua -- migration candidate)
Author
Owner

Implemented as daw.common.sys (not a separate daw.lua.common.io module -- title predates the daw.lua.common -> daw.common namespace migration, DAW/daw-lua-common#30). All acceptance criteria met: new(), write(), write_raw(), write_err(), read_line(), flush(), exit(), plus run()/run_rc() beyond the original scope. Default handles io.stdout/io.stderr/io.stdin, injectable via opts table. Covered in test_sys.lua.

Implemented as daw.common.sys (not a separate daw.lua.common.io module -- title predates the daw.lua.common -> daw.common namespace migration, DAW/daw-lua-common#30). All acceptance criteria met: new(), write(), write_raw(), write_err(), read_line(), flush(), exit(), plus run()/run_rc() beyond the original scope. Default handles io.stdout/io.stderr/io.stdin, injectable via opts table. Covered in test_sys.lua.
michael 2026-07-19 17:55:53 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
DAW/daw-lua-common#16
No description provided.