# \[ANN\] ffi-swig-generator 0.3.0

**URL:** <https://www.ruby-forum.com/t/ann-ffi-swig-generator-0-3-0/165975>\
**Category:** Ruby\
**Created:** [April 20, 2009, 3:22pm UTC](https://www.ruby-forum.com/t/ann-ffi-swig-generator-0-3-0/165975 "2009-04-20T15:22:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![gendag](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/f04885/32.png) [@gendag](https://www.ruby-forum.com/u/gendag)\
**Post date:** [April 20, 2009, 3:22pm UTC](https://www.ruby-forum.com/t/ann-ffi-swig-generator-0-3-0/165975/1 "2009-04-20T15:22:51Z")

</div>

ffi-swig-generator version 0.3.0  
by Andrea F.  
[http://kenai.com/projects/ruby-ffi/sources/swig-generator/show](http://kenai.com/projects/ruby-ffi/sources/swig-generator/show)

== DESCRIPTION

ffi-swig-generator is a ruby-ffi wrapper code generator that produces  
ruby-ffi glue code parsing C header files through SWIG.

ffi-swig-generator is able to traverse an XML parse tree generated by  
the +swig+ command and to produce a ruby-ffi code from it.

ffi-swig-generator is shipped with a command line tool and a rake task  
that automates the code generation process.

ffi-swig-generator XML capabilities are provided by nokogiri.

== CHANGES

- Major enhancements
  - Generate accessors methods for struct fields of type string and  
callback.
  - Add experimental support for nested structs and unions.
  - Add initial support for configuration files.

- Minor enhancements
  - Add support for variadic arguments.
  - Add support for anonymous callbacks in function and struct  
declaration.
  - Add support for volatile types.
  - Add support for U, L, UL constant qualifiers.
  - Improve testing with cucumber.
  - Now the rake task can be configured through a configuration block.

- Bug fixes
  - Fix ruby 1.8.6/1.9.1 compatibility issues.
  - Fix generated const char\* return type.
  - Fix a bug that prevented to manage struct name with a prepending  
underscore.

== FEATURES

- The program is able to generate:
  - all C native types
  - #define constants
  - typedefs
  - struct, union, array and enum types
  - callbacks (pointers to functions)

- Naive indentation of the generated code

== SYNOPSIS

From command line:

ffi-gen mylib.xml mylib.rb

From a Rakefile:

require ‘ffi-swig-generator’  
FFI::Generator::Task.new do |task|  
task.input\_fn = ‘my\_interface\_dir/\*.i’  
task.output\_dir = ‘my\_output\_dir’  
end

== REQUIREMENTS

- rake \>= 0.8.3
- nokogiri \>= 1.1.1
- swig \>= 1.3

== DOWNLOAD

Download and install from rubygems:

[sudo] gem install ffi-swig-generator

or clone mercurial repository:

hg clone [http://kenai.com/hg/ruby-ffi~swig-generator](http://kenai.com/hg/ruby-ffi~swig-generator)

== EXAMPLES

See the examples in examples/ folder.

libc.i is an interface file containing some excerpt of libc functions.

wiiuse.i is a fairly complex example of a C header file interface. It  
reproduces the content of wiiuse.h, the header file of the wiiuse  
library. wiiuse is a C library that handles the connection with  
Nintendo Wiimote devices. The interface file is almost a mere  
copy/paste from the original header file. See [1] for an updated  
revision of ffi-wiiuse library.

== PROJECTS

The generator has been used to generate code for the projects  
below. Take a look at them to see further usage examples.

1. [GitHub - remogatto/ffi-wiiuse: wiiuse ruby binding using FFI](http://github.com/remogatto/ffi-wiiuse/tree/master)
2. [GitHub - remogatto/ffi-opengl: A ruby-ffi binding to OpenGL libraries](http://github.com/remogatto/ffi-opengl/tree/master)
3. [GitHub - remogatto/ffi-spidermonkey: A ruby-ffi binding to spidermonkey JS engine](http://github.com/remogatto/ffi-spidermonkey/tree/master)
