-
-
Notifications
You must be signed in to change notification settings - Fork 223
#[export(file)]
should be limited to certain field types
#772
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
Comments
godotengine/godot#93366 |
i dont see why this issue should be brought up to godot |
Bromeon said that it's issue of Godot that it doesn't notify about incorrect export property |
Sorry about the confusion here, tried to clarify it on the Godot issue. I'm not sure whether Godot performs the same validations for |
|
Won't it support in 4.3? I've seen some information with improvement this part. Maybe I'm wrong, can't find anymore :( |
I don't know -- do you have the time to test your example with a recent 4.3 beta release? |
not really, it requires build |
No need to build -- you can get nightly artifacts from https://github.com/Bromeon/godot4-nightly/actions 🙂 Just click on the latest workflow run, scroll down and select the matching artifact for your platform (e.g. |
#[export(file)]
should be limited to certain field types
@snatvb so it looks like we would need to add validation on godot-rust side. I have an idea how to validate this in a lightweight way. To be clear, I don't want to make the type-system more complex by adding niche traits, or worse, handling at the proc-macro level. I'm very fine with having this validation during startup rather than at compile time. The pub mod export_info_functions {
pub fn export_file<S: AsRef<str>>(filter: S) -> PropertyHintInfo {
...
}
} with #[derive(Clone, Eq, PartialEq, Debug)]
pub struct PropertyHintInfo {
pub hint: PropertyHint,
pub hint_string: GString,
} Now to support this, all export functions could additionally (in a tuple) return a validator function, which would be type ValidateExportType = Box<dyn Fn(&PropertyInfo) -> bool>;
// or:
type RestrictExportType = Option<Box<dyn Fn(&PropertyInfo) -> bool>>; The gdext/godot-core/src/meta/traits.rs Lines 89 to 98 in adcb58d
In this case for example, we could then return: |info| {
info.variant_type == VariantType::STRING // maybe STRING_NAME and NODE_PATH are OK, too
} Should be relatively straightforward to implement. |
@Bromeon as I remember there is issue that I have no option to add file-type for array. If I want to use several resources and take file path - I can't do it. For example it could be textures. When I use |
This is not supported in Godot, see docs and error message in your issue godotengine/godot#93366. So my proposal is to explicitly disallow this in godot-rust, too, in order to provide a meaningful error message. If you want this feature, you'd need to lobby further for it in godotengine/godot#93366 (or maybe create a new one, given that the discussion was now mostly about the GDExtension error capability). |
Not really, I've re-checked the repro case and what I have (use NewScript node): extends Node
class_name NewScript
@export_file("*.txt") var files: Array[String] And what I have rust version node: Sorry I forget and NewScript node to present difference UPD: ah, I think I got it. It doesn't support for GDExentions, right? |
So, I've updated lib version to use godot::prelude::*;
struct RustExtension;
#[gdextension]
unsafe impl ExtensionLibrary for RustExtension {}
#[derive(GodotClass)]
#[class(init, base=Node)]
struct Foo {
base: Base<Node>,
#[export(file = "*.txt")]
resources: Array<GString>,
}
#[godot_api]
impl INode for Foo {} Godot: 4.4.1 and still I see the same issue. But I see your code in PR and can't understand why it doesn't work 🧐 UPD: I've added this: #[export(file = "*.txt")]
export_file_wildcard_parray: PackedStringArray, And got this: |
You should check the pull request I linked, not version 0.2.4. To do this, update the [dependencies]
godot = { git = "https://github.com/godot-rust/gdext", branch = "feature/export-file-arrays" } |
oh, my bad, my bad. I've thought that it's already merged. I apologize. I'll leave it open, and I think you can close it when #1166 is merged :) Many thanks for your work! 🚀✨ |
Thanks a lot for the testing! 👍 Yes, I'll likely merge it for v0.3.1, and close this issue then. |
Uh oh!
There was an error while loading. Please reload this page.
If user tries convert
@export_file("*.txt")
to Array:LSP shows error:


And in console:
But if user does it in rust:
It leads to this:


For user it's unexpected and it would be rather to notify about incorrect annotation.
Reprocase: godot-rust-repro.zip
Discord source conversation
The text was updated successfully, but these errors were encountered: