Subject: rdnzl-devel post from [email-masked] requires approval
From: [email-masked]
To: [email-masked]
Date: Wed, 08 Feb 2006 13:24:55 -0600
List-Id: General interest list about RDNZL <rdnzl-devel.common-lisp.net>

As list administrator, your authorization is requested for the
following mailing list posting:

    List:    [email-masked]
    From:    [email-masked]
    Subject: Problem with invoking static member
    Reason:  Post by non-member to a members-only list

At your convenience, visit:

    http://common-lisp.net/cgi-bin/mailman/admindb/rdnzl-devel
        
to approve or deny the request.

Subject: Problem with invoking static member
From: Jim Sokoloff <[email-masked]>
To: [email-masked]
Date: Wed, 8 Feb 2006 14:20:15 -0500 (EST)

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;
 		}
 	}
}

Subject: confirm 13db49b0f1b2d342e1f70ebfd24b726b9e7642de
From: [email-masked]

If you reply to this message, keeping the Subject: header intact,
Mailman will discard the held message.  Do this if the message is
spam.  If you reply to this message and include an Approved: header
with the list password in it, the message will be approved for posting
to the list.  The Approved: header can also appear in the first line
of the body of the reply.