Soon after I wrote "I also talked about using Scala language (on) on the. NET platform" on the Lenovo ThinkCentre m4000t desktop in my Ubuntu 9.10 operating system, I went home from work. As a result, I will continue to work on the Windows Vista operating system on the Dell migration 1520. First, start sun virtualbox to open a Ubuntu 9.10 operating system. Scala SDK package has not been installed in the Ubuntu 9.10 operating system. In the previous articleArticleMentioned in:
Of course, You can also download the latest Linux installation package for Scala 2.7.7 on the official Scala website without using the apt-GET command in the Ubuntu operating system, this will be installed together in a centralized manner, and you can also have the sbaz tool. Of course, at this time, the supervisor is responsible for upgrading and updating the scala software package. the Ubuntu operating system will not help you upgrade and update the software package that is not installed using the apt-GET command.
So let's take a look:
Ben @ Ben-vbox :~ /Src $WgetHttp://www.scala-lang.org/downloads/distrib/files/scala-2.7.7.final.tgz
Ben @ Ben-vbox :~ /Src $Tar xzf scala-2.7.7.final.tgz
Ben @ Ben-vbox :~ /Src $Sudo music scala-2.7.7.final/OPT
The Scala SDK is installed. For convenience ~ /. Add the following content to the end of the bashrc file:
# Set path for scalascala_home =/opt/scala-2.7.7.finalif [-d "$ scala_home/bin"]; then Path = "$ path: $ scala_home/bin" fi
Let's check the installation result:
Ben @ Ben-vbox :~ $ scalac-version
Scala compiler version 2.7.7 . final -- Copyright 2002-2009, lamp/EPFL
Ben @ Ben-vbox :~ $ Scala-version
scala code runner version 2.7.7 . final -- Copyright 2002-2009, lamp/EPFL
Ben @ Ben-vbox :~ $ Scala
welcome to Scala version 2.7.7 . final (openjdk 64-bit server Vm, Java 1.6.0 _ 0 ).
type in expressions to have them evaluated.
type: Help for more information.
Scala> : Quit
Ben @ Ben-vbox :~ $ sbaz-version
sbaz 1.25tmp -- (c) 2005-2009 lamp/EPFL
Ben @ Ben-vbox :~ $ sbaz installed
base/1.9
sbaz/1.25tmp
sbaz-Setup/1.0
Scala/2.7.7.final
Scala -devel/2.7.7.final
Scala-Library/2.7.7.final
Scala-tool-support/2.7.7.final
7 packages installed
Ben @ Ben-vbox :~ $
Good. Version 2.7.7 is installed correctly, and the sbaz tool is also available. So what are you waiting? Install Scala-msil:
Ben @ Ben-vbox :~ $Sbaz install Scala-msil
Planning to install: Scala-msil/2.7.7.final
Installing...
Ben @ Ben-vbox :~ $Sbaz installed
Base/1.9
Sbaz/1.25tmp
Sbaz-Setup/1.0
Scala/2.7.7.final
Scala-devel/2.7.7.final
Scala-Library/2.7.7.final
Scala-msil/2.7.7.final
Scala-tool-support/2.7.7.final
8 packages installed
Ben @ Ben-vbox :~ $
The tools are complete, so we can start to work. First, modify DOTNET. Scala in the previous article as follows:
Import system. leleobject DOTNET extends application {console. writeline ("Scala. net: Welcome to "); console. writeline ("OS version:" + environment. osversion); console. writeline ("CLR version: {0} ({1})", environment. version, skyiv. runtimeframework. currentframework); console. writeline ("default encoding:" + system. text. encoding. default );}
The change is to add the currentframework attribute of the runtimeframework class, which is in the sourceProgramCodeThis can be found in the article ". NET Framework CLR version check", which is not repeated here.
Finally, it is the MAKEFILE file:
AllSource codeAll the preparations are complete. We can use the make command to generate our goals:
Ben @ Ben-vbox :~ /Projects/scalanet $Make
CSC-T: Library-out: runtimeframework. dll runtimeframework. CS
/Opt/scala-2.7.7.final/bin/scalac-net-xassem-path runtimeframework. dll DOTNET. Scala
The CP/opt/scala-2.7.7.final/lib/predef. dll.
Ilasm DOTNET. msil
Refreshing 'dotnet. msil', no listing file, to EXE --> 'dotnet.exe'
Operation completed successfully
Ben @ Ben-vbox :~ /Projects/scalanet $
The make command first calls CSC (the alias of GMCs) to compile runtimeframework. CS to generate runtimeframework. dll.
Then, call scalac-net to generate DOTNET. msil from DOTNET. Scala. Note that because DOTNET. Scala calls the class in runtimeframework. dll, you need to add the-xassem-path runtimeframework. dll parameter, otherwise an error will occur.
Then, run the CP command to copy the predef. dll file from the scala library directory to the current directory.
Finally, call ilasm to compile DOTNET. msil into dotnet.exe.
Finally, the program runs as follows:
Ben @ Ben-vbox :~ /Projects/scalanet $ ls-L *
-RW-r -- 1 Ben 3072 dotnet.exe
-RW-R -- r -- 1 Ben 5852 2009-12-22 DOTNET. msil
-RW-r -- 1 Ben 375 2009-12-22 DOTNET. scala
-RW-r -- 1 Ben 440 2009-12-22 makefile
-RW-r -- 1 Ben 1180160 2009-12-22 predef. DLL
-RW-r -- 1 Ben 4102 2009-12-22 runtimeframework. CS
-rwxr-XR-x 1 Ben 6144 runtimeframework. dll
Ben @ Ben-vbox :~ /Projects/scalanet $ mono dotnet.exe
Scala. net: Welcome to
OS version: Unix 2.6.31.16
CLR version: 2.0.50727.1433 (Mono 2.4.2.3)
default encoding: system. text. utf8encoding
Ben @ Ben-vbox :~ /Projects/scalanet $
As you can see, the DOTNET. Scala program calls the currentframework attribute of the runtimeframework class defined in the runtimeframework. CS program to display the mono version: Mono 2.4.2.3. That is, we have successfully implemented the scala Language C # hybrid programming.
Complete source code can be downloaded to the http://bitbucket.org/ben.skyiv/scalanet/downloads/ page.
You can also download it using the Hg clone http://bitbucket.org/ben.skyiv/scalanet/ command.
For more information about HG, see the mercurial memorandum.
Now, let's do it here today. As for the various versions of mscorlib. dll mentioned in the previous article, let's talk about it later.