lua-users home
lua-l archive

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


> Given a C function that returns a pointer to an array
> of values, what sort of trickery is needed to get at
> the elements of that array from within lua?
>
> A simple example function recieves a single integer
> argument and returns a pointer to an array and a pointer
> to the length of the array:
>
>   int get_float_array( int arg,
>                        float** ret_array,
>                        int* ret_array_length );
>
> Solutions, workarounds, and/or hints appreciated!

tolua does not provide support for this automatically.
one solution would be to map the vector as a usertype,
and then to provide a function to access vector elements,
binding both functions with tolua.

MyVector* get_array (int arg);
int get_element (MyVector* v, int index);

with C++,
you can also overload the indexing operator to access the elements.

-- waldemar