也谈在 .NET 平台上使用 Scala 语言(续)

而我是在 Ubuntu 操作系统中使用 Scala.NET 的,应该没有这个问题。

那么,就让我们来測试一下吧。

如今,我们添加一个 DotNet.cs 文件,例如以下所看到的:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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;
     }
     */
   }
}

然后,在 dotnetscala 中添加对这些 C# 方法的调用:

1
2
3
4
5
6
7
8
9
10
11
12
13
import  System.Console
 
object  dotnet extends  Application {
   Console.WriteLine( "       Scala.NET: 欢迎光临" );
   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( "欢迎使用 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());
}

最后。对 makefile 文件进行对应修改:

如今来看看编译和执行的情况吧:

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
Assembling 'dotnet.msil' , no listing file, to exe --> 'dotnet.exe'
Operation completed successfully
ben@ben-vbox:~/Projects/ScalaNet$ mono dotnet.exe
       Scala.NET: 欢迎光临
      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$ 

非常好。一切正常。

可见,Scala 语言和 C# 语言的各种类型的參数传递没有问题。

 

可是。假设把 DotNet.cs 程序中被凝视掉的 GetFileModeList 方法释放出来。再编译:

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
... 

出错了!原因是 GetFileModeList 方法返回一个泛型集合,而泛型是 CLR 2.0 才有的功能。

上篇文章中。我们知道,scala-msil 软件包是基于 Mono 1.9.1.0 .ver 1:0:5000:0 开发的,不支持 CLR 2.0 的功能。

看来。仅仅好等待该软件包的作者把他们的开发环境升级到 Mono 2.x 版本号了。

但愿他们早日公布新的 scala-msil 软件包。

:)

 

我还试图从源码開始编译 Scala SDK 。

依照 Subversion Repositiory Access | The Scala Programming Languge 网页上的指示。按下面步骤进行:

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$ 

经过漫长的等待。最终编译完毕了。

如上所看到的,版本号是 2.8.0r0。

可是,在源码包里我没有找到 sbaz 以及 scala-msil 的源码。

所以,我想把 scala-msil 源码又一次编译为适合 CLR 2.0 的想法破产了。 :(

转载于:https://www.cnblogs.com/lxjshuju/p/7237502.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值