Skip to content
This repository

Mix C in (J)Ruby and gulp it on the fly!

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 examples
Octocat-spinner-32 lib
Octocat-spinner-32 spec
Octocat-spinner-32 tasks
Octocat-spinner-32 .gitignore
Octocat-spinner-32 History.txt
Octocat-spinner-32 README.rdoc
Octocat-spinner-32 Rakefile
README.rdoc

ffi-inliner

by Andrea Fazzi
http://github.com/remogatto/ffi-inliner

DESCRIPTION:

With ffi-inliner you can run C code within your ruby script.

FEATURES/PROBLEMS:

  • Mix C snippets in your Ruby code and gulp it on the fly!

  • It's based on Ruby-FFI so the C code you inject is portable across Ruby implementations!

  • Yep, it means that you can run it on JRuby too!

  • Fast compilation through tcc

  • But it can use the system's compiler (e.g. gcc) on those platforms that don't support tcc (e.g. OSX) or that don't have it installed

SYNOPSIS:

require 'ffi-inliner'

module MyLib
  extend Inliner
  inline 'void say_hello(char* name) { printf("Hello, %s\n", name); }'
end

MyLib.say_hello('boys')

class Foo
  include MyLib
end

Foo.new.say_hello('foos')

For other hints see the examples/ folder or visit the wiki. For a “real” world example you may be interested to ffi-life.

REQUIREMENTS:

  • ffi >= 0.4.0

  • gcc and/or tcc >= 0.9.25 (optional)

DOWNLOAD/INSTALL:

From rubyforge:

[sudo] gem install ffi-inliner

or from github:

git clone git://github.com/remogatto/ffi-inliner
cd ffi-inliner
sudo rake gem:install

CREDITS

Special thanks to:

  • Ryan Davis for his inspiring RubyInline.

  • Roger Pack for improving support for Windows platforms.

LICENSE:

(The MIT License)

Copyright © 2009 Andrea Fazzi

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Something went wrong with that request. Please try again.