Skip to content
Maximilian Winter edited this page Apr 8, 2022 · 29 revisions

Welcome to the Bite Programming Language wiki!

What is Bite?

Bite (ˈbīt, pronounced the same as the word "byte") is a dynamically-typed object-oriented programming language that syntactically resembles C# and a bit of JavaScript.

The initial goal of Bite is to be a simple runtime scripting language for Unity, or any C# application, and to be able to have access to C# types and objects within the language.

Bite compiles to a bytecode that is run on a virtual machine. The reference virtual machine, BiteVM, is a stack-based virtual machine written in C#.

Getting Started

To try out Bite, you will need to download the BiteVM. It's a command line program that will compile and interpret Bite programs. You can also execute Bite code directly in REPL (Read Eval Print Loop) mode. You can use your favorite editor to create Bite programs, but we have a Visual Studio Code Extension. that gives .bite programs syntax highlighting.

Writing code in Bite

Bite code revolves around modules. To create a module, you define it with the module directive. Then you can start writing code in it!

Create a new file named hello.bite and enter the following code.

module HelloWorld;

// My first Bite program

import System; // required for the PrintLine function

System.PrintLine("Hello World!");

Save the file, then run the program using the command bitevm.exe -i hello.bite. Congratulations, you just wrote and executed your first Bite program!

Variables, Functions, and Classes

A module encapsulates variables, functions, classes, and even code, as we just saw. Let's create a variable and a function and use it to display a message.

module HelloWorld2;

// My second Bite program

import System; // required for the PrintLine function
using System;  // so that we don't have to type System before PrintLine

// declare a function
function SayMessage(message) {
   PrintLine(message);
}

// declare a variable
var hello = "Hello World"; 

// call the function with the variable
SayMessage(hello);

Bite is object-oriented, meaning we can create classes within modules to further manage our code. When creating a class, create a function with the same name as the class to define the constructor.

module HelloWorld2;
import System; 
using System; 

class Notification {
   
   var _counter = 0;
   var _message;
   var _trigger;

   // This is our constructor
   function Notification ( message, trigger ) {
      _message = message;
      _trigger = trigger;
   }

   function Tick() {
      _counter++;
      if ( _counter == _trigger ) {
         PrintLine(message);
      } else {
         PrintLine(_counter);
      }
   }

}

var notify = new Notification( "Work Complete!", 10 ); 

for ( var i = 0; i < 10; i++ ) {
   notify.Tick();
}

More information

Clone this wiki locally