Files
catscript/tests/functions_as_objects.cat
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

29 lines
831 B
Plaintext

-- tests/functions_as_objects.cat -- functions are objects too.
--
-- A closure carries a member object, so it can hold `_doc_` (and any
-- other attribute) exactly like an object. `help()` reads it; a dotted
-- assignment can reach an attribute of a nested object (a method).
local t = {x = 1, y = 2}
t._doc_ = "A point."
function add(a, b) return a + b end
add._doc_ = "add(a, b) -- soma dois numeros."
print("call:", add(2, 3))
print("name:", add.name)
print("doc:", add._doc_)
for a in attributes(add) do print("attr:", a) end
-- documenting a method: nested (chained) attribute assignment
class Calc
function add(self, a, b) return a + b end
end
Calc.add._doc_ = "add(a, b) on Calc."
print("method doc:", Calc.add._doc_)
local c = Calc()
print("method call:", c.add(4, 5))
-- help() reads a function's _doc_
help(add)