- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
compile in app
Fri, 2010-07-09, 19:11
Is there an example somewhere of how to compile scala code from inside an application? I was looking at scala.tools.nsc.Main but I can't find any documentation or scaladoc. The only info I could find about the parameters was my calling '> scalac -help'. A small example would be very helpful.
Thanks,
_M!ke
Fri, 2010-07-09, 19:47
#2
Re: compile in app
On Friday July 9 2010, Kevin Wright wrote:
> have you tried stack-overflow?
Stack overflow can't do that. It can only serve as a repository for and
source of knowledge. ... Oh, I get it!
> On 9 July 2010 19:11, Michael Fortin wrote:
> > Is there an example somewhere of how to compile scala code from
> > inside an application? I was looking at scala.tools.nsc.Main but I
> > can't find any documentation or scaladoc. The only info I could
> > find about the parameters was my calling '> scalac -help'. A small
> > example would be very helpful.
> >
> > Thanks,
> > _M!ke
RRS
Sat, 2010-07-10, 00:27
#3
Re: compile in app
That's not necessarily easy to do. While I do know this question has been asked before, I, for one, couldn't find it right now.
On Fri, Jul 9, 2010 at 3:30 PM, Kevin Wright <kev [dot] lee [dot] wright [at] gmail [dot] com> wrote:
--
Daniel C. Sobral
I travel to the future all the time.
On Fri, Jul 9, 2010 at 3:30 PM, Kevin Wright <kev [dot] lee [dot] wright [at] gmail [dot] com> wrote:
have you tried stack-overflow?
On 9 July 2010 19:11, Michael Fortin <michael [at] m410 [dot] us> wrote:
Is there an example somewhere of how to compile scala code from inside an application? I was looking at scala.tools.nsc.Main but I can't find any documentation or scaladoc. The only info I could find about the parameters was my calling '> scalac -help'. A small example would be very helpful.
Thanks,
_M!ke
--
Kevin Wright
mail/google talk: kev [dot] lee [dot] wright [at] gmail [dot] com
wave: kev [dot] lee [dot] wright [at] googlewave [dot] com
skype: kev.lee.wright
twitter: @thecoda
--
Daniel C. Sobral
I travel to the future all the time.
Sat, 2010-07-10, 09:37
#4
Re: compile in app
Here are two examples:
http://people.apache.org/~mduerig/scala4scripting/
You might probably want to watch his talk from the Scala Days as well.
Here's some code I wrote some time ago (in Java!) which uses Scala for
scripting (I'm not sure which version but definitely pre-2.8):
http://github.com/jrudolph/scolorz/blob/master/src/net/virtualvoid/graph...
Actually it is quite easy to use the Scala interpreter (beware Java
code following):
import scala.tools.nsc.Interpreter;
import scala.tools.nsc.Settings;
final Interpreter interpreter = new Interpreter(new Settings());
final Painter[] painter = new Painter[1];
interpreter.bind("painter", "Array[net.virtualvoid.graphics.Painter]", painter);
String code = "object aPainter extends net.virtualvoid.graphics.Painter{\n"
+ "def paint:Unit = {\n"
+ text.getText() + "\n}\n"
+ "}\n";
interpreter.interpret(code);
interpreter.interpret("painter(0) = aPainter;");
So I defined a Painter interface and bound an array of that variable
to receive the results. Code which I executed got wrapped by code
which implements the interface. After evaluating this, the result is
stored into the array and can be accessed afterwards.
On 9 July 2010 19:11, Michael Fortin <michael [at] m410 [dot] us> wrote:
--
Kevin Wright
mail/google talk: kev [dot] lee [dot] wright [at] gmail [dot] com
wave: kev [dot] lee [dot] wright [at] googlewave [dot] com
skype: kev.lee.wright
twitter: @thecoda