You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Marco Bambini a135732f5b Fixed a setter issue that affects some unit tests too 5 days ago
.github/workflows Create codeql-analysis.yml 10 months ago
api Fix api example 7 months ago
binding Update 6 months ago
docs Add constructor and destructor to class documentation 2 months ago
examples Added code to show how to expose a C++ property 2 months ago
gravity.xcodeproj Added ObjC binding example 6 months ago
gravity_visualstudio Updated Visual Studio to version 2019 4 months ago
src Fixed a setter issue that affects some unit tests too 5 days ago
test Add unit test run to the CI 5 days ago
.gitattributes Update .gitattributes 4 years ago
.gitignore Added code to show how to expose a C++ property 2 months ago
.travis.yml Add unit test run to the CI 5 days ago
CMakeLists.txt cmake: Add BUILD_CLI option 9 months ago Fixed a Spelling mistake and MD syntax 4 years ago
CONTRIBUTORS Added my(Matan Silver) email to the contributors file 4 years ago
LICENSE Initial commit 4 years ago
Makefile Build shared object on BSDs; remove unneeded WITH_GETLINE. 3 weeks ago Update Travis CI badge 5 days ago Added documentation for the import statement. 4 years ago

Build Status

Gravity Programming Language

Gravity is a powerful, dynamically typed, lightweight, embeddable programming language written in C without any external dependencies (except for stdlib). It is a class-based concurrent scripting language with modern Swift-like syntax.

Gravity supports procedural programming, object-oriented programming, functional programming, and data-driven programming. Thanks to special built-in methods, it can also be used as a prototype-based programming language.

Gravity has been developed from scratch for the Creo project in order to offer an easy way to write portable code for the iOS and Android platforms. It is written in portable C code that can be compiled on any platform using a C99 compiler. The VM code is about 4K lines long, the multipass compiler code is about 7K lines and the shared code is about 3K lines long. The compiler and virtual machine combined add less than 200KB to the executable on a 64-bit system.

What Gravity code looks like

class Vector {
	// instance variables
	var x = 0;
	var y = 0;
	var z = 0;

	// constructor
	func init (a = 0, b = 0, c = 0) {
		x = a; y = b; z = c;

	// instance method (built-in operator overriding)
	func + (v) {
		if (v is Int) return Vector(x+v, y+v, z+v);
		else if (v is Vector) return Vector(x+v.x, y+v.y, z+v.z);
		return null;

	// instance method (built-in String conversion overriding)
	func String() {
	        // string interpolation support
		return "[\(x),\(y),\(z)]";

func main() {
	// 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 "[1,2,3] + [4,5,6] = [5,7,9]"
    	return "\(v1) + \(v2) = \(v3)";


  • multipass compiler
  • dynamic typing
  • classes and inheritance
  • higher-order functions and classes
  • lexical scoping
  • coroutines (via fibers)
  • nested classes
  • closures
  • garbage collection
  • operator overriding
  • powerful embedding API
  • built-in unit tests
  • built-in JSON serializer/deserializer
  • optional semicolons

Special thanks

Gravity was supported by a couple of open-source projects. The inspiration for closures comes from the elegant Lua programming language; specifically from the document Closures in Lua. For fibers, upvalues handling and some parts of the garbage collector, my gratitude goes to Bob Nystrom and his excellent Wren programming language. A very special thanks should also go to my friend Andrea Donetti who helped me debugging and testing various aspects of the language.


The Getting Started page is a guide for downloading and compiling the language. There is also a more extensive language documentation. Official wiki is used to collect related projects and tools.


Seems like a good idea to make a group chat for people to discuss Gravity.
Join the chat at


Contributions to Gravity are welcomed and encouraged!
More information is available in the official CONTRIBUTING file.


Gravity is available under the permissive MIT license.