-
Notifications
You must be signed in to change notification settings - Fork 4
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
Nested modules in definitions #64
Comments
I wonder what need to set the root module name is... Since the user can do: import "foo" as xyz;
xyz::some_function();
xyz:;bar::some_inner_function(); That would mean that the root name can be freely changed by the script. Otherwise you'd need to force the user to always do Alternatively, you can keep some form of a mapping dynamically, mapping |
These definitions are only for modules that are already loaded in the engine. By using |
Ah OK. I understand. However, in the examples, I see I wonder what will happen if I change the import to EDIT: Ha! It works just fine! |
It should work as you expect, otherwise file a bug. I made a distinction between modules that are already loaded, and modules introduced by import statements. Using The You can define the following module structure in rust: #[exported_module]
mod foo {
mod bar {
pub fn baz() {}
}
} The only way this can be expressed right now in definition files is the following:
This implies that |
As it looks like module definition files are likely going to be needed only for Rust-based modules, your solution of the |
This only leaves one small issue of inconsistency... Module definition files have their own syntax (sort of), and are used to document Rust-based functions and modules. Rhai scripts will be parsed dynamically and documentation extracted from the scripts. The inconsistency is that, in case that there is a definition file with the same name as a Rhai script, then the doc-comment on its top-most I wonder if there is a way to embed module comments directly into the Rhai script itself to avoid you having to do this. |
Can you give an example? Definitions for scripts and existing modules should never conflict. You can write the following for your script definition:
Then a
The only way for these to conflict is doing
At which point it's either a name conflict, or |
I think I didn't make myself clear. What I mean is... a script file internally has all the documentation, and the only reason why we need a definition file is to provide documentation on the script file itself as a module. Therefore, if I find a way to include module documentation inside the script file itself, then script files should never need definition files as they are self-contained. In that case, we keep all definition files exclusively for use with Rust modules.
In this case, the |
I see, yeah the syntax
You currently need definitions for all type information, I think adding all of this to rhai should come after the definition format is fully tested and fleshed-out. I opened rhaiscript/rhai#488 for type hints, but I don't think it should be rushed as it'd be a significant addition. |
Ah, got that. I see now. There is no way to get rid of definition files (unless I also embed type info into the script). Therefore, mind as well keep the current way of doing things then. It is not simple to add a |
I don't think it's an issue, we can relax it to allow it anyhere and just merge them together, in fact we don't even need the support from Rhai in that case, and I can do it in the rowan-based parser alone. |
That would be the best, I think. Do it in the LSP, and Rhai will continue to treat it as normal comments. |
In that case, the definition files for scripts will be to hold type declarations only. The script file's module doc can be obtained via This looks like a great solution. |
I'll put |
Inspired by your comment, I actually found an easy way to implement In the new version, |
|
Currently it's not possible to define nested modules in definition files.
Nested modules can only come from import statements.
The solution is simple-ish without breaking the existing architecture.
We can define arbitrary modules within a module with the following syntax:
And then we flatten the inner modules and assign unique URIs to them, then treat them as usual afterwards.
The text was updated successfully, but these errors were encountered: