mirror of
https://github.com/CPunch/Cosmo.git
synced 2026-10-23 13:30:05 +00:00
syntax: 'var'->'let' 'function'->'func'
- '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
This commit is contained in:
14
README.md
14
README.md
@@ -5,31 +5,31 @@ Cosmo is a portable scripting language loosely based off of Lua. Cosmo easily al
|
||||
|
||||
```lua
|
||||
proto Vector
|
||||
function __init(self)
|
||||
func __init(self)
|
||||
self.vector = []
|
||||
self.x = 0
|
||||
end
|
||||
|
||||
function __index(self, key)
|
||||
func __index(self, key)
|
||||
return self.vector[key]
|
||||
end
|
||||
|
||||
function push(self, val)
|
||||
func push(self, val)
|
||||
self.vector[self.x++] = val
|
||||
end
|
||||
|
||||
function pop(self)
|
||||
func pop(self)
|
||||
return self.vector[--self.x]
|
||||
end
|
||||
end
|
||||
|
||||
var vector = Vector()
|
||||
let vector = Vector()
|
||||
|
||||
for (var i = 0; i < 4; i++) do
|
||||
for (let i = 0; i < 4; i++) do
|
||||
vector:push(i)
|
||||
end
|
||||
|
||||
for (var i = 0; i < 4; i++) do
|
||||
for (let i = 0; i < 4; i++) do
|
||||
print(vector:pop() .. " : " .. vector[i])
|
||||
end
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user