[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

A couple of Ruby API questions

Jon McClintock

2/9/2005 6:37:00 AM

Hi Rubyists,

I'm working on wrapping a C library, and I've got a couple of things I
can't quite figure out how to manage:

1) Wrapping functions that take variable-length arguments (varargs). Is
there are standard way to do this? The best I've found is libffi,
which lets you construct the stack frames you need to do this, but it
seems like this would be a problem someone would have solved a while
ago.

2) Wrapping structures with flexible arrays. How do I realloc the
structure held by a VALUE? Or do I have to create an entirely new
Ruby object each time I need to resize the structure?

Thanks,

-Jon


1 Answer

Tim Hunter

2/9/2005 1:16:00 PM

0

Jon McClintock wrote:

>
> 2) Wrapping structures with flexible arrays. How do I realloc the
> structure held by a VALUE? Or do I have to create an entirely new
> Ruby object each time I need to resize the structure?

If you have created a VALUE by wrapping a structure with Data_Wrap_Struct or
Data_Make_Struct and you need to change the structure that the VALUE wraps,
use the DATA_PTR macro:

VALUE my_obj;
MyStruct my_struct;

my_struct = malloc(sizeof(MyStruct));
DATA_PTR(my_obj) = my_struct;

As far as Ruby is concerned the object is unchanged.
--
Tim Hunter