From: Aaron Patterson Date: 2009-08-14T01:52:52+09:00 Subject: Re: Ruby/DL question On Thu, Aug 13, 2009 at 07:06:51PM +0900, Gin Mendi wrote: > Been trying to learn how to use ruby and Ruby/DL and I'm unsure how to > implement this: > > I have a callback function in C which I want to implement in ruby > > void my_callback(my_struct resultList, DWORD count) > { > while (count != 0) > { > if (resultList != NULL) > { > printf("field1 - %s , field2 - %f \n", resultList->field1, > resultList->field2); > } > resultList++; > count--; > } > } > > I started with this: > > MY_CALLBACK = DL.callback('0PL') { |result_list, count| > if result_list > record = MyStruct.new(result_list) > puts record.field1 > end > } > > My problem is I don't know how to get the other records if result_list > points to 2 or more records. I want to be able to traverse the whole set > or records like in the C callback function. I understand that I will > need to loop "count" times but how do I make my pointer point to the > next record? Result list should always be a pointer to a pointer, right? If that is the case, you need to create a struct of size count that contains that array. From the new list struct, you should be able to access each MyStruct. -- Aaron Patterson http://tenderlovemaking.com/