Files
catscript/std/io/io.cat
T
Minus d29b0706c9 remove nil/null: absence is an error, empty object is the only no-value
- delete the nil type; catscript has no nil and no null
- add the empty object (Object with no members), exposed as the global
  'empty'; it is a shared immutable singleton
- 'nil' is no longer a keyword: it is an undefined global, which raises
- undefined global -> error (consistent with a missing attribute)
- only 'false' is falsy (numbers/objects are truthy); booleans kept
- OP_NIL -> OP_EMPTY; compiler, VM, stdlib, toml, ffi, generator, file,
  list, selector, value all migrated
- rename the table type to Object
- std/ front-end and examples/tests migrated to 'empty'
- 84/84 tests
2026-11-16 04:08:24 +00:00

42 lines
813 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 == empty 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