Skip to content
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

Using mun to script rust? #288

Open
shadowcat-mst opened this issue Nov 4, 2020 · 3 comments
Open

Using mun to script rust? #288

shadowcat-mst opened this issue Nov 4, 2020 · 3 comments

Comments

@shadowcat-mst
Copy link

I can see in the documentation that I can bind in an extern C function, which I presume also means I can bind in a plain rust function.

However I'm not sure where I'd start to, say, expose a rust struct and its methods to mun code, and I'm also not sure where to look to try and figure out where to start :/

To be clear, my hope would be to be able to do roughly

let thing = get_thing_from_rust(...);
futz_thing(thing);

where get_thing_from_rust returns a struct or a reference thereto and futz_thing can then call 'thing.futz()' on the rust side or similar.

I apologise if this issue is still vague or if I've missed something obvious - replies of the form "please go read document X" or "please go read code Y" or "please clarify question Z" would be much appreciated :D

@baszalmstra
Copy link
Collaborator

Hey @shadowcat-mst ! The goal would be to enable interoping between the two language in roughly the same way you describe but we are not there yet.

You can bind rust functions that you can then use in Mun and you can call Mun functions from rust. We dont have any form of traits or associated methods currently. The docs here show how to call Rust functions from Mun: https://docs.mun-lang.org/ch02-04-extern-fn.html . It's currently still limited to primitive types (f32, i32, u64, etc).

So, you'll have to hang in there a little longer. Well get there! :) Hope that answers your question?

@shadowcat-mst
Copy link
Author

Aha, I see. I somehow read that document, saw the 'extern C' one, and then completely flipping missed the first non-C-ABI example.

Whereabouts in the codebase would I look to see the current bits? I'm not at the point with the project that led me to start asking questions where it's an itch I'm likely to try to scratch myself, I'm afraid, but I'd love to at least read up and understand what's there a bit better :)

@Wodann
Copy link
Collaborator

Wodann commented Nov 11, 2020

Haha, all good.

The code for the parser can be found here. Lowering from an abstract syntax tree to HIR can be found here.

I hope that helps! 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants