jackalcooper

jackalcooper

I am working on a Elixir project compiling Elixir to native code: GitHub - beaver-lodge/charms: NIF, in Elixir, for Elixir · GitHub
To further drive the development of this project. I want to create a game engine binding for Elixir to collect the requirements for the FFI capability of Charms.
Some criteria I can think of:

  • it is in C or Zig, for the simplicity
  • the artifacts of the engine itself should be small. ideally smaller the Erlang runtime (to justify it is being embedded)
  • ideally it is 3D, but if it is super simple 2D is also fine
  • it doesn’t have very special C macro or extended grammar/preprocessing (like Unreal C++)
  • it has good UI framework (so we got a native UI library for Elixir as bonus)

the reason I ask is that I was thinking Godot is going to support embed mode by the end of 2024 but looks like progress has been stalled recently(I might be wrong).

Showing Posts 1 to 4

andyleclair

andyleclair

You could do something simple like raylib. There are some existing projects integrating with it. There are also idiomatic Zig bindings!

infinityfye

infinityfye

Charms looks like a very cool project, I’ll be keeping a closer eye on it.

For a game engine, I think Sokol matches what you are looking for. It’s not exactly a game engine rather than a collection of STB-style (header only) libraries. They are (1) cross platform, and (2) fairly easy to understand and port.
It’s not a complete game engine in the sense that it has a physics engine, or PBR rendering, etc…

Another one that I had explored recently is Gunslinger It has some basic physics utilities as well.

LTheGreats

LTheGreats

The biggest problem with embedding a game engine in the BEAM is that preexisting ones, even embeddable ones, generally have preexisting assumptions about the runtime of your application that don’t mesh too well with BEAM’s. Especially since platforms like macOS (last time I checked) require the main thread to be the only windowing thread. It might make the most sense to have a port that handles windowing and draw calls and convince that with NIFs that do related computations in the BEAM.

jackalcooper

jackalcooper OP

So this doesn’t work

defmodule WinRaylib do
  use Charms

  defbind init_window_wrapper() :: i32()

  defm init_window(env) :: i32() do
    init_window_wrapper()
  end

  def dynamic_libraries() do
    so = Path.join(System.tmp_dir!(), "raylib_test.so")

    {_, 0} =
      System.cmd("cc", [
        "-shared",
        "-fPIC",
        "-o",
        so,
        "test/support/raylib_test.c",
        "-I/opt/homebrew/include",
        "-L/opt/homebrew/lib",
        "-lraylib"
      ])

    [so]
  end
end
#include "raylib.h"

int _mlir_ciface_Elixir$RaylibTest$ScreenWidthTest$init_window_wrapper() {
    int width, height;
    if (GetScreenWidth() > 0 && GetScreenHeight() > 0) {
        width = GetScreenWidth();
        height = GetScreenHeight();
    } else {
        width = 800;
        height = 600;
    }
    const char *title = "Test Window";
    TraceLog(LOG_INFO, "Initializing window: %dx%d, title: %s", width, height, title);
    InitWindow(width, height, title);
    TraceLog(LOG_INFO, "Window initialized - IsWindowReady: %d", IsWindowReady());

    if (IsWindowReady()) {
        TraceLog(LOG_INFO, "Entering window loop");
        // Keep window open until ESC pressed
        while (!WindowShouldClose()) {
            TraceLog(LOG_DEBUG, "Window loop iteration");
            BeginDrawing();
            ClearBackground(RAYWHITE);
            DrawText("Test Window Open", 20, 20, 20, DARKGRAY);
            EndDrawing();
        }
    }

    return IsWindowReady();
}

void close_window(void) {
    CloseWindow();
}
Running ExUnit with seed: 20931, max_cases: 16

.........................................INFO: Initializing window: 800x600, title: Test Window
INFO: Initializing raylib 5.5
INFO: Platform backend: DESKTOP (GLFW)
INFO: Supported raylib modules:
INFO:     > rcore:..... loaded (mandatory)
INFO:     > rlgl:...... loaded (mandatory)
INFO:     > rshapes:... loaded (optional)
INFO:     > rtextures:. loaded (optional)
INFO:     > rtext:..... loaded (optional)
INFO:     > rmodels:... loaded (optional)
INFO:     > raudio:.... loaded (optional)
— All posts loaded —

Where Next? Top

Trending in Discussions Top

cblavier
Hey there, It’s been more than a year since we started using LiveView as our main UI library and building a whole library of UI componen...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
axelson
Hi there! :wave: @frigidcode and I (but mostly him) have been running an Elixir Book club, we’re almost done with Designing Elixir Syste...
New
achempion
I’ve been using Emacs as my main code editor for more than a two years. It’s a custom build version although I’ve tried doom emacs and sp...
New
budgie
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with. But I don’t use it anymore. Serverless was the promis...
New
jtormey
Lately I’ve been thinking about how to organize components as a LiveView application grows. One of the pain points I’ve found (for myself...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New
georgeguimaraes
Just published claude-code-elixir, a plugin marketplace for Claude Code with Elixir support. These are the plugins I’ve been using for my...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews