-
Notifications
You must be signed in to change notification settings - Fork 181
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
Add metadata to functions script side #925
Comments
You can always access metadata in Rust. So I suppose you want to access metadata in code? https://rhai.rs/book/engine/metadata/index.html If you'd like to put arbitrary data inside the metadata, currently there is no easy way to do this, other than put it inside a doc-comment. |
Yes, I meant specifically access metadata of a function in Rhai code. On a complexity scale how hard would implement something like this directly into Rhai be? In the meantime, I'll see if I can't get by with the doc comments alternative - thank you for the suggestion:) |
Quite complex as it would require extending the syntax. Then we'll need to design the syntax to make sure it is flexible enough. |
If you use doc comments, it is built in. But you have to parse the MarkDown. You can use a crate for it. |
The markdown idea is definitely interesting! It might be more than what I want for my usecase though. I haven't tried it yet but I think I'll likely do something like this:
And the register function could do all the fancy logic. Its signature could take the Fn_Ptr and a Dynamic. A little more setup but I think it should cover my immediate needs. I wonder, would I be able to do something like this?
(anyways don't mind me too much, I'm going to play with all this this week) |
Yes you can. Just register a method for the |
Hi, is there a way to add metadata to Rhai functions? Kind of similar to Python's decorator syntax.
Or even Rust's macros (example from Actix)
The examples I gave might be doing more than what I'm after or working in a completely different way. For my use case I don't need anything other than marking certain functions with with arbitrary attributes (perhaps with data).
One workaround I was thinking of was maybe forcing the user to make an object, defining an object with the function as a closure and my metadata on a field but it looks kinda odd:
and I'd wish there was a way to just do something like:
Is this possible through custom syntax perhaps or even now in some kind of work around way?
The text was updated successfully, but these errors were encountered: