Description
As of writing (7d4ab54
), the InitHandle
type now contains a staggering amount of publicly visible variants of the add_class
method:
add_class
add_class_with
add_tool_class
add_tool_class_with
add_class_as
add_class_as_with
add_tool_class_as
add_tool_class_as_with
It would look much nicer if we can somehow reverse the control flow and reduce this to just a single entry point returning ClassBuilder
, which then expose methods to rename and customize the type being registered naturally. It would however mean a departure from our current model of forwarding calls one-by-one to Godot as they happen, which has consequences that could be deemed good or bad depending on how one looks at it:
- This would give us a chance to look at the whole definition of a class at runtime before actually registering it to Godot, which we might be able to use to do some potentially useful things, including but not limited to:
- Modify certain methods like
_ready
to insert code, generating one if not provided by the user. - Remove the need for
#[no_constructor]
completely, since theadd_class
call would no longer need to know immediately whether there is a default constructor or not. - Automatically generating
get_{}
andset_{}
methods for properties from their accessors, if not provided by the user.
- Modify certain methods like
- On the other hand, it would obviously increase internal complexity by some amount, and it would probably make init slower -- however unlikely that is to matter.
Depending on how we do this the final implementation does not necessarily have to be breaking, although the implementation complexity would probably be lower if we remove the ability to use ClassBuilder
with a shared reference (and thus break any registration functions that are manually written).