- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
JNA for Scala?
Sat, 2011-02-12, 16:47
I just ran across Java Native Access (JNA), which is a key part of how JRuby gets access to POSIX things like chmod and signal. Has anyone tried doing the same thing for Scala? I see that SBT's process support uses java.lang.Process, so it's not using JNA. Has any other project tried it?
The reason I ask is that Scala has excellent syntax for a scripting language, but writing scripts runs you into challenges as soon as you want to interact with the underlying Unix operating system. For example, you can't send a signal of your choice to a child process. You only get Process.destroy, which I'm guessing sends a KILL signal. You also can't exit a JVM if there are child processes around, including ones that your own child processes created, so there's no way to reliably exit a JVM if its child processes aren't behaving well. It's enormously complicated compared to how things are in languages that are built as scripting languages.
Here are some JNA pointers, for any curious:
http://www.infoq.com/news/2007/09/jna-jruby/
http://headius.blogspot.com/2007/09/java-native-access-jruby-true-posix.html http://java.net/projects/jna/
Lex
The reason I ask is that Scala has excellent syntax for a scripting language, but writing scripts runs you into challenges as soon as you want to interact with the underlying Unix operating system. For example, you can't send a signal of your choice to a child process. You only get Process.destroy, which I'm guessing sends a KILL signal. You also can't exit a JVM if there are child processes around, including ones that your own child processes created, so there's no way to reliably exit a JVM if its child processes aren't behaving well. It's enormously complicated compared to how things are in languages that are built as scripting languages.
Here are some JNA pointers, for any curious:
http://www.infoq.com/news/2007/09/jna-jruby/
http://headius.blogspot.com/2007/09/java-native-access-jruby-true-posix.html http://java.net/projects/jna/
Lex
Sat, 2011-02-12, 18:37
#2
Re: JNA for Scala?
On Sat, Feb 12, 2011 at 11:25 AM, Paul Phillips <paulp@improving.org> wrote:
scalac -optimise ?
You have to write some java because JNA uses public fields to infer the memory layout and there's no way to make scala generate them.
scalac -optimise ?
On 2/12/11 7:47 AM, Lex Spoon wrote:
> I just ran across Java Native Access (JNA), which is a key part of how
> JRuby gets access to POSIX things like chmod and signal. Has anyone
> tried doing the same thing for Scala? I see that SBT's process support
> uses java.lang.Process, so it's not using JNA. Has any other project
> tried it?
I did.
https://github.com/paulp/jna-fuse-scala
I had it working if somewhat clunkily, with fuse filesystems
successfully written in scala. You have to write some java because JNA
uses public fields to infer the memory layout and there's no way to make
scala generate them. This was all a while ago, maybe close to two years
ago.