mystor / rust-cpp

Embed C++ directly inside your rust code!
Apache License 2.0
802 stars 44 forks source link

Rusty Cheddar Integration #8

Closed kkimdev closed 6 years ago

kkimdev commented 7 years ago

Is it possible to do something like this?

#[no_mangle]
pub extern "C" fn callback() {
    println!("Called from C");
}

cpp! {
    raw {
        void function() {
            callback();
        }
    }
}
mystor commented 7 years ago

Currently rust-cpp does not detect exported functions from rust to add bindings in C++ land, though I may add that sort of functionality in the future. Your above example would work, however, in the current system, if you did this:

#[no_mangle]
pub extern fn callback() {
  println!("Called from C");
}

cpp! {
  raw {
    extern "C" { void callback(); }
    void function() {
      callback();
    }
  }
}
kkimdev commented 7 years ago

I see, and thanks for the answer!

kkimdev commented 7 years ago

btw, I've found this, https://gitlab.com/rusty-binder/rusty-cheddar and I will be using this to generate C headers for now. Maybe we can consider supporting c header generation inside cpp! using Cheddar?

mystor commented 7 years ago

Yeah, I have considered adding some sort of rusty-cheddar integration to rust-cpp but I haven't had a clear enough idea of what exactly I would want it to look like. Once I figure that out & get time to implement it I'll probably have it behind a cheddar feature gate.

ogoffart commented 6 years ago

Is this issue still valid?

Now one can do

fn callback() {
  println!("Called from C");
}

cpp! {{
    void function() {
      rust!(xxx [] { callback() })
    }
}}
ogoffart commented 6 years ago

Closing this since we have the rust! macro now.