Pass array of structs from Python to C

后端 未结 2 868
盖世英雄少女心
盖世英雄少女心 2021-02-08 17:44

[Update: Problem solved! See bottom of the post]

I need to allow python developers to pass an array of packed data (in this case vertices) into my API,

2条回答
  •  离开以前
    2021-02-08 18:19

    The easiest thing I can see to do would be to just avoid the issue altogether and expose a Device_ReadVertex that takes in x, y, z, u, v and color as arguments. This has obvious drawbacks, like making the Python programmers feed it vertices one by one.

    If that's not good enough (seems likely it isn't), then you could try defining a new Python type as described here. It's a bit more code but I think this is the "more architecturally sound" method, because you ensure your Python developers are using the same type definition as you are in the C code. It also allows for a bit more flexibility than a simple struct (it's really a class, with the potential to add methods, etc), which I'm not sure you actually need but it might come in handy later.

提交回复
热议问题