Activity

Omer

I wanna make a cute game to make my fiance cry on her birthday. Happy tears of course!

I’ll use nostalgia and cute things to accomplish that. i’m giving myself till the end of March to get it done. Perfectly matching flavortown’s deadline!

Attachment
0
Omer

My project hit 50 stars and it’s now on google results if you search “raylib go wasm”

Anyways, i’ve generated all the raylib types. Now I need to make a function binding generator. Which is hard 😰.

Attachment
Attachment
0
Omer

I’ve gotten the codegen working. Now i’m going to work on making it backwards compatible with raylib-go. And clean up the codebase a bit.

To make it backwards compatible. Pretty much everything needs to use PascalCase.

Then I will work on writing the actual bindings generator (the hard part) which will let us call raylib functions in web assembly.

Once the WASM part is polished. I intend on auto generating bindings for other platforms too. Like libffi shared libraries. This would allow you to use raylib on linux and mac os without needing a C compiler. We could call raylib functions from a dll. Giving you the full benefit of Go’s fast compile times, with the trade off of a little bit of performance.

Attachment
0
Omer

I’ve successfully written one part of the code generator. Now I can parse raylib’s json that describes it’s API (supplied in the official repo) and generate the structs on the Go side.

This was the easiest part. Now we need to add support for everything else. Macros, aliases, constants, functions, and so much more. Also need to make sure the structs match the C abi properly.

Attachment
0
Omer

Okay, I’ve learned enough about the edge cases, Now time to implement a code generator. Editor macros were really handy for the last part. I was able to focus on improving my custom FFI implementation instead of mindlessly writing bindings.

The improvement included better naming, fixing bugs on the javascript runtime bridge, and adding some more functions for binding use cases.

I was constantly forgetting to free memory on some functions, so I added a 2nd return argument that returns a function to free the memory. The Go compiler forces you to do something about unused varaibles. That was really smart of me, i’m petting myself on the back.

I’ve got a clear idea in my head on how I will implement the code generator. So i’ll start working on that now :P

Attachment
0
Omer

Another fun fact: The Go bindings for raylib didnt have a web export option for a whole decade, I literally spent a whole year learning about web assembly and emscripten to be able to create these bindings. People thought it was impossible to support it https://github.com/gen2brain/raylib-go/issues/69#issuecomment-451955578

So yeah, I can call myself a real engineer now 😋
Anyways, I’ve been implementing the v2 bindings by hand using editor macros to learn about the edge cases, so In the future I can auto generate the bindiings using just a JSON file from the raylib repository, that would be peak ngl.

Attachment
Attachment
0
Omer

I’ve begun the rewrite of my already popular project. Fun fact it’s featured on the OFFICIAL raylib-go repo with 2.2k stars.

I implemented a low level javascript runtime glue thingy that allows Go to call raylib functions more efficiently. Here’s how:

In the previous version Go would have to first copy memory over to Javascript, then Javascript would copy the memory to Raylib. (Go -> JS -> Raylib)

In V2, we control the Go runtime itself.. This allows us to implement functions that directly interact with Go memory. And allow us to copy Go memory directly into Raylib’s memory (Go <-> Raylib)

Using this, I basically created my own easy to use foreign function interface but for webassembly.

Here is a code snippet
// SetWindowTitle - Set title for window (only PLATFORM_DESKTOP)
func SetWindowTitle(title string) {
ptr := cStringFromGoString(title)
defer free(ptr)
setWindowTitle(ptr)
}
cStringFromGoString and free() are functions implemented in JS, they literally just copy the Go string into raylib’s memory using malloc. Controlling the Go runtime allows us to mess directly with the Go stack. We are basically writing assembly glue but instead of assembly, it’s javascript.

I apologize if my explanation doesn’t make sense, I plan on making a full detailed blog post later.

Attachment
0
Omer

I’m working on my first project! This is so exciting. I can’t wait to share more updates as I build.

Attachment
0