How do I convert this GDNative c++ statement `Ref<File> file = File::_new();` to the Godot Module c++ equivalent?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By hidemat

I was able to find the _File class under "core/bind/core_bind.h" and it seems to work for the most part but I don’t know how to write Ref<File> file = File::_new();, which I found on a GDNative plugin, in its Module equivalent.

:bust_in_silhouette: Reply From: hidemat

Oh I actually figured it out. Please correct me if I’m wrong. The call that made it work for me was the following:

Ref<_File>  file = Ref<_File>();
file.instance();

You can simplify it to:

Ref<_File> file;
file.instance();

Although in reality, _File exists only because it is an object wrapper around the real thing. If you write a module, you dont have to use that. You could use the real thing instead:

FileAccessRef f = FileAccess::open(path, FileAccess::READ);

Zylann | 2022-02-22 22:21

Gotcha! Thanks for your help.

hidemat | 2022-02-23 01:35