-
-
Notifications
You must be signed in to change notification settings - Fork 21.3k
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
Fix GDScript load
with relative path
#66550
Conversation
9a5c3e3
to
fb90101
Compare
Could you add a unit test to the PR? I would hope to merge this PR for the 4.1 release, but time is running out. |
Passes the script reference to all gdscript utility function calls.
fb90101
to
209842c
Compare
@adamscott Added some tests. I don't really have time to figure this stuff out, so if you or another GDScript dev knows more about this, please fix up my commit or attach a diff that fixes this part, if it's urgent to land it. EDIT: I confused |
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.
The PR seems good to me. OK for 4.1!
@@ -229,19 +229,24 @@ struct GDScriptUtilityFunctionsDefinitions { | |||
} | |||
} | |||
|
|||
static inline void load(Variant *r_ret, const Variant **p_args, int p_arg_count, Callable::CallError &r_error) { | |||
static inline void load(Variant *r_ret, const Variant **p_args, int p_arg_count, const Ref<GDScript> p_script, Callable::CallError &r_error) { |
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.
We usually do const Ref<T> &
where suitable, would that work here?
Might it be better to resolve this in the compiler and VM (with a separate opcode to convert relative paths, if the argument is unknown at compile time) than to construct a |
Added the PR to the PRs to review by the GDScript team. |
I do think this is overkill to solve this particular issue. Adding an argument to every function just because one needs it looks like too much. We can discuss other solutions to this. For instance, we could have a second, optional argument to If dynamic is not a necessity, we could detect relative paths at runtime and prepend the script's base directory to it so it becomes an absolute path. I think an opcode as @dalexeev suggested is also too much, but we could generate the logic with a combination of opcodes (it does increase the overhead of calling In any case, I do believe we can find a more localized solution rather than changing all utility functions. |
Note that if the This only affects variable expressions such as |
I'll leave a more optimized implementation to someone who has more experience with GDScript internals. Thanks for the feedback! |
@RedMser Thanks for your contribution nonetheless! |
Supersedes #37324
Fixes #35832
First time touching GDScript internals, hope I didn't mess anything up!
As suggested in a comment in the previous PR, all utility function calls now pass the script reference, which is used for figuring out the absolute path.
Also by using
get_path()
instead ofpath
, this PR supports built-in scripts as well.Open Question:
I'm currently passing the analyzer a
nullptr
script reference. WhileResourceLoader::load(parser->script_path, "Script")
is possible, I don't understand yet what the "benefits" are, since I don't understand the analyzer's purpose beyond type checking.