Inheritance & Generics #4087
-
SummaryHello, i'm creating a game engine and I'm trying to implement collisions. I need to implement it for all Additional Detailsexport class Graphic { ... }
export class Rectangle extends Graphic { ... }
... #[wasm_bindgen]
extern "C" {
pub type Graphic;
pub type Circle;
pub type Ellipse;
pub type Line;
pub type Rectangle;
} So firstly i would have to know what kind of instance it is so here is just a function to do that. Unfortunately it doesn't work: the output is always "???" #[wasm_bindgen]
pub fn show_info(graphic: &Graphic) {
if graphic.is_instance_of::<Ellipse>() {
console_log!("Ellipse");
} else if graphic.is_instance_of::<Circle>() {
console_log!("Circle");
} else if graphic.is_instance_of::<Rectangle>() {
console_log!("Rectangle");
} else if graphic.is_instance_of::<Line>() {
console_log!("Line");
} else {
console_log!("???");
}
} let testRect = new cazan.graphics.Rectangle({
game: game,
position: {x: 10, y: 10},
dimensions: {width: 50, height: 50},
styles: {
graphic: blackStyle
}
})
show_info(testRect) Thanks to you all for your help :). If you need more details i'm answering for sure |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
I'm unfortunately unfamiliar with integrating with JS, but everything here looks right. I don't think Could you provide a complete but minimal example that reproduces your issue? |
Beta Was this translation helpful? Give feedback.
Does the trick for me.
See the
wasm-bindgen
Guide on this topic.