and3rson / foreigner

FFI library for Godot, built with GDNative
MIT License
25 stars 4 forks source link

Adding buffer/struct support #11

Open follower opened 4 years ago

follower commented 4 years ago

Progress so far

Primarily just a placeholder issue for now but wanted to mention that after further investigation I've gotten some hacky buffer support working--which can be made even more hacky to somewhat support structs.

I've moved away from the PoolByteArray approach (at least initially) because neither it nor StreamPeerBuffer (nor any other builtin Godot type) seem to support shared/non-Copy-on-Write access to memory/buffers (Array & Dictionary are shared but don't offer direct access). (Also Pool*Array is changing implementation in 4.0 to use Vector so don't know what effect that will have.)

Plan to push a hacky proof-of-concept implementation and add further notes at some point after I've finished with the cross-platform build support in #9.

Buffer/Struct API design considerations

As an additional point of consideration, lacking other design inspiration, one option could be to copy however much of the Python ctypes approach makes sense: https://docs.python.org/3/library/ctypes.html

Conclusion

But, suffice to say, being able to wrap a pre-existing binary library with just foreigner.so & pure GDScript is very very cool. :)