Somebody talking the python's code can embed into C#'s code. What the mechanism to do that? please explain for me.
Thanks a lot
There are several approaches to this, depending on which languages you want to interoperate with.
.Net/CLR Languages - Iron Python provides an implementation of Python running on the CLR. Allows you to use other CLR assemblies and embed a python scripting engine in your code
Java/JVM Based Languages - Jython provides an implementation on the JVM and allows you to use Java classes and call to call into jython as a scripting language using JSR 223 - Scripting for the Java Platform
C/C++/Perl/etc, etc The Simplified Wrapper and Interface Generator allows you to interop between C based languages and others, including .Net and Java. It's very good for C++, C and COM - other languages are little trickier - but worth checking out if you need to use CPython with .Net or Java
Use IronPython for integration with .net. Likewise, Jython integrates with Java.
And Jython for integration with Java.
Related
I'm reading about new Java 8 features and came to know it comes with Nashorn (Javascript engine). Can someone explain me why would/should I use a Javascript engine inside Java. What programming problems it would solve ? any examples
Thanks,
Ravi
Simply, it would allow you to create standalone JavaScript programs and allow embedding JavaScript in Java. Java must be compiled into what is known as a "machine language" before it can be run. JavaScript is text-based and interpreted, and is interpreted by browsers. So being able to use this technology inside Java is a pretty cool thing. JRuby is another example of a scripting language that can run inside Java, as well as it's Python equivalent Jython. They are all just wrappers for languages to use inside Java. It is already possible to run dynamic languages on top of the JVM, but the goal is to ease new dynamic language implementations and increase their performance.
One advantage I can think of is using JavaScript for the scripting of a Java game.
Hope it helps :)
So, I just realized that Java has a built in API system that works with JavaScript and apparently other scripting languages that are JSR-223 compliant. Now, I'm designing a game engine and I'm wondering if I should just use the integrated JavaScript support or figure out how to use Lua.
QUESTION: Can the Java Scripting API easily support Lua? If so, how?
If you feel like it: Would it be unknown to do the scripting side of a game engine in JavaScript?
EDIT: I need scripting capabilities for my engine to allow the creation of AIs, special voxels (Like blocks in minecraft) and other add-ons to the game. I'm not set on doing all this creation in a scripting language because the difficulty of doing so but a scripting language appears as a good alternative to making JARs for all game content. I'm simply exploring what I can do with Java.
The Java Scripting framework relies on the code implementing JSR-223 being written in Java. As such lua won't work.
However, you can use an implementation of lua written in Java such as luaj which has JSR-223 support included.
Note: luaj is not a complete clone of lua but it's pretty functional and allows you access to java classes etc.
On the subject of choosing a scripting language, as you are using Java as your system programming language, some of the benefits of using lua as a scripting language don't apply e.g. fast, small footprint, excellent C integration.
So really it becomes a personal preference. Javascript would be probably be fine, as would Jypthon, JRuby or luaj.
It is not a wise idea to make a game engine in JS. Despite possible(see Node.js / Three.js), JS is rather slow because is interpreted. Node.js has JIT compilation, but it's still 3-4x(best case) slower than C++ equivalent.
I never used Lua or Java Scripting API, I cannot give you an answer on this, but I think the speed of JS will change your mind.
I have a need for providing code snippets at runtime.
For this to work well, I basically need to call into the scripting language, and back into Java. For this to be usable in a debug scenario StackTraces must be usable too (so methods and linenumbers go directly to the script source like in modern JSP-pages) and Exceptions must bubble up correctly.
What scripting languages - where the source is read at runtime - can provide this? JSR-223 support is a bonus.
I think JRuby is best choice because:
Its performance as a scripting language is good.
It can execute in two mode (Compiled, Interpreted).
It supports Ruby on Rails and you can use JRuby for Rails applications in production environments.
You can invoke the classes of the Java Platform easily without any restriction.
I think Groovy would be the perfect fit in your case given it's super similarity and ease of integration with Java not to mention that it's pretty much the most mature JVM language out there with excellent support from the likes of SpringSource.
As an example of JSR support, Groovy has it.
What is main difference between JSR-223 and JSR-241?
If I understood correctly:
JSR -223: introduces a scripting language engine in Java, thats it! You are free to use whatever scripting language you wants, for ex: Groovy, Mozilla Rhino, PHP, Jython, Python etc. Default implementation of J2EE supports JavaScript as scripting engine, but you can add any scripting language you like. So this was simply to connect the Classes written in Java language with piece of code written in Scripting language (or vice-versa). The only benefit of this integration, I could see is simplicity offered by scripting language in writing a program as compared to writing the same program in Java.
JSR 241: This is extension of JSR-223 and emphasize on adopting Groovy as scripting language, i.e. If you're planning to use scripting language in your Java application (Web or Dekstop apps), use Groovy.. leave others, because Groovy is more Java like and other scripting languages like Jython, Python, JavaScript etc have been adopted and modified to suit Java, but natural choice is Groovy.
Could you please throw some more light on this, and Is my understanding correct?
JSR 241 is not an extension of JSR 223, nor does it "emphasize on adopting Groovy". Instead, its main focus is making Groovy (i.e. its syntax and semantics) an official Java standard in the first place.
The only thing it has to do with JSR 223 is that it's mentioned in 2.6 to clarify why the proposal is not already covered by JSR 223:
Do you know of a runtime written in Java/J2ME, that is capable of reading and executing a script/binary file?
Wikipedia has a complete list. However, you sound like you're probably interested in Jython and JRuby.
I wrote just such a language designed to be small enough for J2ME, and to not use reflection/code generation/etc...
http://www.hecl.org
It's open source under a liberal license, so you're welcome to take it, study it, include it in your own programs, or hack it to make it behave like you want.
For 'regular' Java, there are other languages that do more and are faster and more complete.
I know of an x86 emulator written in Java, JPC
Many JVM Languages - Clojure, for example. There are pretty much hundreds of JVM languages floating around, most of which were implemented in Java - Scala, Rhino, etc.
In terms of unique languages, the major ones are Clojure and Scala. Additionally, there are ports of many major languages to the JVM platform, mostly high-level languages. These include Ruby -> JRuby, Python -> Jython, and JavaScript -> Rhino. A more complete list is here.
This is an impressive list of programming languages for the Java virtual machine :
Programming languages for the Java Virtual Machine JVM
The problem is that j2me can be too limited in its use of reflection to enable this, so you need to investigate your specific target.
In terms of java in general, there are many, such as JRuby, Beanshell, Jython, etc.
I just listened to a Software Engineering Radio podcast where a Sun developer talked about Maxine which is a JVM that is mostly implemented in Java itself. It was a very interesting interview and technology.
So it's feasible that someday Java itself (meaning the standard JVM) will be implemented in Java much like C compilers are written in C (after a bit of bootstrapping).