I am trying to access a array in a c struct from Lua. I want to access it as byte array. I know I have to use typemaps somehow but I am not able to get it working like I want to.
the struct is defined within a namespace if that matter at all. For this example I call the headerfile send.h
namespace foo{
namespace bar{
typedef struct
{
...
unsigned char data[8];
} message;
}};
So I want to be able to access the unsigned char data array from the c struct from Lua. I want to access it like a table with numbers. Here my Lua script code I want to use.
modul = require("MyModule")
msg = modul.message()
msg.data[1] = 0x3b
print(msg.data[1])
All what I get is an error like "attempt to index field 'data' (a userdata value)" I did some research and found out that I have to add some kind of %typemap magic to deal with that. But I was not able to figure out exactly how.
So here my questions:
- Can someone point me to a working example of that scenario?
- What kind of typemap should I apply?
- How can I apply such a typemap only to this struct and not to others?