mirror of
https://github.com/CPunch/Cosmo.git
synced 2024-11-22 07:20:05 +00:00
CPunch
c8cae03604
- 'var' has some weird scoping connotations with users of JS. better to change it to 'let', which will decide whether to make the variable a local or a global - 'func' looks visually appealing lol - some minor refactoring done in cparse.c
39 lines
754 B
Plaintext
39 lines
754 B
Plaintext
proto Vector
|
|
func __init(self)
|
|
self.vector = []
|
|
self.x = 0
|
|
end
|
|
|
|
func push(self, val)
|
|
self.vector[self.x++] = val
|
|
end
|
|
|
|
func pop(self)
|
|
return self.vector[--self.x]
|
|
end
|
|
|
|
func __index(self, key)
|
|
return self.vector[key]
|
|
end
|
|
|
|
func __iter(self)
|
|
// you don't *have* to make a new object, i just wanted to show off anonymous functions
|
|
return {__next = (function(self)
|
|
return self.vector[self.iterIndex++]
|
|
end),
|
|
iterIndex = 0,
|
|
vector = self.vector
|
|
}
|
|
end
|
|
end
|
|
|
|
let vector = Vector()
|
|
|
|
for (let i = 0; i < 100000; i++) do
|
|
vector:push(i)
|
|
end
|
|
|
|
local total = 0
|
|
for i in vector do
|
|
print(i)
|
|
end |