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.
36 lines
964 B
Plaintext
36 lines
964 B
Plaintext
-- tests/selectors.cat -- the a.b / a::b selector syntax.
|
|
--
|
|
-- a.b -- read the member `b` of `a`
|
|
-- a.b(args) -- call member `b` WITH `a` as self
|
|
-- a::b -- static read (no self)
|
|
-- a::b(args) -- call `b` WITHOUT self
|
|
--
|
|
-- `a:b` is gone.
|
|
|
|
local counter = { n = 0 }
|
|
counter.bump = function(self, by)
|
|
self.n = self.n + by
|
|
return self.n
|
|
end
|
|
|
|
counter.bump(3)
|
|
counter.bump(4)
|
|
print("with self:", counter.n)
|
|
|
|
-- a plain object field
|
|
local point = { x = 10, y = 20 }
|
|
print("field x:", point.x)
|
|
|
|
-- static access: no receiver is passed
|
|
local util = { twice = function(x) return x * 2 end }
|
|
print("static:", util::twice(21))
|
|
|
|
-- method vs static on the same member
|
|
local obj = { val = "obj" }
|
|
obj.who = function(self) return "self=" .. self.val end
|
|
print(obj.who())
|
|
|
|
-- static form passes no receiver: the first arg is the real first arg
|
|
local math2 = { add = function(a, b) return a + b end }
|
|
print("static no self:", math2::add(2, 3))
|