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

Generate macro for extern "C" function generation #12

Closed
2 of 3 tasks
swfsql opened this issue Oct 22, 2021 · 0 comments
Closed
2 of 3 tasks

Generate macro for extern "C" function generation #12

swfsql opened this issue Oct 22, 2021 · 0 comments
Labels
enhancement New feature or request

Comments

@swfsql
Copy link

swfsql commented Oct 22, 2021

The #[near_bindgen] from sdk enables generation of functions that effectively gets exposed in the compiled wasm file.
Those functions are actually invoked from the near runtime and runs the contract's logic.

On the Rust code, as they need to be individually marked with Rust attributes, they must either be created manually or get generated by macros. And if #[near_bindgen] is to be used, that usage also must either be created manually or also get generated by macros - example on fungible-token usage.

This library currently doesn't support this and so those extern functions must be created manually.

In order to have automated generation of those, some design on macros is required.

Some possibilities are:

  • Generate a macro that will actually generate the code, when called by the user, similar on the macros on the fungible-token usage example.
  • A benefit is to not require such generator macro to be written manually, as all information that are required (ie. the trait and method names, whether the method requires self, and the actual Self/struct/contract type) exist during the impl item definition.
  • Users have more control of how and when they are making extern functions in their contracts, as this action would be extremely contained and explicit, and independent from the trait and impl definitions themselves.
  • Enables the possibility to universally add customizations on those macros usage, such as skipping methods for when making externs, prefix/postfix on method names, etc.
@swfsql swfsql added the enhancement New feature or request label Oct 22, 2021
@swfsql swfsql closed this as completed in e5dc585 Nov 1, 2021
swfsql pushed a commit that referenced this issue Nov 8, 2021
* Alternative to #15
* Enhances #12 to allow a contract to contain a particular state inside a field, and automatically access that field for it's exposed method calls
  * This is shown in the newly added example 03, where `Struct3` has a `FungibleToken` field inside of it
  * In the code, some methods are now generic over some `OuterType`. In example 03, that type would be `Struct3`.
* Added aliases to `contract_standards` as `cs` and `contract_interface` as `ci`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant