|
@@ -4,16 +4,18 @@
|
|
|
|
|
|
**Gravity** is a powerful, dynamically typed, lightweight, embeddable programming language written in C without any external dependency (except stdlib). It is a class based concurrent scripting language with a modern <a href="https://github.com/apple/swift">Swift</a> like syntax.
|
|
**Gravity** is a powerful, dynamically typed, lightweight, embeddable programming language written in C without any external dependency (except stdlib). It is a class based concurrent scripting language with a modern <a href="https://github.com/apple/swift">Swift</a> like syntax.
|
|
|
|
|
|
-**Gravity** supports procedural programming, object-oriented programming, functional programming and data-driven programming. Thanks to built-in bind methods it can also be used as a prototype-based programming language.
|
|
|
|
|
|
+**Gravity** supports procedural programming, object-oriented programming, functional programming and data-driven programming. Thanks to built-in bind method it can also be used as a prototype-based programming language.
|
|
|
|
|
|
-## Example
|
|
|
|
|
|
+## How Gravity code looks like
|
|
|
|
|
|
```swift
|
|
```swift
|
|
class Vector {
|
|
class Vector {
|
|
|
|
+ // instance variables
|
|
var x=0;
|
|
var x=0;
|
|
var y=0;
|
|
var y=0;
|
|
var z=0;
|
|
var z=0;
|
|
|
|
|
|
|
|
+ // constructor
|
|
func init (a, b, c) {
|
|
func init (a, b, c) {
|
|
if (!a) a = 0;
|
|
if (!a) a = 0;
|
|
if (!b) b = 0;
|
|
if (!b) b = 0;
|
|
@@ -21,26 +23,33 @@ class Vector {
|
|
x = a; y = b; z = c;
|
|
x = a; y = b; z = c;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // instance method (built-in operator overriding)
|
|
func + (v) {
|
|
func + (v) {
|
|
if (v isa Int) return Vector(x+v, y+v, z+v);
|
|
if (v isa Int) return Vector(x+v, y+v, z+v);
|
|
else if (v isa Vector) return Vector(x+v.x, y+v.y, z+v.z);
|
|
else if (v isa Vector) return Vector(x+v.x, y+v.y, z+v.z);
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ // instance method (built-in String conversion overriding)
|
|
func String() {
|
|
func String() {
|
|
return "[" + x.String() + "," + y.String() + "," + z.String() + "]";
|
|
return "[" + x.String() + "," + y.String() + "," + z.String() + "]";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
func main() {
|
|
func main() {
|
|
- var v1 = Vector(1,2,3);
|
|
|
|
- var v2 = Vector(4,5,6);
|
|
|
|
- var v3 = v1 + v2;
|
|
|
|
- return v3.String();
|
|
|
|
|
|
+ // initialize a new vector object
|
|
|
|
+ var v1 = Vector(1,2,3);
|
|
|
|
+ // initialize a new vector object
|
|
|
|
+ var v2 = Vector(4,5,6);
|
|
|
|
+ // call + function in the vector object
|
|
|
|
+ var v3 = v1 + v2;
|
|
|
|
+ // returns string "[5,7,9]"
|
|
|
|
+ return v3.String();
|
|
}
|
|
}
|
|
```
|
|
```
|
|
|
|
|
|
## Features
|
|
## Features
|
|
|
|
+* multipass compiler
|
|
* dynamic typing
|
|
* dynamic typing
|
|
* classes and inheritance
|
|
* classes and inheritance
|
|
* higher order functions and classes
|
|
* higher order functions and classes
|
|
@@ -53,6 +62,9 @@ func main() {
|
|
* built-in unit test
|
|
* built-in unit test
|
|
* built-in JSON serializer/deserializer
|
|
* built-in JSON serializer/deserializer
|
|
|
|
|
|
|
|
+## Credits
|
|
|
|
+**Gravity** has been developed from scratch for the <a href="http://creolabs.com" target="_blank">Creo</a> project in order to offer an easy way to write portable code for the iOS and Android platforms. For closures implementation inspirations come from the excellent <a href="http://www.lua.org" target="_blank">Lua</a> programming language. For fibers and some portions of the garbage collector my gratitude should come to <a href="http://journal.stuffwithstuff.com" target="_blank">Bob Nystrom</a> and his excellent <a href="https://github.com/munificent/wren">Wren</a> programming language.
|
|
|
|
+
|
|
## Documentation
|
|
## Documentation
|
|
|
|
|
|
## Author
|
|
## Author
|