File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33
44module FFI
55
6- # @private
6+ ##
7+ # Generate files with C structs for FFI::Struct and C constants.
8+ #
9+ # == A simple example
10+ #
11+ # In file +zlib.rb.ffi+:
12+ # module Zlib
13+ # @@@
14+ # constants do |c|
15+ # c.include "zlib.h"
16+ # c.const :ZLIB_VERNUM
17+ # end
18+ # @@@
19+ #
20+ # class ZStream < FFI::Struct
21+ #
22+ # struct do |s|
23+ # s.name "struct z_stream_s"
24+ # s.include "zlib.h"
25+ #
26+ # s.field :next_in, :pointer
27+ # s.field :avail_in, :uint
28+ # s.field :total_in, :ulong
29+ # end
30+ # @@@
31+ # end
32+ # end
33+ #
34+ # Translate the file:
35+ # require "ffi/tools/generator"
36+ # FFI::Generator.new "zlib.rb.ffi", "zlib.rb"
37+ #
38+ # Generates the file +zlib.rb+ with constant values and offsets:
39+ # module Zlib
40+ # ZLIB_VERNUM = 4784
41+ #
42+ # class ZStream < FFI::Struct
43+ # layout :next_in, :pointer, 0,
44+ # :avail_in, :uint, 8,
45+ # :total_in, :ulong, 16
46+ # end
47+ #
48+ # @see FFI::Generator::Task for easy integration in a Rakefile
749 class Generator
850
951 def initialize ( ffi_name , rb_name , options = { } )
Original file line number Diff line number Diff line change 33require 'rake/tasklib'
44
55##
6- # Rake task that calculates C structs for FFI::Struct.
7-
8- # @private
6+ # Add Rake tasks that generate files with C structs for FFI::Struct and C constants.
7+ #
8+ # @example a simple example for your Rakefile
9+ # require "ffi/tools/generator_task"
10+ # # Add a task to generate my_object.rb out of my_object.rb.ffi
11+ # FFI::Generator::Task.new ["my_object.rb"], cflags: "-I/usr/local/mylibrary"
12+ #
13+ # The generated files are also added to the 'clear' task.
14+ #
15+ # @see FFI::Generator for a description of the file content
916class FFI ::Generator ::Task < Rake ::TaskLib
1017
1118 def initialize ( rb_names )
You can’t perform that action at this time.
0 commit comments