Cosmo/examples/getters_setters.cosmo

20 lines
364 B
Plaintext
Raw Normal View History

let object = {
2021-01-13 00:27:29 +00:00
__setter = [
2023-05-29 02:16:30 +00:00
"field1" = func(self, val)
2021-01-13 00:27:29 +00:00
print("setter for field1 called!")
self.x = val
end
],
__getter = [
2023-05-29 02:16:30 +00:00
"field1" = func(self)
2021-01-13 00:27:29 +00:00
print("getter for field1 called!")
return self.x + 1
end
]
}
object.field1 = 1337
print("got field: " .. object.field1)