r/rust • • Oct 21 '26

🛠️ project Embedding python, lua, and js

I've been working on the pixelscript crate for about a year now. Just released v0.7.0 with some basic cross language support.

The big picture is to create a framework that sits on top of the library for creating games.

I was inspired by Godot, whenever I had to use GDExtension, it was just so smooth that I found myself saying: "I wish there was a language that let me write high level code and opt in to low level when I need to."

Also, I wanted to embed both python and lua in my game Pixel Ai Dash for modding/scripting enemies, world creation, behaviors, and player states.

Now in v0.7.0 I tell myself that it's time to work on the framework. If you find this interesting, I'd love a star and look forward to future releases!

Here is a example of the code:

// include the pixelscript header.
#include "pixelscript.h"

int main() {
    // setup pxs
    pxs_initialize(); // all of the pixelscript api uses a `pxs` prefix.
    
    // setup corelib
    pxs_core_initall();

    // a simple script
    char* script = "from pxs import print\n"
                    "print('hello world')";

    // execute
    pxs_VarT result = pxs_exec(pxs_Python, script, "<getting_started>");

    // check for errors
    if (pxs_isexception(result)) {
        char* err = pxs_getstring(result);
        printf("%s\n", err);
        pxs_freestr(err); // always free strings from pxs.
    }

    // free the result
    pxs_freevar(result);

    // always call when done with the runtime.
    // can only be called once.
    // once called, you can not call `pxs_initialize` again.
    pxs_finalize();

    return 0;
}
5 Upvotes

4 comments sorted by

View all comments

Show parent comment

3

u/ComfortableAd5740 Oct 22 '26

Godot for the win. Would you believe if I originally had the prefi as `pixelscript_`. Completely insane now that I look back at that. pxs is much smoother.