Files
catscript/tests/repr.cat
T
Minus 7cdf388bf4 object, not table: fix user-facing terminology
The language is OOP with a single compound value, the object (an
anonymous `{...}` or a class instance); it is not Lua and has no
"tables".  The visible type name was already `object`; this fixes the
remaining user-facing wording:

- error messages: "object has no member 'x'", "object is not callable".
- README: drop the "Lua-like" phrasing; describe member objects, not
  tables.
- self-hosted front-end AST node `t="object"` (was "table"), updated
  across parser/compiler/checker.
- test comments/expected output aligned ("object:").

The internal C symbols keep the cat_types_table_* naming convention.
Suite stays 130 green.
2026-11-17 23:14:17 +00:00

28 lines
774 B
Plaintext

-- tests/repr.cat -- the `_repr_` protocol.
--
-- `tostring` and the REPL echo honour a `_repr_` member: a text value is
-- used verbatim, and a callable is invoked with the value as `self`.
-- `tostring` is the display form (text unquoted); the REPL echo is the
-- repr form (text quoted, unless it came from `_repr_`).
local t = {a = 1, b = "x"}
t._repr_ = "a custom point"
class Point
function init(self, x, y)
self.x = x
self.y = y
end
function _repr_(self)
return "Point(" .. tostring(self.x) .. ", " .. tostring(self.y) .. ")"
end
end
local p = Point(3, 4)
print("object:", tostring(t))
print("point:", tostring(p))
print("int:", tostring(42))
print("str:", tostring("hi"))
print("bool:", tostring(true))
print("list:", tostring(attributes(t)))