Skip to content

Suggestion about definitions generation #46

@Shatur

Description

@Shatur

You recently added support for definitions generation via a separate utility that parses Rust code. Thank you for addressing this so quickly 🙂It's useful when you directly write an app with Lua API.

But in my case I'm planning to provide a crate with Bevy integration that can be used inside games. In this scenario users will need annotations for both: Bevy API and their own custom types. To achieve this, they'll have to download the source code of my crate and run this utility on it separately. Even If I bundle the generated definitions with the library, they'll still have to find it somewhere in the target dir.

In Rhai they do it a bit differently. They provide a special feature called metadata. When enabled, the macro captures comments as well and stores this information inside Engine (it's similar to Lua in this crate). And with this feature users can dump annotations at runtime in the specified destination. This way users and my crate add their types into Lua, from which users can dump it without additional steps.

I see 2 other advantages that doesn't matter to me specifically, but I think it could be useful to others:

  • Functions defined without the macro will also be available in these definitions. This will probably require adding a special method to add a comment to a function by name.
  • This approach will work for code that generated by other macro.

Would you be open to consider changing the approach?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions