update Docs to reflect keyword changes

This commit is contained in:
CPunch 2023-02-10 20:46:05 -06:00 committed by cpunch
parent 8ac8085d20
commit 0a4d36f2f4
5 changed files with 13 additions and 13 deletions

View File

@ -46,8 +46,8 @@ There are two main types of for loops, the traditional c-style for loops, and th
The c-style for loops starts with the `for` keyword, followed by '(' and an initializer, a conditional expression, and an iterator statement each separated by a ';', followed by ')' then the `do` keyword. The loop body is ended by the matching `end` keyword. Like so:
```
var total = 0
for (var i = 0; i < 10; i++) do
let total = 0
for (let i = 0; i < 10; i++) do
total = total + i
end
print(total)

View File

@ -1,6 +1,6 @@
# Introduction
Cosmo is a lightweight embeddable scripting language written in C99. Cosmo has comparable syntax to Lua 5.1, so if you are familiar with that syntax, learning Cosmo should be trivial. Cosmo has eccentric support for object-oriented programming, procedural programming, and functional programming. To see some examples that highlight the syntax, please see the `examples/` directory.
Cosmo is a lightweight embeddable scripting language written in C99. Cosmo has comparable syntax to Lua 5.1, so if you are familiar with that syntax, learning Cosmo should be trivial. To see some examples that highlight the syntax, please see the `examples/` directory.
As Cosmo is an embeddable scripting language, it is designed to be extended by the host program (from here on referenced as 'host'.) Cosmo provides extensive C API for the host to set up the Cosmo VM, modify state, add custom Proto objects, define custom globals and more.

View File

@ -6,17 +6,17 @@ For example, the following is a proto description for a Range Iterator Object, m
```
proto Range
function __init(self, x)
func __init(self, x)
self.max = x
end
// __iter expects an iterable object to be returned (an object with __next defined)
function __iter(self)
func __iter(self)
self.i = 0
return self
end
function __next(self)
func __next(self)
if self.i >= self.max then
return nil // exit iterator loop
end
@ -50,7 +50,7 @@ When an object is called using the `()` operator, `__init` is called and a new O
Objects hold fields, these fields can be grabbed using the '.' operator. Conversely, fields can also be set using the '.' and '=' operators. For example:
```
var object = {
let object = {
field = "Hello world"
}
@ -63,17 +63,17 @@ Objects have two main ways of being declared, first was just shown in the above
```
proto Test
function __init(self)
func __init(self)
// __init is required for an object to be instantiated, the 'self' passed is the
// newly allocated object with it's proto already set
end
function print(self)
func print(self)
print(self)
end
end
var objTest = Test()
let objTest = Test()
// the ':' operator is used to invoke a method. if the '.' operator is used instead, the
// raw closure will be given meaning the 'self' parameter won't be populated

View File

@ -17,8 +17,8 @@
| -------- | ---------------------------- | -------------------------------------- |
| `!` | "Not" logical operator, flips the logical polarity. | `print(!true)` -> `false` |
| `#` | "Count" calls '__count' metamethod on objects or gives the count of entries in tables | `print(#[1,2,3])` -> `3`, `print(#{__count = function(self) return self.x end, x = 1337})` -> `1337` |
| `++` | Increment operator. | `var i = 0 print(++i .. ", " .. i++ .. ", " .. i)` -> `1, 1, 2` |
| `--` | Decrement operator. | `var i = 0 print(--i .. ", " .. i-- .. ", " .. i)` -> `-1, -1, -2` |
| `++` | Increment operator. | `let i = 0 print(++i .. ", " .. i++ .. ", " .. i)` -> `1, 1, 2` |
| `--` | Decrement operator. | `let i = 0 print(--i .. ", " .. i-- .. ", " .. i)` -> `-1, -1, -2` |
| `( ... )` | Call operator. Arguments should be separated using `,`. | `print("Hello", " ", "world!")` -> `Hello world!` |
> -> means 'outputs'

View File

@ -17,5 +17,5 @@ There are two main types of datatypes in Cosmo, primitives and references. Primi
| String | A string of characters | `"ABC"`, `"\x41\x42\x43"`, `"\b1000001\b1000010\b1000011"` |
| Object | A stateful data structure. See `objects.md`. | `{x = 3}`, `proto Test end` |
| Table | A generic data structure. | `[1,2,3]`, `[1 = "hello", "two" = "world"]` |
| Function | A callable routine. | `function() print("Hello world!") end` |
| func | A callable routine. | `function() print("Hello world!") end` |
> There are some other reference datatypes that are used internally, however these will remain undocumented until they are accessible by the user