Files
catscript/std/io/io.cat
T
Minus ef305e7824 std/ tree, use (import) and class syntax
- std/ layout: std/lang/{lexer,parser,checker,compiler}.cat moved from src/catscript
- std/io/io.cat, std/fs/fs.cat, std/math/math.cat modules
- use "path.cat": import another unit (compile+run in the same VM)
- class NAME [extends BASE] ... end: methods, inheritance via __index,
  default new constructor (runs optional init), tables are callable
- examples/classes.cat, tests/std.cat; 48/48 tests
2026-11-16 01:53:53 +00:00

42 lines
811 B
Plaintext

-- std/io/io.cat -- input/output helpers (standard library module).
--
-- Thin, catscript-level conveniences over the C-provided natives.
-- Use: use "std/io/io.cat"
-- Print each argument on its own line.
function print_lines(a)
local i = 1
while i <= len(a) do
print(a[i])
i = i + 1
end
end
-- Join a list's items with a separator, returning one string.
function join(a, sep)
local out = ""
local i = 1
while i <= len(a) do
if i > 1 then
out = out .. sep
end
out = out .. tostring(a[i])
i = i + 1
end
return out
end
-- Read a whole file as text ("" when missing).
function read_text(path)
local s = read_file(path)
if s == nil then
return ""
end
return s
end
-- Write text to a file, returning bytes written.
function write_text(path, text)
return write_file(path, text)
end