Files
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

55 lines
1.3 KiB
Plaintext

-- examples/cpk.cat -- cpk, the Cat Package Manager.
--
-- This is the first real program written in catscript. cpk reads a
-- package's `package.toml` manifest (every package has one) using the
-- standard library's TOML parser. Commands:
--
-- cpk show [file.toml] -- parse and print a manifest (default: package.toml)
-- cpk new <name> -- print a starter manifest
--
-- Run: catscript examples/cpk.cat show examples/package.toml
function cpk_show(path)
local text = read_file(path)
if text == empty then
print("cpk: cannot read " .. path)
return 1
end
local pkg = toml_parse(text)
print("package: " .. tostring(pkg.name))
print("version: " .. tostring(pkg.version))
print("author: " .. tostring(pkg.author))
return 0
end
function cpk_new(name)
print("# package.toml for " .. name)
print("name = \"" .. name .. "\"")
print("version = \"0.1.0\"")
print("author = \"\"")
return 0
end
function cpk_usage()
print("cpk -- cat package manager")
print("usage: cpk show [file.toml] | cpk new <name>")
return 0
end
function cpk_main(argv)
local cmd = argv[1]
if cmd == "show" then
local path = argv[2]
if path == empty then
path = "package.toml"
end
return cpk_show(path)
elseif cmd == "new" then
return cpk_new(argv[2])
else
return cpk_usage()
end
end
cpk_main({ "show", "examples/package.toml" })