D bindings: Fix nested struct methods, formatting, and Memory
mutability
#3471
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR resolves the following issues with the D bindings:
Init.Limits
causes compiler errorMethods 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 modifiedMemory
is always returned asconst(Memory)*
, which means you can't mutate its data in D becauseconst
is transitive.I fixed this by creating a custom version of
alloc
andcopy
which returns aMemoryRef
. ThisMemoryRef
will implicitly convert to aconst(Memory)*
, but also has adata
member, which is thedata
fromMemory
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 tomakeRef
isconst
.As a side-effect,
fakeenum
has been renamed toimpl
because it also contains the originalalloc
andcopy
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 afterbindings-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 typeReleaseFn
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 toextern(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.