Integrate with gdrust
macro for easy property and signal exports
#715
Milestone
gdrust
macro for easy property and signal exports
#715
Uh oh!
There was an error while loading. Please reload this page.
I wrote gdrust not thinking it would fit in well here, but it turns out it would. This ticket is for discussing how gdrust fits into this project.
Properties
Properties in gdrust use a very gdscript-like syntax:
In general, I think we should try to keep this syntax as it maps well to Godot's syntax. I discussed some syntax ideas with @toasteater on discord, and there are a few things we should keep in mind:
#[property]
#[property]
, namely the path and accessor hooks:One difference between gdrust and the
#[property]
syntax is the way other information such as default and getters and setters are defined.#[property]
favors grouping them all in one attribute like the example above, whereas gdrust tries to split them into multiple attributes. The reason gdrust splits them is that godot's export documentation defines an "annotation-style" syntax. Export hint information is added as annotation arguments.default
and getters/setters were placed in separate attributes to prevent interfering with godot's syntax. As a result, there are more lines of code, but it is easier to read and we aren't cramming everything in one big attribute. We don't have to bring this togdnative-rust
, but it is worth considering.Things to consider
export_*
,default
,path
,setter
,getter
, etc.)?property
, or is there still a need forproperty
?"or_greater"
and"or_lesser"
not be strings? Parsing a list ofLit
s is easy, but there's no reason they couldn't be keywords:#[export_range(0, 10, 10, or_lesser, or_greater)]
.gdrust
requires all properties to have a default value. This allows us to generate anew
method. This doesn't work in 100% of cases, but I've always found thenew
method annoying, so I added it.Signals
Signals in gdrust are defined with an attribute on a struct:
The syntax was chosen to look like gdscript. You may be wondering why the types are weird; they are required to be (
VariantType
s)[https://docs.rs/gdnative/0.9.3/gdnative/core_types/enum.VariantType.html]. I suppose this is not a hard requirement, but it makes it much easier to export the signal as it requires aVariantType
instead of a generic.Things to consider
VariantType
to a rust type?const
with the signal name. This is good for ensuring anyone emitting on the signal is emitting with the correct name at compile time, but it is a bit of magic.unsafe_functions
A collection of extension functions that make coding easier at the risk of crashing the program. I wasn't asked to include this, but I'm throwing it in for clarity. It sounds like the unsafe nature of these functions means they should not be a part of this library and should maybe live in gdrust. Let me know if there are other opinions.
The text was updated successfully, but these errors were encountered: