From: E S Date: 2005-02-09T16:00:57+09:00 Subject: Re: A couple of Ruby API questions > L�hett�j�: Jon McClintock > Aihe: A couple of Ruby API questions > > 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. Wrapping how? Should these be callable from Ruby? Ruby can define a method to take variable arguments either as a RArray or as a C array, so you'll pick one, construct a wrapper function based your selected way and have that function extract the values and feed them to your 'actual' function. > 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? Just wrap a pointer to the struct instead if you already have the C to manage the arrays. Whenever Ruby needs those values, have a C function extract them. Alternatively, you could use a RArray. > Thanks, > > -Jon E