Parent

Namespace

FFI::Generator

Public Class Methods

new(ffi_name, rb_name, options = {}) click to toggle source
    # File lib/ffi/tools/generator.rb, line 4
 4:     def initialize(ffi_name, rb_name, options = {})
 5:       @ffi_name = ffi_name
 6:       @rb_name = rb_name
 7:       @options = options
 8:       @name = File.basename rb_name, '.rb'
 9: 
10:       file = File.read @ffi_name
11: 
12:       new_file = file.gsub(/^( *)@@@(.*?)@@@/) do
13:         @constants = []
14:         @structs = []
15: 
16:         indent = $1
17:         original_lines = $2.count "\n"
18: 
19:         instance_eval $2
20: 
21:         new_lines = []
22:         @constants.each { |c| new_lines << c.to_ruby }
23:         @structs.each { |s| new_lines << s.generate_layout }
24: 
25:         new_lines = new_lines.join("\n").split "\n" # expand multiline blocks
26:         new_lines = new_lines.map { |line| indent + line }
27: 
28:         padding = original_lines - new_lines.length
29:         new_lines += [nil] * padding if padding >= 0
30: 
31:         new_lines.join "\n"
32:       end
33: 
34:       open @rb_name, 'w' do |f|
35:         f.puts "# This file is generated by rake. Do not edit."
36:         f.puts
37:         f.puts new_file
38:       end
39:     end

Public Instance Methods

constants(options = {}, &block) click to toggle source
    # File lib/ffi/tools/generator.rb, line 41
41:     def constants(options = {}, &block)
42:       @constants << FFI::ConstGenerator.new(@name, @options.merge(options), &block)
43:     end
struct(options = {}, &block) click to toggle source
    # File lib/ffi/tools/generator.rb, line 45
45:     def struct(options = {}, &block)
46:       @structs << FFI::StructGenerator.new(@name, @options.merge(options), &block)
47:     end
to_s() click to toggle source

Utility converter for constants

    # File lib/ffi/tools/generator.rb, line 52
52:     def to_s
53:       proc { |obj| obj.to_s.inspect }
54:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.