From: Byerley <reg...@ho...> - 2014-09-19 00:14:23
|
Hi, I'm trying to pass 2D array from Ruby to a C++ function. For 1D array of some class Cls, I wrote a typemap: %typemap(in) Cls *arr { int size = RARRAY_LEN($input); $1 = (Cls *)malloc(sizeof(Cls) * size); for (int i = 0; i < size; i++) { VALUE rb_obj = rb_ary_entry($input, i); Cls *cpp_obj = NULL; Data_Get_Struct(rb_obj, Cls, cpp_obj); $1[i] = *cpp_obj; } } And it was successful. So, for 2D arrays, I wrote, %typemap(in) Cls **arr { int rowSize = RARRAY_LEN($input); int colSize = RARRAY_LEN($input[0]); ... } However, the swig gave me the error message, saying "invalid types ‘long unsigned int[int]’ for array subscript" I looks like that $input[0] has some problem. How should I fix my code so that I can get the size of 2D array? -- View this message in context: http://swig.10945.n7.nabble.com/Geting-the-dimensions-of-2D-arrays-in-typemap-Ruby-tp13994.html Sent from the swig-user mailing list archive at Nabble.com. |