rpav / cl-autowrap

(c-include "file.h") => complete FFI wrapper
BSD 2-Clause "Simplified" License
212 stars 41 forks source link

Struct initialization #121

Open shelvick opened 2 years ago

shelvick commented 2 years ago

Use case: I have two nested structs, and I want to ensure that one of their respective fields contains/points to the same object (i.e. EQ, not just EQL). Example C code:

typedef struct Foo {
  int x;
} Foo;

typedef struct Bar {
  Foo foo;
} Bar;

I want to create two Bar objects with EQ foo's. So in Lisp:

(c-let ((bar1 bar)
        (bar2 bar))
  (setf (bar.foo bar2) (bar.foo bar1)))

But of course this fails, because cl-autowrap doesn't support setting structs directly. It seems simple, but I cannot for the life of me figure out how to make this work. If there were a way to initialize bar2 with a pre-existing foo, then I could work around the limitation to a large extent. I don't see a way though.

Are there any other workarounds for this?