Next |

The Blade Language Documentation

Welcome! This is the official documentation for Blade 0.0.86.

For the official package manager, test runner and repository server — Nyssa, visit https://nyssa.bladelang.org.

This documentation is a work in progress!

Build Status Gitter License Coverage Status Version


The following code implements a simple backend API that runs on port 3000:

import http

var server = http.server(3000)
server.handle('GET', '/', @(req, res) {
  res.json(req)
})

echo 'Listening on Port 3000...'
server.listen()



What is Blade?

Blade is a modern general-purpose programming language focused on enterprise Web, IoT, and secure application development. Blade offers a comprehensive set of tools and libraries out of the box leading to reduced reliance on third-party packages.

Blade comes equipped with an integrated package management system, simplifying the management of both internal and external dependencies and a self-hostable repository server making it ideal for private organizational and personal use. Its intuitive syntax and gentle learning curve ensure an accessible experience for developers of all skill levels. Leveraging the best features from JavaScript, Python, Ruby, and Dart, Blade provides a familiar and robust ecosystem that enables developers to harness the strengths of these languages effortlessly.

What's interesting about Blade

  • Built-in package manager and repository server: Package management is built into the language module system. Blade also comes with Nyssa. Nyssa is a package manager and self-hosted repository server highly suitable for private use.
  • Zero-dependency full-stack web development: Blade comes with a built-in web server and a rich set of tools and libraries that support it, making it easy to build composable full-stack web applications out of the box:
    • Built-in Model-View-Template (MVT) based HTTP web server.
    • Built-in testing framework.
    • Built-in Object Relation Mapping support — Planned!
    • Built-in support for multiple databases.
    • Built-in web template engine — Wire.
    • Built-in routing library.
    • Built-in mail library with SMTP, IMAP, and POP3 support.
    • Built-in device integrations (such as support for COM/Ports, USB, etc.) — Planned!
    • Built-in cryptography library.
    • Built-in support for media processing (Image, audio, video, etc.) — Planned!
    • And more.
  • Function promotion: A feature of the Blade language that makes it easy to reuse any code from an imported module.
  • Access modifiers: Unlike JavaScript and Python, Blade supports access modifiers for variables, properties, functions, classes, modules, etc.
  • Decorator functions: Decorator functions are a set of class methods in Blade that makes extending the functionality of existing code super easy.
  • Easy to extend with C modules: Blade supports external extensions built in C with a built-in extension compiler via Nyssa. This feature makes it easy to extend language features with C modules.

Showcase of other uses

While Blade focuses on Web and IoT, it is also great for general software development. Below are a few showcases of libraries using Blade for other impressive stuff:

  • jsonrpc: A JSON-RPC library for Blade programming language.
  • tar: Pure Blade library for creating and extracting TAR archives.

Download

Windows   Linux   MacOS  

Since version 0.0.86, Every Blade download/installation comes with nyssa — the official package manager, test runner and repository server for Blade.

  • This downloads only support x86-64 plaforms.
  • Apple M1 devices should install Rosetta 2 to run the downloaded application or install from source.
  • For other platforms, you'll need to install from source (see below for details).

Installing Blade from source

Blade currently supports and have been tested on the Linux, OSX and Windows operating system. To install Blade, you need to have CMake and a C/C++ compiler toolchain/IDE installed on your computer.

For Linux and macOS

If you are on a Unix, OSX or Linux machine, you can use the automated install tool by running the command below in your favorite terminal.

$ bash <(curl https://raw.githubusercontent.com/blade-lang/blade/main/scripts/install.sh)

For Windows

Starting from version 0.0.7, Blade's officially supported compilers for the Windows environment is now the TDM-GCC and WinLibs compiler. The decision to change the official compiler from Visual Studio and MSYS2 to TDM-GCC and WinLibs is to allow a minial configuration effort while installing Blade as well as to allow us to develop Blade faster as trying to be cross-compatible with Visual Studio has proven to slow down the growth of the language and the ecosystem and setting up MSYS2 environment to compile Blade is more work than required for either TDM-GCC or WinLibs.

This also allows us to build valid Blade C extensions on Windows with less hassle. Check out the blade-ext-demo or any of the extension in the packages directory for more info on how to write a valid C extension for Blade.

Important Notice

  1. Only TDM-GCC, WinLibs, MinGW64 and MSVC compiler have been tested and are currently guaranted to build Blade. While other compilers may build it, they are not currently recommended.
  2. For MSVC, a minimum of Windows SDK version 10.0.18362 is recommended. This will be readily available from Visual studio 2017 on Windows 10 and above.

To install Blade with TDM-GCC or WinLibs, install TDM-GCC or WinLibs via the given links. Add TDM-GCC or WinLibs bin directory to your environment path. TDM-GCC also allows you to add to path during its installation.

Dependencies

The following dependencies are required and can be installed via Cygwin or Vcpkg.

  • CMake
  • OpenSSL
  • Curl
  • Libffi

After this, run the following commands from the root of your Blade clone:

git clone https://github.com/blade-lang/blade.git
cd blade
cmake -B . -DCMAKE_MAKE_PROGRAM=mingw32-make -G "Unix Makefiles"
cmake --build .

If your dependencies were installed via Vcpkg, you may need to reference the Vcpkg toolchain. E.g.

git clone https://github.com/blade-lang/blade.git
cd blade
cmake -B . -DCMAKE_MAKE_PROGRAM=mingw32-make -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=PATH_TO_VCKPG\scripts\buildsystems\vcpkg.cmake
cmake --build .

This will build and install Blade into a new directory called blade within the current directory. You can move this directory to any location on your computer.

To make Blade (blade) available from your terminal, you'll need to add the generated blade directory to your computer paths.

See this, this or this Stack overflow questions for information on adding Blade installation directory to path.

For all other platforms

For environments without an autoinstall and the adventurous ones, to install Blade, so far as you can successfully setup git, cmake and one of GCC or Clang based compilers, you can use the following commands to install Blade:

$ git clone https://github.com/blade-lang/blade.git
$ cd blade
$ cmake -B .
$ cmake --build .

See the Windows section above for a list of dependencies.

See BUILDING for more details.

Running the Blade REPL

Blade comes with support for REPL (Read-Evaluate-Print-Loop). The REPL mode is triggered when calling the Blade (blade) executable without any file.

Something like this:

$ blade
Blade 0.0.86 (running on BladeVM 0.1.1), REPL/Interactive mode = ON
Clang 13.0.0, (Build time = Feb  8 2022, 02:47:36)
Type ".exit" to quit or ".credits" for more information
%> echo 'Hello, World'
'Hello, World'
%> 

To exit the loop, simply type .exit and press enter or press the Ctrl+D combination on your keyboard.

We'll be using this mode a lot in this documentation.

Running a Blade script

The blade command can take a file as parameter and execute the file as simply as follows:

$ blade somefilename.b
...

Did you notice how the filename ends with a .b? Blade program files should make use of the .b extension. This is the recommended convention.

It is important to remember that:

While Blade may not enforce the .b extension for all scripts, it is a requirement for a script that is meant to be imported as a module into another program.

Editor Support

For editor support, we recommend Visual Studio Code along with the blade-vscode Extension. Support for more editors are planned and on the way.

Blade CLI options

Blade CLI comes with lots of options to control how Blade runs and how it runs your scripts.

Type:

$ blade -h

to show the CLI options. It should look something like this.

Usage: blade [-[h | c | d | e | v | g | w]] [filename]
   -h       Show this help message.
   -v       Show version string.
   -b arg   Buffer terminal outputs with the given size.
   -d       Print bytecode.
   -e       Print bytecode and exit.
   -g arg   Sets the minimum heap size in kilobytes before the GC
            can start. [Default = 1024 (1mb)]
   -c arg   Runs the give code.
   -w       Show runtime warnings.

This help message will automatically be triggered when you try to use an unsupported switch.

For example, to get the version of Blade installed:

$ blade -v
Blade 0.0.86 (running on BladeVM 0.1.0)

Community

Contributing

We need your help to make Blade great! The Blade community is as friendly and welcoming as possible. All kinds of contributions like pull requests, suggestions, typo fixes in documentation, feature request, bug reports, and others are highly appreciated. Please refer to the Contributing guide for more information.