rhaiscript / rhai

Rhai - An embedded scripting language for Rust.
https://crates.io/crates/rhai
Apache License 2.0
3.73k stars 175 forks source link

Plugin question #729

Closed jkvargas closed 1 year ago

jkvargas commented 1 year ago

How can I request the user to write a function called prepare in Rhai so I can call it in rust? I want to ask the developer to write a bunch of functions on their side so I can later call these functions.

Can I get an example?

emesare commented 1 year ago

If I understand you correctly you want to call a rhai function from rust. If that is what you are trying to do here is the book page.

schungx commented 1 year ago

If you just want to call it, that book page is what you need. There will be an error if the user doesn't define such a function.

If you want to make sure that all required functions are properly defined, compile thr script to AST and the use one of the iter functions to check for function names and number of parameters.