This page is no longer maintained — Please continue to the home page at www.scala-lang.org

JNA for Scala?

2 replies
spoon
Joined: 2008-07-01,
User offline. Last seen 1 year 21 weeks ago.
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
extempore
Joined: 2008-12-17,
User offline. Last seen 35 weeks 3 days ago.
Re: JNA for Scala?

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.

nilskp
Joined: 2009-01-30,
User offline. Last seen 1 year 27 weeks ago.
Re: JNA for Scala?
On Sat, Feb 12, 2011 at 11:25 AM, Paul Phillips <paulp@improving.org> wrote:
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 ?

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland