Nelua Programming Language

Minimal, simple, efficient, statically typed, compiled, metaprogrammable, safe, and extensible systems programming language with a Lua flavor.

Overview Download Try Online

What is Nelua?

Nelua is a systems programming language for performance sensitive applications, like real-time applications and game engines. Its syntax and semantics are similar to Lua, but its garbage collection is optional, it provides optional type notations, and it is free from an interpreter. Nelua uses ahead-of-time compilation to generate optimized native binaries. It is metaprogrammable at compile-time using Lua and it is simple and easy to use.

Read language overview
-- Calculates the factorial of a number.
local function factorial(n: integer): integer
  if n == 0 then
    return 1
  else
    return n * factorial(n - 1)
  end
end

local n = 5
local res = factorial(n)
print(n, 'factorial is', res)
-- Sum numbers from 1 to 10.
local sum = 0
for i = 1, 10 do
  sum = sum + i
end
print('The sum is', sum)
-- Print "hello world" manipulating strings.
require 'string'

local s1 = 'olleh'
local s2 = 'dlrow'

print(s1:reverse() .. ' ' .. s2:reverse())
-- Create and print a record data structure.
require 'string'
local Person = @record{
  name: string,
  age: integer
}
local person: Person = {name = "John", age = 20}
print(person.name, 'is', person.age, 'years old')
Statically typed

Nelua takes advantage of type notations to do type checks at compile time and to generate efficient specialized code. Most of the type notations are optional and the compiler can infer them at compile time.

Efficient

Nelua should be as efficient as C when programming with manual memory management, and more efficient than Lua when using the optional garbage collector.

Simple

Nelua is as simple and intuitive as Lua. Some additions like type notations, efficient data structures, and metaprogramming utilities are available, unlike Lua, but all of them are optional.

Lua flavored

If you know how to code in Lua then you probably know how to code in Nelua. It tries to have the same syntax, semantics, features, and APIs.

Compiled

Nelua takes advantage of ahead-of-time compilation using powerful, optimized C compilers such as GCC or Clang, and thus generates very efficient native code. No interpreter is needed at runtime.

Minimal

Nelua provides mechanisms for implementing features instead of providing a host of features directly in the language. For example, although Nelua is not an object-oriented language, it does provide mechanisms for implementing classes and inheritance efficiently at compile time via metaprogramming.

Safe

Nelua tries to be safe by default for the user by minimizing undefined behavior and doing both compile-time checks and runtime checks.

Low level

Nelua has C-like low level features to allow micro-optimizing parts of the code when needed.

Metaprogrammable

Nelua keeps its host features minimal and provides metaprogramming mechanisms, allowing the semantics to be extended in unconventional ways at compile time. For example, Nelua allows you to create generics, polymorphic functions, and specialized code at compile time using Lua and using the concepts system.

Extensible

Nelua's compiler is written in Lua and is completely modifiable on the fly via the preprocessor, thus you can change the behavior of the compiler at compile time, allowing, for example, direct manipulation of the AST, or even extensions to the language syntax, semantics, or the code generator.

C Compiles to C

Nelua compiles to C first then to native code, thus you can read and debug the generated C code, mix in other C code without costs, create or use C libraries, use C tools, and reuse the generated C code. You can think of Nelua like a "better C" heavily inspired by Lua.

Run anywhere

Nelua has minimal dependencies. This means you can use it for any system where C is available, including the web.

Optional GC

Nelua uses a garbage collector by default, but it is completely optional and can be replaced by manual memory management for predictable runtime performance and for use in real-time applications, such as game engines and operational systems.

Self contained

Nelua does not use external dependencies. Its standard library is written in Nelua and you only need a C compiler to use it.

Installing

Use your terminal to install Nelua

Requires git, build tools, and a C compiler. On Windows you should use MSYS2 with mingw-w64, on Linux you can use GCC, and on MacOS you can use Clang.

Read installation docs
git clone https://github.com/edubart/nelua-lang.git
cd nelua-lang
make install
nelua examples/helloworld.nelua

Why Nelua?

Nelua is being developed by a Lua lover who, after years of using Lua in game projects, wished for a Lua-flavored, efficient, simple language that was powerful at compile time and could replace C/C++ code in game projects. For more information, read the frequently asked questions.

Learn more

Go to the documentation to learn more about Nelua's capabilites and how to use the language.

Read documentation

Open Source

The Nelua compiler is open source and licensed under the MIT license, with most development taking place on GitHub. Be sure to watch the repository to get updates on Nelua's development and star it to show support for the project.

Support Nelua

If you like Nelua, consider contributing in some way! The simplest way would be to give a star on GitHub. You can also try out Nelua and share your experience, report bugs, join the Discord server, spread it to the world, share something created with it, make blog post about it, or even make a donation.