Share your Programming Language Jam submissions here!

← Back to all posts
Nelua
h
edubart (7)

Nelua

Nelua is a language that I've wished after years making game engines in C/C++/Lua. It's my take on making a language that is compiled, efficient and simple with Lua syntax and semantics. It compiles first to C then to native code. You could think of it as a "better C" with a Lua syntax/goodies and type notations, but it's much more. Nelua is influenced by Nim, Odin and Zig languages, all of them tries to be a "better C", so does Nelua, but with a Lua flavor.

Quick Example

-- 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)

This program will print the factorial of 5.

About it

In short Nelua is a minimal, simple, efficient, statically typed, compiled, meta programmable, safe and extensible systems programming language with a Lua flavor. It uses ahead of time compilation to compile to native code. Nelua stands for Native Extensible Lua.

For more details check the website nelua.io and the GitHub page, give a star if you find it interesting!
To get an overview of the language syntax and features by example, check the overview page.

Try it in REPL.it

You can try Nelua on the REPL.it here.
There are many examples in the examples and tests folder that you can run like nelua examples/condots.nelua (this one is graphical and it will open X11) inside REPL.it.

To learn about the language features the examples/overview.nelua is the most interesting to run and you can follow it along the overview page.

Complete Examples

Here are some small games made in pure Nelua, all of them you can play in the browser and check the sources!
https://edubart.github.io/nelua-tetris/ - Tetris game
https://edubart.github.io/nelua-game2048/ - Clone of 2048 game
https://github.com/Andre-LA/baixada-game-jam-game - Castle Game - play here

Some other interesting stuff:
https://github.com/Andre-LA/raylib-nelua-mirror - Raylib Bindings
https://github.com/Andre-LA/nprof - Profiler for Raylib
https://github.com/edubart/lunray - Ray Tracer

Internals

Nelua compiler is made in pure Lua, and consists in 4 passes:
1. Use LPEG for parsing all the syntax into an AST
2. Analyze the AST for checking and inferring types
3. Generate C code using the analyzed AST
4. Compile the C code using a C compiler such as GCC/Clang

You will notice some C code in the repository but that's because I've bundled Lua 5.4 interpreter with needed extensions to make easy to install Nelua on REPL or any machine.

One thing interesting about Nelua is that it has a Lua preprocessor with powerful meta programming capabilities that gives full access to the compiler itself while it's compiling and assists specializing efficient static code.

Team

The nelua team:
@edubart - Author of the Language
@AndreLuizLuiz22 - Tester, making libraries and games with it

NOTE: I've been making this language for more than one year, although I've been very active the whole month developing this language and polishing some stuff for the JAM.