Open
Description
I'm working to use graaljs as embedded script engine for a custom defined DSL and was looking for a method to achieve something like what's possible with with groovy's DelegatingScript (http://docs.groovy-lang.org/latest/html/api/groovy/util/DelegatingScript.html) so basically having the script engine delegating properties and method invocation to a delegate object.
As pointed out by @chumer on gitter, there is a way to do a similar thing like:
@HostAccess.Implementable
static interface MyInterface {
int foo();
}
public static void main(String[] args) {
try (Context context = Context.create()) {
MyInterface v = context.getBindings("js").as(MyInterface.class);
context.eval("js", "function foo() { return 42; }");
System.out.println(v.foo());
}
}
This however supports interface only but would be nice to have support for classes so one can use this functionality to create DSLs