I know that I can use Lua Script files to manipulate Java Objects by using libraries like LuaJava. I had this idea of using C# scripts instead~
Is it possible to run C# scripts inside Java?
In theory, yes - you can certainly do this in .Net applications and there are Java / .Net interops.
Typically however Java / C# interops are performed through either P/Invoke or COM - both are pretty cumbersome for this sort of thing and so in reality this probably won't work as neatly as you might have imagined.
All the same if you did want to do this I'd probably recommend that you write the "scripting engine" (i.e. wrapper around the C# compiler) in C#, and then have that expose it to Java land via interops, for example:
public ScriptResult(string Script)
{
// Implemented in .Net
// Script is a string containing the C# code to execute
}
You then need to think carefully about how your C# scripts are going to be able to access any Java-land functionality, again I imagine the best way would be to implement a .Net wrapper class that calls Java objects through interops.
Using C# as a scripting language from within a .Net application is surprisingly straightforward - for information see:
Are C# programs "scripts"? Regardless, you could run most all outside programs from via Runtime.exec(...), but be sure to watch for traps: When Runtime.exec() won't.
Things get a bit more tricky if you wish to have two-way communication between C# and Java, which can be done via simple sockets/streams or all the way up to COM interfaces.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With