Cosmo/examples/increment.cosmo

38 lines
594 B
Plaintext
Raw Normal View History

2020-12-05 23:58:56 +00:00
proto Vector
2020-11-20 21:10:49 +00:00
function __init(self)
2021-01-09 05:07:44 +00:00
self.vector = []
2020-11-20 21:10:49 +00:00
self.x = 0
end
function push(self, val)
2020-11-20 21:32:12 +00:00
self.vector[self.x++] = val
2020-11-20 21:10:49 +00:00
end
function pop(self)
2020-11-20 21:32:12 +00:00
return self.vector[--self.x]
2020-11-20 21:10:49 +00:00
end
function __index(self, key)
2020-11-20 21:32:12 +00:00
return self.vector[key]
2020-11-20 21:10:49 +00:00
end
function __iter(self)
self.iterIndex = 0
return self
end
function __next(self)
2021-01-10 19:20:09 +00:00
return self.vector[self.iterIndex++]
end
2020-11-20 21:10:49 +00:00
end
2020-11-20 21:32:12 +00:00
var vector = Vector()
2020-11-20 21:10:49 +00:00
2020-11-20 21:32:12 +00:00
for (var i = 0; i < 100000; i++) do
vector.push(i)
2020-11-20 21:10:49 +00:00
end
for i in vector do
print(i)
2020-11-20 21:10:49 +00:00
end