In other words, ivony... wrote in Lao Zhao, "using Scala language (below) on the. NET platform: analysis," commented on the 18th floor of this article:
I use scala. net in the Ubuntu operating system, and this should not be the case.
So let's test it.
Now, we add a DOTNET. CS file, as shown below:
using System;using System.IO;using System.Web;using System.Collections.Generic;namespace Skyiv{ public class DotNet { public static string UrlEncode(string s) { return HttpUtility.UrlEncode(s); } public static decimal ToDecimal(double d) { decimal dec; try { dec = (decimal)d; } catch (OverflowException) { dec = decimal.MinValue; } return dec; } public static FileMode[] GetFileModes() { return (FileMode[])Enum.GetValues(typeof(FileMode)); } /* public static List<FileMode> GetFileModeList() { var list = new List<FileMode>(); foreach (FileMode item in Enum.GetValues(typeof(FileMode))) list.Add(item); return list; } */ }}
Then, add the call to these C # methods in dotnetscala:
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); console. writeline (skyiv. DOTNET. urlencode ("Welcome to Scala-msil! "); Console. writeline (skyiv. DOTNET. todecimal (system. math. pi); console. writeline ("{0: N0}", skyiv. DOTNET. todecimal (system. double. maxvalue); console. writeline (skyiv. DOTNET. getfilemodes (); // console. writeline (skyiv. thexmltree. getvalue ());}
Finally, modify the MAKEFILE file:
Now let's take a look at the compilation and running situations:
Ben @ Ben-vbox :~ /Projects/scalanet $Make
CSC-out: runtimeframework. dll-T: Library runtimeframework. CS
CSC-out: DOTNET. dll-T: Library-R: system. Web. dll DOTNET. CS
CSC-out: thexmltree. dll-T: Library-R: system. xml. LINQ. dll thexmltree. CS
Scalac-net-xassem-path runtimeframework. dll: DOTNET. dll: thexmltree. dll DOTNET. Scala
Ilasm DOTNET. msil
Refreshing 'dotnet. msil', no listing file, to EXE --> 'dotnet.exe'
Operation completed successfully
Ben @ Ben-vbox :~ /Projects/scalanet $Mono dotnet.exe
Scala. Net: Welcome
OS Version: Unix 2.6.31.16
CLR version: 2.0.50727.1433 (Mono 2.4.2.3)
Default encoding: system. Text. utf8encoding
% E6 % AC % A2 % E8 % BF % 8e % E4 % BD % BF % E7 % 94% A8 + Scala-msil!
3.14159265358979
-79,228,162,514,264,337,593,543,950,335
System. Io. filemode []
Ben @ Ben-vbox :~ /Projects/scalanet $
Good. Everything works. It can be seen that there is no problem in passing parameters of scala and C # languages.
However, if you release the annotated getfilemodelist method in the DOTNET. CS program, compile it again:
ben@ben-vbox:~/Projects/ScalaNet$ make
csc -out:DotNet.dll -t:library DotNet.cs
scalac-net -Xassem-path RuntimeFramework.dll:DotNet.dll:TheXmlTree.dll dotnet.scala
8@(00 00 15 12 25 01 11 11)
error: error while loading DotNet, type 'Skyiv.DotNet' is broken
...
Error! The reason is that the getfilemodelist method returns a generic set, which is only available in CLR 2.0.
From the previous article, we know that the scala-msil software package is developed based on mono 1.9.1.0. Ver 1: 0: 5000: 0 and does not support CLR 2.0.
It seems that I had to wait for the author of the software package to upgrade their development environment to mono 2.x. Hopefully they will release a new Scala-msil package soon.
I also tried to compile the scala SDK from the source code.
Follow the instructions on the Subversion repositiory access | the scala programming pluge page to perform the following steps:
ben@ben-m4000t:~$ sudo apt-get install ant
ben@ben-m4000t:~$ cd src
ben@ben-m4000t:~/src$ svn co http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk scala
ben@ben-m4000t:~/src$ cd scala
ben@ben-m4000t:~/src/scala$ ant
ben@ben-m4000t:~/src/scala$ ln -s build/quick/bin bin
ben@ben-m4000t:~/src/scala$ bin/scala -version
Scala code runner version 2.8.0.r0-b20091224094007 -- Copyright 2002-2010, LAMP/EPFL
ben@ben-m4000t:~/src/scala$ bin/scala
Welcome to Scala version 2.8.0.r0-b20091224094007 (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-m4000t:~/src/scala$
After a long wait, the compilation is completed. As shown above, the version is 2.8.0r0.
However, I did not find the source code of sbaz and Scala-msil in the source code package.
So I want to recompile the scala-msil source code into an idea suitable for CLR 2.0, and the idea is gone.