Subject:
[ruby-ffi] Re: Basic question about types
From:
Gimi
Date:
10/21/09 9:26 AM
To:
ruby-ffi


Thank you very much Wayne, thank you for your so-detailed replies!

For the 2nd question, I'd already known about :varargs and its usage.
My question is how about a function which uses va_list as a parameter,
like this:
int vprintf ( const char * format, va_list arg );

According to my test, it's impossible to do it in this way:
#-- code --
attach_function :vprintf, [:string, :varargs], :int
# -- code end --

As va_llist actually is void*,  so I guess I should do:
#-- code --
attach_function :vprintf, [:string, :pointer], :int
#-- code end --
But I don't know how to call it.

Although it's not important to do that because there are always(i
guess) a :varargs version for this kind of va_list-style-function, I
just want to know is it possible to do this in Ruby-FFI.

With many thanks!


Sincerely,
Gimi

On Oct 21, 7:21 am, Wayne Meissner <wmeiss...@gmail.com> wrote:
> 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.g...@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,