(Apologies if this posts twice; I outsmarted myself with mailman, and I tried to cancel the first one that mailman thought was posted by a non list member.)
Hi,
I'm having trouble invoking a static member on a class.
I've reduced the case to the following simple test case, and I suspect I may be missing somewhat simple. (I'm far from a Lisp wizard. Far...)
Basically, I'm trying to load a C# assembly, and be able to call a static method on it. I can call instance methods without issue, but make-type-from-name is not working the way I expect it should, and therefore, calling static methods fails.
Any help would be appreciated!
--Jim
Source code and sample interaction below:
Lisp interaction: (win32, using slime and clisp-2.38, but I doubt it makes any difference) Some output trimmed for legibility.
CL-USER> (load "/c/vp/devenv/lib/clisp/rdnzl-0.9.1/load.lisp") CL-USER> (in-package :rdnzl) RDNZL> (enable-rdnzl-syntax) RDNZL> (setq lisp-sample-assembly (import-assembly [System.Reflection.Assembly.LoadFrom "C:\temp\bin\Debug\LispSample1.dll"])) RDNZL> (setq p (new (import-type "LispSample1.Parrot" lisp-sample-assembly) "Bob")) #<CONTAINER LispSample1.Parrot #x2929E6A8> RDNZL> (ffi-call-with-args %invoke-instance-member p "SayHello" '(42))
47 RDNZL> (resolve-type-name "LispSample1.Parrot")
"LispSample1.Parrot, LispSample1, Version=1.0.2230.24825, Culture=neutral, PublicKeyToken=null"
;; To me, it appears that that worked.
RDNZL> (make-type-from-name (resolve-type-name "LispSample1.Parrot"))
#<CONTAINER NULL #x2929E540>
RDNZL> ;; ^^^^ This appears to be as close to the root of the problem as ;; I am able to get
RDNZL> (invoke p "SayHello" 17)
22 ;; this worked (There is stdout output, but my slime discards it.)
RDNZL> (invoke p "StaticSayHello" "Bill" 17)
; Evaluation aborted ;; failed - .NET error (System.Exception): Instance method not found: LispSample1.Parrot::StaticSayHello(System.String,System.Int32) ;; Of course, it's not an instance method...
RDNZL> (invoke "LispSample1.Parrot" "StaticSayHello" "Bill" 17) Trying to call function %INVOKE-STATIC-MEMBER with NULL object #<CONTAINER NULL #x292961E0>.
C# class is here, compiled into an assembly: C:\temp\bin\Debug\LispSample1.dll using System;
namespace LispSample1 { public class Parrot { private string m_name; public Parrot(string name) { m_name = name; } public int SayHello(int value) { Console.WriteLine("Hello {0}.", m_name); return value + 5; } static public int StaticSayHello(string name, int value) { Console.WriteLine("Hello {0}.", name); return value * 2; } } }