0

I have been using ClearScript for .NET for quite a long time. I have been exposing C# functions and classes to javascript like this: engine.AddHostObject("ftp", new ftp());

After that I could do engine.eval("ftp.upload(""));

I have been trying to do something similar with nashorn for java but I can't figure it out. What would be the easiest way to do it.

2
  • possible duplicate of Nashorn access non-static Java method Commented Jun 19, 2015 at 16:23
  • Please provide the behaviour you observe/error you get. Commented Jun 19, 2015 at 16:25

2 Answers 2

1

I think this code is the Nashorn equivalent of what you've posted.

ScriptEngineManager factory = new ScriptEngineManager();
factory.getBindings().put("ftp", new ftp());
factory.getEngineByName("nashorn").eval("ftp.upload('')");
Sign up to request clarification or add additional context in comments.

1 Comment

For adding function I was using this: engine.AddHostObject("save", new Func<string, string, int>(SaveFile)); and adding Class (not instances, so I could use var x = new Html() in JS) I used this: engine.AddHostType("Html", typeof(Html)); Do you know what would be equivalent in Nashorn? Thank you so much
0
ScriptEngineManager factory = new ScriptEngineManager();
factory.getBindings().put("ftp", new ftp());
factory.getEngineByName("nashorn").eval("ftp.upload('')");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.