danielpclark/rutie

rutie proc macros

Opened this issue ยท 9 comments

wasmer-ruby wrote some proc proc macros - it would be good if these were integrated in rutie - haven't brought it up in the wasmer project yet.

wasmerio/wasmer-ruby#48

Hywan commented

Hi!

I wrote those macros. They aren't perfect, but they helped me on the short-term. I can dedicate some times to improve them if @danielpclark believes it can be useful for rutie :-).

Can I have some clarification on what exactly is being proposed to be added and improved upon? Is it some of the written crates/ in the link provided above?

I'm open for improvements, macros, helpers, and the like. If you're wanting to just add macros that help with the ease of use in writing Ruby methods/objects feel free to place those in src/dsl.rs. If the feature(s) require any external dependencies then I would recommend have them implemented as an optional feature.

From the sound of it it may indeed be something we want in Rutie itself.

Hywan commented

I believe @dsisnero is talking about rutie-derive (I just wrote a succinct documentation today). It's the #[rubyclass], #[rubymethods] and #[rubyfunction] procedural macros. It's far from being perfect, but from my point of view, it provide a more intuitive API than the existing class! and methods! macro.

See a usage example, crates/wasmer/src/module.rs (or any file in this crates/wasmer/src/ directory).

I've also defined a new ruby_define! macro to declare the modules, classes, methods and functions, see it in action in crates/wasmer/src/lib.rs. We can do better here with proc macros but I was missing time.

If you find them useful, I can open a PR to integrate them inside rutie itself.

Bonus: I've also used rustdoc to generate a documentation for Ruby, see it in action here. All examples are tested by rustdoc (it's based on the rutie-test crate, see it in crates/rutie-test/).

@Hywan excellent! Yes I like those. Feel free to add them to this project.

Hywan commented

I will try to find time to do that then!

Hywan commented

The macros must be polished. For example, it's not possible to support optional parameter, or named parameter for a function or a method for the moment. Do we want to migrate the macros, and polish them here in this repository, or do you prefer to get a fully polished version first?

You can work on them here and polish them here. They don't have to be the best to go public, they just have to work. Those features you're describing that don't work yet can simply be a future update to this project.

I'm working on a PR with migration. I've copied source files of rutie-derive and rutie-derive-macros from wasmer-ruby/crates/ to the newly created rutie/src/dsl folder and moved rutie/src/dsl.rs to rutie/src/dsl/mod.rs. I want to keep the directory structure of rutie with the least possible changes.

Not sure it's the best approach. Currently fixing compilation errors.

Maybe a better option is move rutie/src/* to rutie/crates/rutie and copy wasmer-ruby/crates/{rutie-derive,rutie-derive-macros} to rutie/crates/. Similar to what wasmer-ruby/crates.

@danielpclark @Hywan What do you think?