sciter-sdk / rust-sciter

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

Interop for arrays not implemented #17

Closed kraln closed 7 years ago

kraln commented 7 years ago

Apologies if this is an incorrect issue, I'm still new to Rust. I am trying to return an array to tiscript from a callback. I get the following error:

error[E0277]: the trait bound `for<'r> [u8; 61452]: std::ops::Fn<(&'r [sciter::Value],)>` is not satisfied
  --> src\main.rs:28:5
   |
28 | /     dispatch_script_call!
29 | |     {
30 | |         fn get_gfx_buffer();
31 | |     }
   | |_____^ the trait `for<'r> std::ops::Fn<(&'r [sciter::Value],)>` is not implemented for `[u8; 61452]`
   |
   = note: required because of the requirements on the impl of `std::convert::From<[u8; 61452]>` for `sciter::Value`
   = note: required by `std::convert::From::from`
   = note: this error originates in a macro outside of the current crate

error[E0277]: the trait bound `for<'r> [u8; 61452]: std::ops::FnOnce<(&'r [sciter::Value],)>` is not satisfied
  --> src\main.rs:28:5
   |
28 | /     dispatch_script_call!
29 | |     {
30 | |         fn get_gfx_buffer();
31 | |     }
   | |_____^ the trait `for<'r> std::ops::FnOnce<(&'r [sciter::Value],)>` is not implemented for `[u8; 61452]`
   |
   = note: required because of the requirements on the impl of `std::convert::From<[u8; 61452]>` for `sciter::Value`
   = note: required by `std::convert::From::from`
   = note: this error originates in a macro outside of the current crate

error: aborting due to previous error(s)

Here's the code that causes this:

static mut gfx_buffer: [[u32; 256]; 240] = [[0; 256]; 240];
struct Handler;

impl Handler
{
    fn get_gfx_buffer(&self) -> [u8; 256*240+12]
    {
        // unroll gfx_buffer into the appropriate format
        [0u8; 61452]
    }
}

impl sciter::EventHandler for Handler
{
    dispatch_script_call!
    {
        fn get_gfx_buffer();
    }
kraln commented 7 years ago

(note that I'd rather use the video interop, but that doesn't appear to be supported at the moment and I anyway want to send some raw data to the ui)

kraln commented 7 years ago

Nevermind.

pravic commented 7 years ago

:)

Well, of course I can't implement type conversion for everything, so it's better to return Value which can be constructed from &[u8].

pravic commented 7 years ago

Also I guess that my changes for gfx libraries are outdated pretty much, need to update them and to think about more convenient integration.