【发布时间】:2011-12-20 05:36:30
【问题描述】:
我遇到异常非静态字段、方法或...需要对象引用
这是我想要做的:
;; Here's the program.clj file from a VsClojure project.
;; First thing you need to do is add the :methods property
;; which takes a of methods that are to be generated when
;; the class is created. Here, I'm generating a static method
;; named hi which has no parameters and returns a String.
;;
;; When program.hi() is called from the C# code the
;; the clojure function -hi will be called. By default any
;; method in the :methods vector will be mapped to a function
;; with the same name prefixed by a -.
(ns program
(:gen-class
:methods [ #^{:static true} [hi [] String]]))
(defn -hi []
"Hi from ClojureCLR!")
(defn -main [& args]
(println "Hello world")
(println (-hi)))
;; The C# code is nothing special
;; You MUST add both the program.exe and program.clj.dll
;; files as references in hte C# project. In addition
;; to these assemblies you'll need to add the following
;; assemblies which can be found in the ClojureCLR's directory:
;; clj.gen_class.clj.dll, clojure.clr.io.clj.dll, clojure.core.clj.dll
;; clojure.core_deftype.clj.dll, clojure.core_printl.clj.dll,
;; clojure.core_proxy.clj.dll, clojure.genclass.clj.dll, clojure.gvec.clj.dll
;; using System;
;; namespace csharp
;; {
;; class Program
;; {
;; static void Main(string[] args)
;; {
;; // You can see here you'd never know this was
;; // really a clojure function I'm calling
;; Console.WriteLine("p.hi => {0}", program.hi());
;; }
;; }
;;}
但得到:错误 1 非静态字段、方法或属性 'program.hi()' ConsoleApplication1 需要对象引用。
我正在使用 内置的 Visual Studio 扩展 vsClojure。 1.1.0; GitHub 自述文件之后的最新版本 1.1.0。也许我需要更新它,但我遇到了一些本地小问题,这让我无法构建最后一个 clojre-clr(我将在明年解决它们)。
所以问题是如何从 C# 调用 clojure clr 库,我的麻烦在哪里?
日志:
'program.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'program.exe' (Managed (v2.0.50727)): Loaded 'D:\nCdy\P\Clojure1\Clojure1\bin\Debug\program.exe', Symbols loaded.
'program.exe' (Managed (v2.0.50727)): Loaded 'D:\nCdy\P\Clojure1\Clojure1\bin\Debug\Clojure.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'program.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\System\2.0.0.0__b77a5c561934e089\System.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'program.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Core\3.5.0.0__b77a5c561934e089\System.Core.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'program.exe' (Managed (v2.0.50727)): Loaded 'D:\nCdy\P\Clojure1\Clojure1\bin\Debug\Microsoft.Scripting.ExtensionAttribute.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'program.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\mscorlib.resources\2.0.0.0_ru_b77a5c561934e089\mscorlib.resources.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
【问题讨论】:
标签: c# .net clojure clojureclr