godot-cpp icon indicating copy to clipboard operation
godot-cpp copied to clipboard

Separate definition of templates to solve the vararg/template issues

Open PapyChacal opened this issue 2 years ago • 1 comments

Hi,

I stumbled upon #802 - I wanted to call Callable::call from GDExtension, but realized all varargs methods were not generated. Digging a bit, I saw that the deeper problem is the circular dependency between Callable and Variant - at least in my tentative. So I went for a classical approach, defining the template methods separately in an .impl file.

This way, at least, it compiles and links properly when I try to use Callable::call in my code. (by including "godot_cpp/variant/callable.impl") But this is a first draft: not clean at all and crashes badly! I just wanted to open the PR already to start discussing the idea itself. If this could be the way to go, I can clean up in the coming days. Please feel welcome to do it if you have time and motivation before I do!

PapyChacal avatar Sep 11 '22 23:09 PapyChacal

Okay, this is still far from clean and not working, but I made a draft for varargs methods argument encoding. If anyone is interested, please check the generated gen/include/godot_cpp/variant.impl and gen/include/godot_cpp/encode.hpp The weird templates in encode.hpp are to mimic bindings_generator.py's get_encoded_arg by the C++ compiler, because it needs to be done when the types Args... are known. They are probably far from correct, but seems to work in some cases including mine (calling Callable::call<Vector3i>). Now it compiles and runs until it hits the 0x00 _method_bindings.method_call of Callable.

PapyChacal avatar Sep 12 '22 15:09 PapyChacal

I made it simpler and working by using Variant for every argument.

I am not sure it could even work with "native pointers", because how would the callee know the pointed type? If it could, please tell me and I will try to implement it.

Either way, this depends on godotengine/godot#65718.

PapyChacal avatar Sep 28 '22 13:09 PapyChacal

I am closing this PR as I see no reaction and I had a good idea to do it with my master branch. I kept my branch safe, feel free to ping me if somebody wants this.

PapyChacal avatar Oct 24 '22 17:10 PapyChacal