Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to access elements of a C++ image array (struct) with Lua? #2894

Closed
Jonathhhan opened this issue Apr 25, 2024 · 3 comments
Closed

How to access elements of a C++ image array (struct) with Lua? #2894

Jonathhhan opened this issue Apr 25, 2024 · 3 comments

Comments

@Jonathhhan
Copy link

Jonathhhan commented Apr 25, 2024

I have an array of this struct (sd_image_t*) as the return value of a function:

typedef struct {
    uint32_t width;
    uint32_t height;
    uint32_t channel;
    uint8_t* data;
} sd_image_t;

In C++ I can call sd_image_t[n].data while with SWIG created Lua bindings I can only call sd_image_t.data (which seems to be a pointer to all data of the struct). Is there a way to wrap it, so that I can call it like in C++?
Could %naturalvar help in my case? https://www.swig.org/Doc1.3/SWIGPlus.html#SWIGPlus_member_data
Here I tried to describe my issue too: https://forum.openframeworks.cc/t/swig-lua-binding-for-accessing-elements-of-an-image-array/43429

@ojwb
Copy link
Member

ojwb commented Jul 18, 2024

You're looking at a really ancient version of the manual there (the last SWIG 1.3.x release was in 2009, the current release is SWIG 4.2.0).

See https://www.swig.org/Doc4.2/Lua.html#Lua_typemap_arrays for documentation discussing wrapping arrays for Lua.

@ojwb
Copy link
Member

ojwb commented Aug 1, 2024

Question and answered so closing.

@ojwb ojwb closed this as completed Aug 1, 2024
@Jonathhhan
Copy link
Author

@ojwb thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants