cincheo / jsweet

A Java to JavaScript transpiler.
http://www.jsweet.org
Other
1.46k stars 160 forks source link

question about @Ambient #82

Closed ssatguru closed 8 years ago

ssatguru commented 8 years ago

I have a javascript class - Colorpicker It has a constructor and a single method called setRGB How would I define this using @Ambient Tried the following

@Ambient
class  ColorPicker extends jsweet.lang.Object {
    public ColorPicker(HTMLElement e, TriConsumer<Object, Object, RGB> f){}; 
        public void setRGB(RGB rgb){};
}

class RGB {
    double r;
    double g;
    double b;

}

I get the following compilation error

ERROR: method 'setRGB' cannot define a body in interface 'ColorPicker' 

If i remove the method and just leave the constructor it works

renaudpawlak commented 8 years ago

Just use the native keyword (when you think of it, it makes sense to use it).

@Ambient
class  ColorPicker extends jsweet.lang.Object {
    public ColorPicker(HTMLElement e, TriConsumer<Object, Object, RGB> f) {}; 
    public native void setRGB(RGB rgb);
}

class RGB {
    double r;
    double g;
    double b;
}

Maybe you also want to define RGB as an ambient an/or and @Interface. I will add some indication for using the native modifier in the error message.

ssatguru commented 8 years ago

That worked. Nice! Yes , some more documentation on this would be helpful. Thanks

renaudpawlak commented 8 years ago

I have updated the error message to give an hint for using modifiers such as 'abstract' and 'native'. Thanks for the feedback.