暫無描述

cedlemo f53e91195c Update README 9 年之前
app 9d78caaa1c Initial commit based on truckboris static linking 10 年之前
ext 060d502306 Make test over Clang 3.8 9 年之前
lib 7b7b20798f adapt to_s methods in some classes 9 年之前
swig bdc5363598 clean swig file 9 年之前
test 845c339b7f use name for methods more compliant to ruby syntax 9 年之前
README.md f53e91195c Update README 9 年之前
Rakefile 23e8610ab3 Revert commenting variable construction 9 年之前
TODO f31638ff48 use name for methods more compliant to ruby syntax almost done 9 年之前
rtruckboris-1.0.1.gem 060d502306 Make test over Clang 3.8 9 年之前
rtruckboris.gemspec cbbfb40ed3 Clean and update gemspec 9 年之前

README.md

Rtruckboris: Ruby bindings for the truckboris library

With rtruckboris, you can easily parse C headers files in pure Ruby.

#!/usr/bin/env ruby

require 'rtruckboris'

parser = Rtruckboris::HeaderParser.new("a_file.h", ["/usr/include"])
parser.parse

functions = parser.functions
puts "Functions number : #{functions.size}"
functions.each do |f|
  puts "Name : #{f.name}"
  puts "Return : #{f.return.name}"
  params = f.parameters
  puts "\t #{params.size.to_s} parameters :"
  params.each do |p|
    puts "\t\t#{p.type.name}  #{p.name}"
    if(!p.type.is_canonical)
      puts "\t\t\t#{p.type.canonical_type.name}"
    end
  end
end

functions.each do |f|
  puts f.raw(parser.source_manager,parser.lang_opts)
end

Resolve dependencies and Install

Dependencies

rtruckboris is a ruby extension for the truckboris library so you need to install it (https://github.com/cedlemo/truckboris) and its dependencies (LLVM and Clang >= 3.4 to 3.8).

You will need to install :

  • Ruby
  • Rake-compiler
  • swig

Install

When this is done, clone this repository with:

git clone https://github.com/cedlemo/rtruckboris

First (re)generate the extension source code via swig with:

rake swig

Then create the gem for your platform:

gem build rtruckboris.gemspec

You can now install the rtruckboris gem with:

gem install rtruckboris-x.x.x.gem

Usage

a lot of examples can be found in the test lib. I use those files when I test truckboris functionnalities you have two ways to try them:

Without installing rtuckboris

rake swig rake compile Then you can use each files in the directory (be sure to be in this directory in order to launch those files.

After installing rtruckboris as a gem

Just modify the require line: require File.dirname(FILE) + "/../lib/rtruckboris/rtruckboris"

with

require 'rtruckboris'

Cedlemo