blob: 5e6a7c80cbbf145b9b95f623cc72826b2e37ee37 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
-- run like so: luam -lcskin test-cskin.lua
class Named {
def _init(self,name) { -- name for ctor
self.name = name
}
def __tostring(self) { -- metamethod
return self.name
}
}
class Shamed: Named { -- doesn't have to define a ctor
def __tostring(self) {
return "shame on "..self.name
}
}
class Person : Named {
def _init(self,name,age) { -- ctor must call inherited ctor explicitly
Named._init(self,name)
self:set_age(age)
}
def set_age(self,age) { -- plain method
self.age = age;
}
def __tostring(self) {
return Named.__tostring(self)..' age '..self.age
}
}
a = Named 'Alice'
print(a)
b = Shamed 'Job'
print(b)
aa = {|Named(n)| n in {'Johan','Peter','Mary'}}
forall(a in aa) { print(a) }
p = Person ('Bob',12)
print(p)
|