-
Notifications
You must be signed in to change notification settings - Fork 3
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
Plugins TODO #38
Comments
Your link has an extra underscore at the end, which does not work. If you edit the text and remove it, then it points to the comment. |
@jhwgh1968 I suggest we make new conversation here. The original issue is getting way too long and sometimes it takes forever to load... |
Alright. I will post a new To-Do list comment right after this, so you can link to it. |
Former To-Do List (edit: everything is done! 🎉 )
Code ExamplesHere are the current top-level code examples from the crate to give an idea of the syntax: Exporting a Module to Rhai
Exporting a Raw Function to Rhai
|
I also updated the code to use |
Yes, |
BTW, I find that errors, especially return type conflicts when use The best way to clean these errors seem to be to copy the module out, remove It would be great if |
This is why I have tried to focus on error handling and diagnostic tests every time I add a new error. You are probably finding the issues I was planning to find with negative testing later. Post examples of all the ones you find, and I will try to fix them. |
The location of the error is pointing to the first character of This error, or something similar, is generated whenever I made a mistake by using For example: Ok(x.into()) will generate this error if the type of Ok(Dynamic::from(x)) solves this problem. |
Ah, I see. I am currently working on a large refactoring (so no plugin changes please!), but I will have a commit in there that makes the error message clearer. |
As @schungx noted:
I think this means I should probably start shaking the trees harder to see what fruit falls. I will start with the |
@jhwgh1968 BTW... is it possible for The code base right now is a bit littered with a number of Since you're doing generating a module, I'm not sure if you can splice it in at the registration call site... |
BTW, just fyi... I rerun the benchmarks and it seems plugins do not have any material impacts. Good news! Still, I would suggest removing the I'll put an item in the TODO... |
Also, I'll start on the plugins documentation. |
Indeed it is! 🎉
The
Unfortunately. no. You should think of macro_rules set_exported_fn! {
(module:$ident, export_name:$literal, fn_path:$path) => {{
macro_let!($generated_module_path = {
let fn_name = module_path.segments.pop();
let rhai_fn_module = format!("rhai_fn_{}", fn_name);
module_path_segments.join(rhai_fn_module);
});
macro_let!($input_types_fn = concat!($generated_module_path, "input_token_types"));
macro_let!($callable_token_fn = concat!($generated_module_path, "token_callable"));
$module.set_fn($export_name, FnAccess::Public,
$input_types_fn().as_ref(), // array of argument types
$callable_token_fn()); // the token implementing PluginFunction
}}
} In other words, it simply navigates to the generated module, and calls the functions defined therein to return the list of arguments and the The only way to get that module generated in its current form requires an
I am hoping that can be cleaned up once I allow including a function in a module "remotely". Then, it should be possible to generate those functions with macros, not tag them as |
BTW, I just merged in the first draft of the Plugins section in the documentation. |
Example of error: macro_rules! gen_cmp_functions {
($($arg_type:ident),+) => {
mod test { $(pub mod $arg_type {
use super::super::*;
#[export_module]
pub mod functions {
#[rhai_fn(name = "<")]
pub fn lt(x: $arg_type, y: $arg_type) -> bool {
x
}
}
})* }
};
}
gen_cmp_functions!(i8);
The same code without |
@jhwgh1968 Actually, I feel that Or leave it on a branch just in case we need to do bug fixes in master. Merge when we're ready to release 0.19.0. |
Hmm... I think that might be the order of how macros are invoked vs procedural macros. I will look into it.
I'd say merge the current branch to master, but keep the branch going a little longer. The merge to master (and then to upstream master) allows us to discover integration issues, and lets other people give feedback on what we have so far. I think it is definitely a "beta version" now, so we should do that. However, I'd still like the
(I'm considering leaving the last one out of the 0.19 release, because it's a bit of a mess right now.) Everything else on the to-do list is fixes or usability improvements (such as the items for extern imports or |
Okay, I am very confused. Checking out the current plugins branch, I get 32 failed doc tests for Rhai if I use the I'll try opening my PR as-is, and see if CI passes anyway... |
Which tests failed? Can you send me a log? |
It seems that You should match the actual function name instead because, if I put a |
You are absolutely right. I went back and forth on this for a while, and without thinking, implemented the wrong way! I will fix it.
Attached is the log of failures on 1.46.0 stable (nightly is very similar if not identical): cargo-test.txt It seems that changing |
Actually, I find that it probably would be more useful to have a
|
Well, module construction should not happen frequently, so it is usually not a bottleneck. Auto-flattening is nice, but not critical. That's because the user can always call I recommend skipping it for now. Instead, auto getters/setters/indexers will be a huge feature. One thing you may consider is that sometimes the same function is used to register multiple Rhai functions. For example, the user may have an Right now, I must define two functions, with one call the other. Some way to automate this? Maybe allowing |
I've put in a PR that supports multiple |
I've added your ID to the Would you like PS I've also removed my name from |
Since my committer full name is a "Nom De Plume" rather than a real name (it's a long story), I think As to the authorship of the |
Do you think |
I would like to go down the checklist one more time, and perhaps discuss one or two of the items. But unless one of those turns into a blocker in your mind, I think it's ready!
Just so it's on the record, our discussion via e-mail ended up here: I'll stay primary author of the |
OK. I take that you mean the |
Correct. |
Sorry, accidentally merged the latest PR. But it looks OK, except for a feature test that I'll fix. |
I think I might have found what went wrong. I did merges on my So if I just delete the branch after merge, and then reopen a new one... as long as I haven't merged that one, I can freely rebase, I suppose. |
Your statement is correct. The workflow is:
That is the workflow I use. The only difference is, I create "feature branches" for one thing at a time, and delete them once they merge. As noted in #58, some stuff did get reverted. I will fix it. |
On second thought, I think you're right. It ended up merged okay. I'll add a second PR for a rustfmt CI job, though. |
If I do a |
It shouldn't. The first step of the rebase command is to figure out where to put it. To see the commit it will decide on, you can run this yourself: If the commit it shows is the tip of the plugins branch, then If you do a rebase onto a branch which is ahead, it will point to the head of your current branch. That means there is nothing above it to rebase, and the branch will just fast forward. See if this longer explanation helps. |
Ah! Gotcha! |
BTW there is a I suppose we are just about ready to put out |
That was an experiment at a previous point in development, and was committed by mistake. Please do remove it.
Very close. I will double check my list when I get time this week. |
On the current list, I checked off a couple more things to bring it up to date. At the very least, I think we can merge the Could you please double check, and make sure you agree all the items are done? In particular, that your PR handled the The two items left are:
I will double check to make sure I haven't missed anything later this week. |
Not really... I manually update the |
@jhwgh1968 I think the nightly compiler has some new changes. Types wrapped up in repeat blocks in macros now reside inside I've put in a simple |
I'm glad you've got a fix for it. Meanwhile, after a long thread on the Rust Forums, apparently the lint I suppressed was not saying what I thought it was. I have removed an extra |
@jhwgh1968 I fixed a problem with rename checking. |
I'll leave the current version on the official repo for a few more days, then we can probably push out |
I'll delete the Thanks for all this work! |
@jhwgh1968 Just to let you know that I've added a new feature to plugins so that functions take a virtual It makes it completely unnecessary to ever call I must admit the plugins system is making it almost embarrassingly easy to define functions for Rhai! |
Tracking Issue
The text was updated successfully, but these errors were encountered: