tcr / mug

A self-hosted JavaScript compiler for the JVM. Written in CoffeeScript.
150 stars 5 forks source link

Support seamless Java<->Mug Interoperability #12

Closed tcr closed 13 years ago

tcr commented 13 years ago

This feature is not yet supported, but probably a requirement if Mug is to be used in any production environment.

The current workaround is to write modules which wrap Java functionality.

tcr commented 13 years ago

Mug now has support for this using the java module:

var java = require("java")
var JFrame = java.import("javax.swing.JFrame")
var JButton = java.import("javax.swing.JButton")
var frame = new JFrame("Window")
frame.add(new JButton("Click me"))
frame.setSize(200, 200)
frame.setVisible(true)

Which uses the reflection API. It will be worthwhile to write a specialized compiler that will hard-code references to a Java class in a JSObject to avoid the Reflection API overhead, as a second option.