Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSR 223 #15

Open
eliasvasylenko opened this issue Oct 28, 2016 · 5 comments
Open

JSR 223 #15

eliasvasylenko opened this issue Oct 28, 2016 · 5 comments

Comments

@eliasvasylenko
Copy link

Feature request: implement javax.script.ScriptEngineFactory to satisfy JSR 223 standard. Any interest?

@mjanicek
Copy link
Owner

I wasn't under the impression that JSR 223 is a particularly successful/popular standard, but I might well be wrong. 😄 That said, hopefully this shouldn't be too hard to do. Are you interested in JSR 223 compliance yourself? I could look into it if there is actual demand.

@eliasvasylenko
Copy link
Author

Ahaha well you may be right about it being unpopular. FWIW many of the newer, high-profile JVM languages (e.g. kotlin/ceylon) do appear to provide it, though it often feels like a bit of an afterthought, so I'm not sure how exactly that speaks to its relevance either way.

I assume then that you've not heard much demand from others, and I can only speak for myself that it'd be useful to me, so perhaps the effort would be best spent elsewhere. Oh well, I'll leave the suggestion with you :).

Cheers

@mjanicek
Copy link
Owner

mjanicek commented Nov 4, 2016

I'm looking into it -- as I've written above, it doesn't seem to be particularly difficult, but there are a few things I'm not very sure about yet.

The main open question is how to support both global and engine scopes nicely. The documentation of javax.script isn't particularly helpful, and I haven't used the JSR 223 -based interfaces myself, so I'm not sure how these engines are used in an idiomatic way.

I'll try to finish it in the coming days, though!

@GotoFinal
Copy link

GotoFinal commented Dec 2, 2016

@mjanicek is this still a thing? JSR 223 is very useful for creating generic scripting interfaces, as I can prepare bindings and then I don't need to care if user use lua or some other language like javascript, as all of them will use common interfaces, like CompiledScript if language support that.

@eliasvasylenko kotlin/ceylon isn't like this, they are full languages that are compiled to bytecode compatible with JVM, without ability to compile and run them from java as script. But they are many implementations for jsr 223 of other languages: javascript included in JRE, jpyton, jruby, groovy, AppleScript and more.

Problem is that implementation must support java classes inside scripts, (IDK if rembulan can do this) so you can bind some variable to java object and use it from script, so JSR 223 can be powerful tool.

	ScriptEngineManager mgr = new ScriptEngineManager();
	RembulanScriptEngine e = (RembulanScriptEngine) mgr.getEngineByName("rembulan");

        CompiledScript script = e.compile("result = player:kill()");

        Bindings bindings = e.createBindings();
	bindings.put("player", somePlayerInstance);
        script.eval(bindings);
	System.out.println( "result="+e.get("result"));

@eliasvasylenko
Copy link
Author

@GotoFinal I understand that Kotlin and Ceylon are compiled, but that doesn't mean they can't be used as scripting languages. A scripting language just doesn't have an explicit compilation step, there are lots of implementations which compile and cache even in the case of more traditional scripting languages.

I don't know much about Ceylon, but in Kotlin's case there seem to be quite a few people working on different approaches to scripting capabilities, with JSR-223 compliance in active official development from JetBrains.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants