-
-
Notifications
You must be signed in to change notification settings - Fork 22.5k
Add OS::get_cwd virtual #87789
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Add OS::get_cwd virtual #87789
Conversation
Please generate documentation by running the compiled editor with |
2915e46
to
2f0ea0b
Compare
Do functions that are not registered in the bind_method also need it? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also take a look at our code style guidelines, there are some issues with it.
virtual Error set_cwd(const String &p_cwd); | ||
virtual String get_cwd() const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: neither set_cwd
, not newly added get_cwd
are bound, and therefore it will be accessible only from the engine C++ code (not from GDScript or GDExtension). If you want't it to be accessible, a wrapper should be added to the CoreBind
(OS
is a special case and its methods can't be bound directly).
Here's links to one of such wrappers, for example (OS.get_name
):
Wrapper definition:
Line 175 in 9adb7c7
String get_name() const; |
Wrapper implementation:
Lines 351 to 353 in 9adb7c7
String OS::get_name() const { | |
return ::OS::get_singleton()->get_name(); | |
} |
Wrapper binding:
Line 601 in 9adb7c7
ClassDB::bind_method(D_METHOD("get_name"), &OS::get_name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that set_cwd is not bound, so I don't plan to get_cwd the corresponding one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what's the purpose of adding get_cwd()
if it can't be used from script and not used by the engine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope it will provide an intuitive way to get the current working directory in future engine development, and it will correspond to set_cwd.
Maybe it could also be used to gradually replace the original code that used DirAccess to get the working path?
5abe2ec
to
e8b2343
Compare
Can |
The name comes from another set_cwd method that already exists. I'm not sure if this should be changed |
Oh, then no. |
e8b2343
to
40e0326
Compare
It seems that we get current working directory by creating a DirAccess without path init and use get_current_dir(). It doesn't look intuitive.
In fact, the DirAccess finally calls the cwd getting function of specific platform. This PR move them to the OS::get_cwd virtual.