update Docs to reflect keyword changes

This commit is contained in:
CPunch 2023-02-10 20:46:05 -06:00
parent c8cae03604
commit 8e278e3a7d
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: 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 let total = 0
for (var i = 0; i < 10; i++) do for (let i = 0; i < 10; i++) do
total = total + i total = total + i
end end
print(total) print(total)

View File

@ -1,6 +1,6 @@
# Introduction # 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. 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 proto Range
function __init(self, x) func __init(self, x)
self.max = x self.max = x
end end
// __iter expects an iterable object to be returned (an object with __next defined) // __iter expects an iterable object to be returned (an object with __next defined)
function __iter(self) func __iter(self)
self.i = 0 self.i = 0
return self return self
end end
function __next(self) func __next(self)
if self.i >= self.max then if self.i >= self.max then
return nil // exit iterator loop return nil // exit iterator loop
end 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: 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" field = "Hello world"
} }
@ -63,17 +63,17 @@ Objects have two main ways of being declared, first was just shown in the above
``` ```
proto Test proto Test
function __init(self) func __init(self)
// __init is required for an object to be instantiated, the 'self' passed is the // __init is required for an object to be instantiated, the 'self' passed is the
// newly allocated object with it's proto already set // newly allocated object with it's proto already set
end end
function print(self) func print(self)
print(self) print(self)
end end
end end
var objTest = Test() let objTest = Test()
// the ':' operator is used to invoke a method. if the '.' operator is used instead, the // 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 // 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` | | `!` | "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` | | `#` | "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` | | `++` | Increment operator. | `let i = 0 print(++i .. ", " .. i++ .. ", " .. i)` -> `1, 1, 2` |
| `--` | Decrement operator. | `var 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!` | | `( ... )` | Call operator. Arguments should be separated using `,`. | `print("Hello", " ", "world!")` -> `Hello world!` |
> -> means 'outputs' > -> 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"` | | 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` | | 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"]` | | 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 > There are some other reference datatypes that are used internally, however these will remain undocumented until they are accessible by the user