chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] Passing C pointers into C++ code


From: felix winkelmann
Subject: Re: [Chicken-users] Passing C pointers into C++ code
Date: Mon, 20 Dec 2004 07:34:13 +0100

On Sun, 19 Dec 2004 19:41:34 +0000, John Lenz <address@hidden> wrote:
> 
> Yeah, the guile module is able to extract the SWIG pointer from the wrapped
> proxy class, but I am not sure how to do it for chicken.  Basicly, in the
> function that accepts a SWIG pointer, we need to do something like (this is
> what the guile module does)
> 
> if (arg is tinyclos class) {
>   arg = (slot-ref arg 'swig-this)
> }
> 
> if (arg is SWIG pointer) {
>   ... whatever
> }
> 
> The problem is, is there any way to access (slot-ref arg 'swig-this) from C
> code?  The only way I could think of to do it is to use a callback.  That
> is, inside the SWIG generated scheme file do something like
> 

You can circumvent the mop and extract the slot-values directly:

#;1> (use tinyclos)
; loading library tinyclos ...
#;2> (define-class <foo> () (a b))
#;3> ,d (make <foo>)
instance of class foo:
 a      -> #<unspecified>
 b      -> #<unspecified>
#;3> (use lolevel)
; loading library lolevel ...
#;4> (record->vector (make <foo>))
#(instance #<class foo> #f #<unspecified> #<unspecified>)
#;5> (define s (make <foo>))
#;6> (slot-set! s 'b 99)
#;7> (record->vector s)
#(instance #<class foo> #f #<unspecified> 99)
#;8> (block-ref s 1)
#<class foo>           ; class of instance s
#;9> (block-ref s 2)
#f                               ; method cache
#;10> (block-ref s 3)        ; slot #1 (a)
#;11> (block-ref s 4)        ; slot #2 (b)
99

So in this case slot #4 contains the value of the 'b slot.
Note that this will naturally not work when the user starts
playing with the mop. But for SWIG generated classes
this probably doesn't apply anyway.


cheers,
felix




reply via email to

[Prev in Thread] Current Thread [Next in Thread]