website is under construction
Introduction

Getting Started

What is Ghost?

Ghost is a small scripting language that supports both functional and object-oriented programming. It is designed to be easy to learn, and easy to use.

Installing Ghost

Brew

If you're on Mac, you may use homebrew:

brew tap ghost-language/ghost
brew install ghost-language/ghost/ghost

Go Install

If you have Go installed, you may use go install:

go install ghostlang.org/x/ghost

Direct Download

You may download the compiled binaries for your platform from our GitHub releases page.

Building Ghost

If you're on a Unix or Mac machine, you can easily download the source code and build directly:

git clone https://github.com/ghost-language/ghost
cd ghost
make

This downloads and builds the latest version of Ghost found on GitHub. You will be put inside a fresh instance of ghost if everything was successful.

Running Ghost

Interactive Mode

If you just run ghost without any arguments, it starts the interpreter in interactive mode (aka, REPL mode, read-eval-print loop). You can type in a line of code, and immediately execute it. While in this mode, your state is saved until you exit the program. Meaning if you define a variable, you may reference the variable later on.

$  ghost
   Ghost (0.30.0)
   Press Ctrl + C to exit

>> console.log("Hello, world!")
Hello, world!

Ctrl+C aborts the line you are typing; Ctrl+D ends the session. A line that fails is reported in full and the session carries on.

Running a File

Ghost source files use the .ghost extension. Pass one to ghost and it is executed, then control returns to your terminal.

ghost example.ghost

Anything after the filename is passed through to your script, where os.args() can read it.

Flags

FlagDescription
-hShow help.
-vShow the version and exit.
-tReport how long the program took to run.

A file that fails exits with status 1, so a script's success can be tested from a shell or a build.

Hello, World

Ready to give Ghost a spin?

console.log("Hello, world!")

console.log() is how a Ghost program writes a line of output.

Importing what you use

Ghost's standard library is import-only. Only two names — console and type — are available without an import; everything else is asked for by name:

import "ghost:math"

console.log(math.sqrt(16)) // >> 4

Individual names can be pulled out instead of the whole module:

import { sqrt } from "ghost:math"

console.log(sqrt(16)) // >> 4

Using a module you haven't imported is an error that names the exact import to add, so this is not something you have to memorise. See Modules.

Three rules worth knowing early

Three of Ghost's rules are deliberate, load-bearing, and easiest to learn before you trip over them:

Types are never converted for you. "count: " + 1 is a type error, not "count: 1". Use a template literal`count: ${1}` — to build a string out of mixed types. For the same reason, comparing values of different types with == is an error rather than false.

0 and [] are truthy. Only null, false, and the empty string are falsy — see Truthiness.

and and or do not short-circuit. Both sides are evaluated before the operator is applied, so a test on the left cannot guard the expression on the right.

Once you have Ghost setup and installed, you're ready to jump into learning the language.

Building Games

Ghost also has a 2D game engine, Lumen, which gives it a game loop, a renderer, input, audio, and file access — enough that a whole game can be written in Ghost and nothing else.