From: Nate
Subject: ffi and classes
Date: 
Message-ID: <1165290658.468480.226980@j44g2000cwa.googlegroups.com>
I have a quick question. I've looked several places, and unless I'm
looking in the wrong places, I can't find an answer.

Now, I'm trying to use the lisp ffi (clisp to be exact) to access a
class in a dll (win platform) Would (ffi:def-c-struct classname
etc-slots) and then using (ffi:def-call-out) for each member function
allow me to access the class?

Thanks, Nathan

From: Pascal Bourguignon
Subject: Re: ffi and classes
Date: 
Message-ID: <87irgrx9uk.fsf@thalassa.informatimago.com>
"Nate" <·············@gmail.com> writes:

> I have a quick question. I've looked several places, and unless I'm
> looking in the wrong places, I can't find an answer.
>
> Now, I'm trying to use the lisp ffi (clisp to be exact) to access a
> class in a dll (win platform) Would (ffi:def-c-struct classname
> etc-slots) and then using (ffi:def-call-out) for each member function
> allow me to access the class?

Well, let's see what the doc says.
Let's go to the section about def-call-out.
It mentions an option named:

    (:LANGUAGE language)
        See Section 31.3.4, “The choice of the C flavor”.

so, let's see Section 31.3.4:

    31.3.4. The choice of the C flavor

    FFI:C-FUNCTION, FFI:DEF-CALL-IN, FFI:DEF-CALL-OUT take a :LANGUAGE
    argument. The language is either :C (denotes K&R C) or :STDC
    (denotes ANSI C) or :STDC-STDCALL (denotes ANSI C with the
    “stdcall” calling convention). It specifies whether the C function
    (caller or callee) has been compiled by a K&R C compiler or by an
    ANSI C compiler, and possibly the calling convention.

    The default language is set using the macro
    FFI:DEFAULT-FOREIGN-LANGUAGE . If this macro has not been called
    in the current compilation unit (usually a file), a warning is
    issued and :STDC is used for the rest of the unit.


I don't know you, but I read only three choices: :C, :STDC, and
:STDC-STDCALL.

Now, we'd have to check K&R, or the later ISO-C99, but I don't think
these standard mention any "class".


Can you express these "classes" and "member functions" in terms of C
structures and C functions?

If so, yes, you could write these def-c-struct and def-call-out.


However, if you mean C++, there may be more problems than just  the
names.  For example with respect to exception handling...  But I don't
know anything about DLL and MS-Windows, perhaps C++ has something
special there.



If you want to write portable foreign function calls, you could use
CFFI and it's brother tool, Fetter, which is able to generate the FFI
declarations automatically from the headers, parsed by gccxml.  Fetter
targets C and C++, so you'd have a better chance, if you really meant
C++, with it, than writting manually the clisp FFI declarations.




-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
Kitty like plastic.
Confuses for litter box.
Don't leave tarp around.
From: Nate
Subject: Re: ffi and classes
Date: 
Message-ID: <1165305915.939855.219840@79g2000cws.googlegroups.com>
Okay, thanks for the pointer.

Pascal Bourguignon wrote:
> "Nate" <·············@gmail.com> writes:
>
> > I have a quick question. I've looked several places, and unless I'm
> > looking in the wrong places, I can't find an answer.
> >
> > Now, I'm trying to use the lisp ffi (clisp to be exact) to access a
> > class in a dll (win platform) Would (ffi:def-c-struct classname
> > etc-slots) and then using (ffi:def-call-out) for each member function
> > allow me to access the class?
>
> Well, let's see what the doc says.
> Let's go to the section about def-call-out.
> It mentions an option named:
>
>     (:LANGUAGE language)
>         See Section 31.3.4, "The choice of the C flavor".
>
> so, let's see Section 31.3.4:
>
>     31.3.4. The choice of the C flavor
>
>     FFI:C-FUNCTION, FFI:DEF-CALL-IN, FFI:DEF-CALL-OUT take a :LANGUAGE
>     argument. The language is either :C (denotes K&R C) or :STDC
>     (denotes ANSI C) or :STDC-STDCALL (denotes ANSI C with the
>     "stdcall" calling convention). It specifies whether the C function
>     (caller or callee) has been compiled by a K&R C compiler or by an
>     ANSI C compiler, and possibly the calling convention.
>
>     The default language is set using the macro
>     FFI:DEFAULT-FOREIGN-LANGUAGE . If this macro has not been called
>     in the current compilation unit (usually a file), a warning is
>     issued and :STDC is used for the rest of the unit.
>
>
> I don't know you, but I read only three choices: :C, :STDC, and
> :STDC-STDCALL.
>
> Now, we'd have to check K&R, or the later ISO-C99, but I don't think
> these standard mention any "class".
>
>
> Can you express these "classes" and "member functions" in terms of C
> structures and C functions?
>
> If so, yes, you could write these def-c-struct and def-call-out.
>
>
> However, if you mean C++, there may be more problems than just  the
> names.  For example with respect to exception handling...  But I don't
> know anything about DLL and MS-Windows, perhaps C++ has something
> special there.
>
>
>
> If you want to write portable foreign function calls, you could use
> CFFI and it's brother tool, Fetter, which is able to generate the FFI
> declarations automatically from the headers, parsed by gccxml.  Fetter
> targets C and C++, so you'd have a better chance, if you really meant
> C++, with it, than writting manually the clisp FFI declarations.
>
>
>
>
> --
> __Pascal Bourguignon__                     http://www.informatimago.com/
> Kitty like plastic.
> Confuses for litter box.
> Don't leave tarp around.