[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] ffi questions and bug (?)
From: |
felix winkelmann |
Subject: |
Re: [Chicken-users] ffi questions and bug (?) |
Date: |
Fri, 20 May 2005 10:49:19 +0200 |
On 5/19/05, Carlos Pita <address@hidden> wrote:
>
> Just to get the feeling, can you give me a
> simple example of (manually) wrapping a
> trivial C++ class using the ffi and tinyclos
> (I mean "manually" without recurring to
> easy ffi or swig)?
You can simply use the `-debug F' option to chicken/csc
to see the code generated by the easy FFI:
% cat x.scm
(require-extension tinyclos)
#>!
class Foo {
int x_;
public:
Foo(int x) { x_ = x; }
virtual ~Foo() {}
int bar(int y) { return x_ * y; }
};
<#
(define f1 (make <Foo> 99))
(pp (bar f1 10))
(destroy f1)
% csc -c++ x.scm -debug F
(begin (declare (hide g2)) (define-class <Foo> (<c++-object>) ()))
(begin
(define g2 (foreign-lambda void "delete " (pointer "Foo")))
(define-method (destroy (this <Foo>)) (g2 (slot-ref this 'this))))
(begin
(declare (hide g3))
(define g3 (foreign-lambda (pointer "Foo") "new Foo" integer))
(define-method
(initialize (this <Foo>) initargs)
(slot-set!
this
'this
(if (and (pair? initargs) (eq? 'this (##sys#slot initargs 0)))
(cadr initargs)
(##sys#apply g3 initargs)))))
(begin
(declare (hide g4))
(define g4
(foreign-lambda*
integer
(((pointer "Foo") g5) (integer g6))
"return(g5->bar(g6));"))
(define-method
(bar (this <Foo>) . args)
(##sys#apply g4 (slot-ref this 'this) args)))
% ./x
990
If you need more information, just ask.
cheers,
felix