In data 3/23/2005, "(Luc Heinrich)" <lucsky@mac.com> ha scritto:
>Eric Hodel <drbrain@segment7.net> wrote:
>
>> typealias "FOO", "void *"
>>
>> Something like this should do it. (Yeah, void * is probably the wrong
>> type, see dl/types for what types dl knows about.)
>
>Right, typealias-ing to 'void*' seems to do the trick for this case,
>although I'm not sure if it's really the correct way or just a
>coincidence. dl/types (mostly) knows about primitive types and pointers
>to primitive types, and I'm not sure how structs passed on the stack can
>relate to these.
>
>Because if we now consider this:
>
>Adding this function to foo.c:
>
> void dump_foo( FOO foo )
> {
> printf( "foo.bar = %d\n", foo.bar );
> printf( "foo.baz = %d\n", foo.baz );
> }
>
>And then adding this to foo.rb:
>
> extern 'void dump_foo(FOO)'
>
>And then doing:
>
> foo = Foo.my_make_a_foo
> Foo.dump_foo( foo )
>
>Gives:
>
> foo.bar = -1073791088
> foo.baz = 891578649
>
>Instead of:
>
> foo.bar = 42
> foo.baz = 1
>
>That's why I'm a bit suspicious about the 'void*' thing ;)
Normally you'd cast from void*, of course, but I don't know
if it's possible in DL. Maybe pass around a struct FOO* instead?
That or just write a C extension.
>Luc Heinrich - lucsky@mac.com
E