sciter-sdk / rust-sciter

Rust bindings for Sciter
https://sciter.com
MIT License
804 stars 76 forks source link

Consider Macros 1.1 to register script handlers #25

Open pravic opened 6 years ago

pravic commented 6 years ago

Something like this:


#[derive(ScriptHandler)]
struct EventHandler;

impl EventHandler {
  #[script]
  fn sum(&self, a: i32, b: i32) -> i32 { a + b }

  #[script(name="div")]
  fn custom_div(&self, a: i32, b: i32) -> i32 { a / b }
}

However it does not seem possible. Apparently, Macros 1.1 allow only type-level attributes.

pravic commented 6 years ago

Also there is a proc-macro-hack for function-like macros, but it can't be used inside impl blocks and can't contain more than one declaration within the same scope.

pravic commented 6 years ago

As for custom attributes (which seem the most convenient) — they haven't been stabilized yet. But available on nightly though.

pravic commented 5 years ago

Attributes are available now (since Rust 1.30). Need to check them out.

pravic commented 4 years ago

https://doc.rust-lang.org/reference/procedural-macros.html