lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> I have a class which has arrays as members, the wrapper code is 
> generated with swig, but when I try to access the array elements I got
> an error saying that the array is an userdata. Can this be solved or
> should I change the array for some auxiliar class with accessor
> methods?

Hello Luo Hei,
Just treat it like a normal
SWIG wrappered array.
SWIG considers an array to be just another pointer.
SWIG will not do a conversion from lua table<->C array for you.
The best way to overcome this is to use carray.i
Something like this:

%module demo;
%include "carrays.i"
%array_class(int,iarr)

%inline %{
class A
{
public:
int arr[10];
};
%}
================
require "demo"
a=demo.A()
arr=demo.iarr_frompointer(a.arr)
print(arr[0],arr[1],arr[2])
===============
The
iarr_frompointer function converts a C array(pointer)
into a simple wrappered class which overloads the [] operator.

Thats my preference.
Regards,
Mark




Sent from Yahoo! Mail.
A Smarter Email.