You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Presently, the only real way to use templates or generic functions with Godot classes involves always calling is with of Inherits<T> and .clone().upcast() either inside the function (with templates) or prior to function call (if not using templates). A basic example with the current system is something like this:
Ideally, the redefine with .clone().upcast() wouldn't be there. The primary two ways I can see this being implemented is
Either make a sort of WeakGD<T> type to at least avoid the clone. The conversion from &'a Gd<T> to WeakGD<'a, U> could just be a .into() call. Since this is actually a hard cast here, an explicit call seems preferable anyway.
Shift functions in the main impl to their own traits. I'm not sure how godot hands off this info in the json as I haven't quite checked, but I think that's probably the "best" solution for making true templates. It should be possible to make use of supertraiting to imitate the inheritance model. This would avoid any sort of cast, at least for templates.
Both are possibly good for different situations, and don't necessarily solve the same thing. Either could make templating marginally smoother though.
As a proof of concept about a WeakGd<T> type see this repo. It definitely could be made better, but it seems to work as intended.
The text was updated successfully, but these errors were encountered:
Presently, the only real way to use templates or generic functions with Godot classes involves always calling is with of
Inherits<T>
and.clone().upcast()
either inside the function (with templates) or prior to function call (if not using templates). A basic example with the current system is something like this:Ideally, the redefine with
.clone().upcast()
wouldn't be there. The primary two ways I can see this being implemented isWeakGD<T>
type to at least avoid the clone. The conversion from&'a Gd<T>
toWeakGD<'a, U>
could just be a.into()
call. Since this is actually a hard cast here, an explicit call seems preferable anyway.Both are possibly good for different situations, and don't necessarily solve the same thing. Either could make templating marginally smoother though.
As a proof of concept about a
WeakGd<T>
type see this repo. It definitely could be made better, but it seems to work as intended.The text was updated successfully, but these errors were encountered: