Uh oh!
There was an error while loading. Please reload this page.
This repository was archived by the owner on Nov 20, 2020. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnmultiple.lua
More file actions
Latest commit
170 lines (132 loc) · 2.93 KB
/
Copy pathnmultiple.lua
File metadata and controls
170 lines (132 loc) · 2.93 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
--shared_meters = true
keep_ambiguous=true
require'classlib'
functionsay(msg) print(msgand"> " ..msgor"") end
print[[
> class.meter()
> function meter:__init(value)
> print("meter init " .. (value or 'nil'))
> self.value = value or 0
> end
> function meter:set(value)
> self.value = value
> end
> function meter:read()
> print("meter read " .. self.value)
> return self.value
> end
> function meter:which()
> print("meter = " .. tostring(self) .. " { value = " .. self.value .. " }")
> end
> meter.value = -1
]]
class.meter()
functionmeter:__init(value)
print("meter init " .. (valueor'nil'))
self.value=valueor0
end
functionmeter:set(value)
self.value=value
end
functionmeter:read()
print("meter read " ..self.value)
returnself.value
end
functionmeter:which()
print("meter = " ..tostring(self) .." { value = " ..self.value.." }")
end
meter.value=-1
m=shared_metersandshared(meter) ormeter
mm=shared_metersand"shared(meter)" or"meter"
say("class.hygro(" ..mm..")")
class.hygro(m)
print[[
> function hygro:read()
> print("humidity " .. self.meter.value)
> end
]]
functionhygro:read()
print("humidity " ..self.meter.value)
end
say("class.therm(" ..mm..")")
class.therm(m)
print[[
> function therm:read()
> print("temperature " .. self.meter.value)
> end
]]
functiontherm:read()
print("temperature " ..self.meter.value)
end
print[[
> class.hygrotherm(hygro, therm)
> function hygrotherm:read()
> self.hygro:read()
> self.therm:read()
> end
]]
class.hygrotherm(hygro, therm)
functionhygrotherm:read()
self.hygro:read()
self.therm:read()
end
say('ht = hygrotherm(0)')
ht=hygrotherm(0)
say()
say("ht.therm:set(11)")
ht.therm:set(11)
say("ht.therm:read()")
ht.therm:read()
say()
say("ht.hygro:set(22)")
ht.hygro:set(22)
say("ht.hygro:read()")
ht.hygro:read()
say()
say("ht.therm:read()")
ht.therm:read()
say()
say("ht:read()")
ht:read()
say()
say("ht:which()")
status, msg=pcall(ht.which, ht)
ifnotstatusthenprint(msg) end
functionshow(t)
ifnottornott.__typethenprint("Sorry, cannot show " ..tostring(t)) returnend
print('__type', t.__type)
fori, vinpairs(t) do
iftype(i) ~='string' ori:sub(1, 2) ~='__' thenprint(i, v) end
end
end
print()
print("Class attributes:")
print()
print('meter:') show(meter)
print()
print('therm:') show(therm)
print()
print('hygro:') show(hygro)
print()
print('hygrotherm:') show(hygrotherm)
print()
print("ht is a meter = ", ht:is_a(meter))
print("ht is a therm = ", ht:is_a(therm))
print("ht is a hygro = ", ht:is_a(hygro))
print("ht is a hygrotherm = ", ht:is_a(hygrotherm))
print()
print("Object attributes:")
print()
print("ht:") show(ht)
print()
print("ht.hygro:") show(ht.hygro)
print()
print("ht.therm:") show(ht.therm)
print()
print("ht.hygro.meter:") show(ht.hygro.meter)
print()
print("ht.therm.meter:") show(ht.therm.meter)
print()
print("ht.meter:")
status, msg=pcall(show, ht.meter)
ifnotstatusthenprint(msg)end