From 6485f90c2d7b93a9e053db6bbd0554d7dcab6698 Mon Sep 17 00:00:00 2001 From: CPunch Date: Fri, 20 Nov 2020 15:32:12 -0600 Subject: [PATCH] updated README --- README.md | 42 ++++++++++++++++++++++++++++++++++++---- examples/increment.cosmo | 20 +++++++++---------- 2 files changed, 48 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index fb0d3ff..2f99662 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,41 @@ # Cosmo -Cosmo is a portable scripting language loosely based off of Lua. Designed for embeddability, Cosmo will have a built-in C++ wrapper for ease of use for embedding in in C++ applications. +Cosmo is a portable scripting language loosely based off of Lua. Cosmo easily allows the user to extend the language through the use of Proto objects, which describe the behavior of Objects. For example the following is a simple Vector class which describes behavior for a Vector-like object. -# Why Cosmo? -While C++ wrappers for Lua exist (see: SolLua), they're all maintained by outside entitties while Cosmo writes it's own first party wrapper. Additionally, Cosmo is very easily modifiable having been written in clean C99 with well documented code; this makes it a great candidate for early language hackers and researchers alike. +``` +class Vector + function __init(self) + self.vector = {} + self.x = 0 + end -However Cosmo is not just a friendly developer tool, Cosmo's easy syntax and readability makes it a great scripting language for anyone to use. \ No newline at end of file + function __index(self, key) + return self.vector[key] + end + + function push(self, val) + self.vector[self.x++] = val + end + + function pop(self) + return self.vector[--self.x] + end +end + +var vector = Vector() + +for (var i = 0; i < 4; i++) do + vector.push(i) +end + +for (var i = 0; i < 4; i++) do + print(vector.pop() .. " : " .. vector[i]) +end +``` + +> 3 : 0 +> 2 : 1 +> 1 : 2 +> 0 : 3 + +# C API +The Cosmo C API is currently undocumented, however as soon as development has reached a stable state documentation on full language features and the C API will start. \ No newline at end of file diff --git a/examples/increment.cosmo b/examples/increment.cosmo index 81f9dbd..59f9841 100644 --- a/examples/increment.cosmo +++ b/examples/increment.cosmo @@ -1,28 +1,28 @@ -class Stack +class Vector function __init(self) - self.stack = {} + self.vector = {} self.x = 0 end function push(self, val) - self.stack[self.x++] = val + self.vector[self.x++] = val end function pop(self) - return self.stack[--self.x] + return self.vector[--self.x] end function __index(self, key) - return self.stack[key] + return self.vector[key] end end -var stack = Stack() +var vector = Vector() -for (var i = 0; i < 10000; i++) do - stack.push(i) +for (var i = 0; i < 100000; i++) do + vector.push(i) end -for (var i = 0; i < 10000; i++) do - print(stack.pop() .. " : " .. stack[i]) +for (var i = 0; i < 100000; i++) do + print(vector.pop() .. " : " .. vector[i]) end \ No newline at end of file