Subject: [ruby-ffi] Re: Basic question about types |
From: Wayne Meissner |
Date: 10/20/09 6:21 PM |
To: ruby-ffi@googlegroups.com |
You specifiy variadic parameters as :varargs, and when you call the
function, you need to explicitly specify the type of the parameters.
e.g.
# this says printf takes a string parameter, followed by a variable
number of parameters
attach_function :printf, [ :string, :varargs ], :int
# You don't need to specify the type of any fixed params, since it is part of
# the function signature, but you do need to for each varargs parameter
LibC.printf("Hello, %s", :string, "World")
2009/10/21 Gimi <liang.gimi@gmail.com>:
Hi, it's me again : ) I just wanna ask one more question, how to deal with the va_list parameter? Like the vprintf method, how to attach and call it? With many thanks! Gimi On Oct 20, 10:10 am, Gimi <liang.g...@gmail.com> wrote:Hi all, I'm new to FFI, and I have a basic question about types. Assume there is some C code like this: # -- C code begin -- #if some situation typedef sometype unsignedint #else typedef sometype int #endif void some_function(sometype); #-- C code end -- So I mean when the types of parameters of a function are different in different situations, how do I write the Ruby code? Any help will be greatly appreciated. Regards,