Cosmo/examples/increment.cosmo

28 lines
481 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)
2020-11-20 21:32:12 +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
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
2020-11-20 21:32:12 +00:00
for (var i = 0; i < 100000; i++) do
print(vector.pop() .. " : " .. vector[i])
2020-11-20 21:10:49 +00:00
end