Returning arrays via tolua-4.0a

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Returning arrays via tolua-4.0a

sessil
Hello,

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!


Reply | Threaded
Open this post in threaded view
|

Re: Returning arrays via tolua-4.0a

Waldemar Celes-3
> 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