Skip to content

Conversation

ichordev
Copy link
Contributor

This PR resolves the following issues with the D bindings:

Init.Limits causes compiler error

Methods inside of nested structs didn't put their fully qualified name into the top-level joinFnBinds (only the local name), which failed to compile. This oversight wasn't caught earlier because bgfx didn't have any functions in nested structs until recently.

Memory can't be modified

Memory is always returned as const(Memory)*, which means you can't mutate its data in D because const is transitive.
I fixed this by creating a custom version of alloc and copy which returns a MemoryRef. This MemoryRef will implicitly convert to a const(Memory)*, but also has a data member, which is the data from Memory as a mutable slice (i.e. it's bounds checked).
You'll note that makeRef doesn't get its own special function. This is because the user pointer passed to makeRef is const.
As a side-effect, fakeenum has been renamed to impl because it also contains the original alloc and copy functions.

Formatting

Someone came in and trimmed leading whitespace from every file in the repo at some point, but they didn't change how my binding generation code generates whitespace (instead they edited the auto-generated output even though it says AUTO GENERATED! DO NOT EDIT!), so after bindings-d.lua was re-run a few commits later my bindings had a mixture of trimmed & non-trimmed whitespace. I reverted this change because there is meant to be trailing whitespace, and I've added a line to .editorconfig to make sure nobody accidentally messes it up again.

ReleaseFn's type

ReleaseFn used D's calling convention rather than C++'s. Letting C++ try to call a function with D calling convention would've caused undefined behaviour, so I have changed it to extern(C++). This is a 'breaking change' in that it causes code that compiled before to no longer compile, but that code wouldn't have functioned correctly anyway.

@ichordev ichordev requested a review from bkaradzic as a code owner October 10, 2025 10:45
@bkaradzic bkaradzic merged commit af31da1 into bkaradzic:master Oct 10, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants