yeti icon indicating copy to clipboard operation
yeti copied to clipboard

Script Engine Support

Open sirinath opened this issue 11 years ago • 4 comments

Can this be used as a Java Script Engine? If not can this be added?

sirinath avatar Dec 03 '13 17:12 sirinath

Probably the support can be added (I don't know any reason, why this shouldn't be possible). You could write and submit the code. :)

mth avatar Dec 03 '13 20:12 mth

I might be a user of of this in calling using some ML code from Java but for implementing a scripting engine I am not the best person.

sirinath avatar Dec 04 '13 06:12 sirinath

On Tue, 3 Dec 2013, Suminda Dharmasena wrote:

I might be a user of of this in calling using some ML code from Java but for implementing a scripting engine I am not the best person.

You can use the compiler from Java quite easily without scripting engine.

Only a thin wrapper class written in Yeti is needed, that calls evaluateYetiCode, and then you can use the wrapper from Java. Simple example would be:

module evalwrapper;

load yeti.lang.compiler.eval;

class EvalYetiCode ctx = evaluateYetiCode [],

 Object eval(String code)
     result = ctx [] code;
     case result.result of
     Result res: res;
     Exception ex: throw ex;
     _: failWith result.str;
     esac

end

It could be used for example with following Java code:

public class TestEval { public static void main(String[] _) { new EvalYetiCode().eval("println 'Hello world'"); } }

The code could be compiled and run with following commands:

java -jar yeti.jar -d . evalwrapper.yeti javac TestEval.java java -cp yeti.jar:. TestEval

The evaluateYetiCode documentation:

http://dot.planet.ee/yeti/docs/latest/yeti.lang.compiler.eval.html#evaluateYetiCode

mth avatar Dec 04 '13 11:12 mth

Thanks. This is good enough for now.

In case anybody want to take the next step with this feature request this might help: https://today.java.net/pub/a/today/2006/09/21/making-scripting-languages-jsr-223-aware.html

sirinath avatar Dec 04 '13 14:12 sirinath